Class AbstractDownloadStrategy
java.lang.Object
com.atlassian.bamboo.plugin.servlet.AbstractDownloadStrategy
- All Implemented Interfaces:
com.atlassian.plugin.servlet.DownloadStrategy
- Direct Known Subclasses:
ArtifactDownloadStrategy
,BambooSpecsZipDownloadStrategy
,DefaultDownloadStrategy
,DeploymentDownloadStrategy
,GlobalArtifactDownloadStrategy
,SpecLogsDownloadStrategy
public abstract class AbstractDownloadStrategy
extends Object
implements com.atlassian.plugin.servlet.DownloadStrategy
-
Field Summary
Modifier and TypeFieldDescriptionprotected final BambooAuthenticationContext
protected final BambooContentTypeResolver
protected final BambooPermissionManager
protected static final org.apache.logging.log4j.Logger
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractDownloadStrategy
(AdministrationConfigurationAccessor administrationConfigurationAccessor, BambooContentTypeResolver bambooContentTypeResolver, BambooAuthenticationContext authenticationContext, BambooPermissionManager bambooPermissionManager) -
Method Summary
Modifier and TypeMethodDescriptiongenerateETag
(File file) Generates an ETag for a given file based on its last modified timestamp and lengthprotected abstract @NotNull TitledFile
getFileToServe
(RequestPath requestPath, javax.servlet.http.HttpServletRequest request) protected abstract String
Returns the servlet path handled by this download strategy.static boolean
isByteRangeRequest
(javax.servlet.http.HttpServletRequest request) Checks if the request contains a valid Byte-Range headerboolean
boolean
protected RangeHeaderResult
processRangeHeader
(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, long fileLength) Processes the Range and If-Range headers from the HTTP request to determine the byte range to be served This method validates the range, calculates the start and content length, and sets the appropriate response headers If the range is invalid or not satisfiable, it sets the response status to 416 (Range Not Satisfiable) If an If-Range header is present, it checks whether the file has changed since the specified date or ETag If the file has changed, it serves the entire file instead of the rangevoid
serveFile
(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse) protected void
serveOrdinaryFile
(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, TitledFile titledFileToServe) Serves the specified file, handling both full and partial content requestsprotected void
throwPermissionException
(RequestPath requestPath) Throws an exception indicating that the current user does not have permission to access the requested item.
-
Field Details
-
log
protected static final org.apache.logging.log4j.Logger log -
bambooContentTypeResolver
-
authenticationContext
-
bambooPermissionManager
-
-
Constructor Details
-
AbstractDownloadStrategy
protected AbstractDownloadStrategy(AdministrationConfigurationAccessor administrationConfigurationAccessor, BambooContentTypeResolver bambooContentTypeResolver, BambooAuthenticationContext authenticationContext, BambooPermissionManager bambooPermissionManager)
-
-
Method Details
-
matches
- Specified by:
matches
in interfacecom.atlassian.plugin.servlet.DownloadStrategy
-
getServletPath
Returns the servlet path handled by this download strategy. Includes the leading "/" but no trailing "/", e.g. "/download" or "/artifact". -
serveFile
public void serveFile(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse) throws com.atlassian.plugin.servlet.DownloadException - Specified by:
serveFile
in interfacecom.atlassian.plugin.servlet.DownloadStrategy
- Throws:
com.atlassian.plugin.servlet.DownloadException
-
getFileToServe
@NotNull protected abstract @NotNull TitledFile getFileToServe(RequestPath requestPath, javax.servlet.http.HttpServletRequest request) throws org.acegisecurity.AccessDeniedException, FileNotFoundException, UserNotLoggedInException, WebValidationException - Returns:
- file to serve, with an optional display name if file is a directory
- Throws:
org.acegisecurity.AccessDeniedException
FileNotFoundException
UserNotLoggedInException
WebValidationException
-
serveOrdinaryFile
protected void serveOrdinaryFile(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, TitledFile titledFileToServe) throws IOException Serves the specified file, handling both full and partial content requests- Parameters:
httpServletRequest
- The servlet request containing client datahttpServletResponse
- The servlet response for sending the file datatitledFileToServe
- The file to be served, with metadata- Throws:
IOException
- If an error occurs during file access or streaming
-
isByteRangeRequest
public static boolean isByteRangeRequest(javax.servlet.http.HttpServletRequest request) Checks if the request contains a valid Byte-Range header- Parameters:
request
- The HTTP request- Returns:
- boolean True if the request contains a Range header, false otherwise
-
generateETag
Generates an ETag for a given file based on its last modified timestamp and length- Parameters:
file
- The file for which the ETag is generated- Returns:
- A string representing the ETag
-
processRangeHeader
protected RangeHeaderResult processRangeHeader(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, long fileLength) Processes the Range and If-Range headers from the HTTP request to determine the byte range to be served This method validates the range, calculates the start and content length, and sets the appropriate response headers If the range is invalid or not satisfiable, it sets the response status to 416 (Range Not Satisfiable) If an If-Range header is present, it checks whether the file has changed since the specified date or ETag If the file has changed, it serves the entire file instead of the range- Parameters:
httpServletRequest
- The servlet request containing the Range and If-Range headers (if present)httpServletResponse
- The servlet response to set the headers onfileLength
- The total length of the file being requested- Returns:
- A
RangeHeaderResult
containing the start position and content length to be served, or null if the range is invalid
-
throwPermissionException
protected void throwPermissionException(RequestPath requestPath) throws UserNotLoggedInException, org.acegisecurity.AccessDeniedException Throws an exception indicating that the current user does not have permission to access the requested item. The requestPath parameter may be included in the exception message and/or logs.- Throws:
UserNotLoggedInException
org.acegisecurity.AccessDeniedException
-
isCompressionEnabled
public boolean isCompressionEnabled()
-