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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class -
Field Summary
FieldsFields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final StringattachmentQuery(jakarta.servlet.http.HttpServletRequest request) Validates that path is valid attachment path.protected voidcheckRequesterIsPermittedToViewTheAttachment(Attachment attachment, jakarta.servlet.http.HttpServletRequest request, String exceptionMessage) protected voidcopyRange(InputStream is, OutputStream out, RangeResponse rangeResponse) protected voiddoGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) protected AttachmentgetAttachment(String queryWithIdAndFilenameToIgnore) Looks up the attachment by reading the id from the queryWithIdAndFilenameToIgnore string.protected AttachmentManagerprotected abstract intgetContentLength(String attachmentPath) protected abstract voidgetInputStream(jakarta.servlet.http.HttpServletRequest request, String attachmentPath, InputStreamConsumer<io.atlassian.fugue.Unit> consumer) Gets the attachment file (not the file name) that corresponds to the requested attachment.protected final ApplicationUserprotected final booleanisAnonymousUserPermittedToViewAttachment(Attachment attachment) protected booleanisImageAttachmentJwtTokenPresent(jakarta.servlet.http.HttpServletRequest request) protected booleanisJwtTokenUserPermittedToViewAttachment_andSendAnalyticsEvent(jakarta.servlet.http.HttpServletRequest request, Attachment attachment) protected booleanisLoggedInUserPermittedToViewAttachment(Attachment attachment) protected booleanprotected booleanisUserPermittedToViewAttachment(ApplicationUser user, Attachment attachment) protected abstract voidsetResponseContentHeaders(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.protected abstract booleanReturns true if this implementation supports RFC 7233 "Range Requests".Methods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPost, doPut, doTrace, getLastModified, init, service, serviceMethods inherited from class jakarta.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Field Details
-
IMAGE_DISPLAYING_CANNOT_DISPLAY_IMAGE_PATH
-
IMAGE_ATTACHMENT_JWT_TOKEN_QUERY_PARAM_NAME
- See Also:
-
-
Constructor Details
-
AbstractViewFileServlet
public AbstractViewFileServlet()
-
-
Method Details
-
getAttachmentManager
-
doGet
protected void doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException - Overrides:
doGetin classjakarta.servlet.http.HttpServlet- Throws:
jakarta.servlet.ServletExceptionIOException
-
getContentLength
-
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
#setResponseHeadersimplementation.- 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
Validates that path is valid attachment path.- Parameters:
request- HTTP request- Returns:
- attachment path
-
getAttachment
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
-
isJwtTokenUserPermittedToViewAttachment_andSendAnalyticsEvent
protected boolean isJwtTokenUserPermittedToViewAttachment_andSendAnalyticsEvent(jakarta.servlet.http.HttpServletRequest request, Attachment attachment) -
isUserPermittedToViewAttachment
-
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 pathconsumer- 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 requestrangeResponse- If present, the partial byte range we will returnresponse- HTTP responsecontentLength- the length of the content we are returning in bytes, if known- Throws:
InvalidAttachmentPathException- if the attachment path is invalidAttachmentNotFoundException- if the specified attachment cannot be foundDataAccessException- if there is a problem accessing the database- See Also:
-
isUserLoggedIn
protected boolean isUserLoggedIn() -
getLoggedInUser
-
isAnonymousUserPermittedToViewAttachment
-
isImageAttachmentJwtTokenPresent
protected boolean isImageAttachmentJwtTokenPresent(jakarta.servlet.http.HttpServletRequest request)
-