Class AbstractViewFileServlet

java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
com.atlassian.jira.web.servlet.viewfile.AbstractViewFileServlet
All Implemented Interfaces:
jakarta.servlet.Servlet, jakarta.servlet.ServletConfig, Serializable
Direct Known Subclasses:
ViewAttachmentServlet, ViewThumbnailServlet

public abstract class AbstractViewFileServlet extends jakarta.servlet.http.HttpServlet
See Also:
  • Field Details

    • IMAGE_DISPLAYING_CANNOT_DISPLAY_IMAGE_PATH

      public static String IMAGE_DISPLAYING_CANNOT_DISPLAY_IMAGE_PATH
    • IMAGE_ATTACHMENT_JWT_TOKEN_QUERY_PARAM_NAME

      public static final String IMAGE_ATTACHMENT_JWT_TOKEN_QUERY_PARAM_NAME
      See Also:
  • Constructor Details

    • AbstractViewFileServlet

      public AbstractViewFileServlet()
  • Method Details

    • getAttachmentManager

      protected AttachmentManager getAttachmentManager()
    • doGet

      protected void doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException
      Overrides:
      doGet in class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
      IOException
    • getContentLength

      protected abstract int getContentLength(String attachmentPath)
    • supportsRangeRequests

      protected abstract boolean supportsRangeRequests()
      Returns true if this implementation supports RFC 7233 "Range Requests".

      Returning true means that you must set the appropriate "Content-Range" and "Content-Length" headers for the partial range we will return in the #setResponseHeaders implementation.

      Returns:
      true if this servlet supports RFC 7233 "Range Requests".
    • copyRange

      protected void copyRange(InputStream is, OutputStream out, RangeResponse rangeResponse) throws IOException
      Throws:
      IOException
    • attachmentQuery

      protected final String attachmentQuery(jakarta.servlet.http.HttpServletRequest request)
      Validates that path is valid attachment path.
      Parameters:
      request - HTTP request
      Returns:
      attachment path
    • getAttachment

      protected Attachment getAttachment(String queryWithIdAndFilenameToIgnore)
      Looks up the attachment by reading the id from the queryWithIdAndFilenameToIgnore string.
      Parameters:
      queryWithIdAndFilenameToIgnore - eg. '/10000/foo.txt'
      Returns:
      attachment found
      Throws:
      AttachmentNotFoundException - if no attachment is found after parsing the queryWithIdAndFilenameToIgnore string or if the resulting attachment id does not exist.
      DataAccessException - if there is a problem accessing the database.
    • isLoggedInUserPermittedToViewAttachment

      protected boolean isLoggedInUserPermittedToViewAttachment(Attachment attachment)
    • isJwtTokenUserPermittedToViewAttachment_andSendAnalyticsEvent

      protected boolean isJwtTokenUserPermittedToViewAttachment_andSendAnalyticsEvent(jakarta.servlet.http.HttpServletRequest request, Attachment attachment)
    • isUserPermittedToViewAttachment

      protected boolean isUserPermittedToViewAttachment(ApplicationUser user, Attachment attachment)
    • checkRequesterIsPermittedToViewTheAttachment

      protected void checkRequesterIsPermittedToViewTheAttachment(Attachment attachment, jakarta.servlet.http.HttpServletRequest request, String exceptionMessage) throws PermissionException
      Throws:
      PermissionException
    • getInputStream

      protected abstract void getInputStream(jakarta.servlet.http.HttpServletRequest request, String attachmentPath, InputStreamConsumer<io.atlassian.fugue.Unit> consumer) throws IOException, PermissionException
      Gets the attachment file (not the file name) that corresponds to the requested attachment.
      Parameters:
      attachmentPath - the attachment path
      consumer - a procedure that consumes the stream with the attachment data.
      Throws:
      DataAccessException - If there is a problem looking up the data to support the attachment.
      AttachmentNotFoundException - if the attachment does not exist.
      IOException - if there is a problem getting the attachment.
      NoAttachmentDataException - if the attachment's contents cannot be found.
      AttachmentReadException - if a problem occurs when the consumer processes the attachment's contents.
      PermissionException
    • setResponseContentHeaders

      protected abstract void setResponseContentHeaders(jakarta.servlet.http.HttpServletRequest request, Optional<RangeResponse> rangeResponse, jakarta.servlet.http.HttpServletResponse response, Optional<Long> contentLength)
      Sets the content type, content length and "Content-Disposition" header of the response based on the values of the attachment found.

      The rangeResponse parameter will only be present if this Concrete class declares it supports Range Requests, and the request actually contains a Range header.

      Parameters:
      request - HTTP request
      rangeResponse - If present, the partial byte range we will return
      response - HTTP response
      contentLength - the length of the content we are returning in bytes, if known
      Throws:
      InvalidAttachmentPathException - if the attachment path is invalid
      AttachmentNotFoundException - if the specified attachment cannot be found
      DataAccessException - if there is a problem accessing the database
      See Also:
    • isUserLoggedIn

      protected boolean isUserLoggedIn()
    • getLoggedInUser

      protected final ApplicationUser getLoggedInUser()
    • isAnonymousUserPermittedToViewAttachment

      protected final boolean isAnonymousUserPermittedToViewAttachment(Attachment attachment)
    • isImageAttachmentJwtTokenPresent

      protected boolean isImageAttachmentJwtTokenPresent(jakarta.servlet.http.HttpServletRequest request)