Class DefaultServlet
- All Implemented Interfaces:
Serializable,Servlet,ServletConfig
- Direct Known Subclasses:
WebdavServlet
The default resource-serving servlet for most web applications, used to serve static resources such as HTML pages and images.
This servlet is intended to be mapped to / e.g.:
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
It can be mapped to sub-paths, however in all cases resources are served from the web application resource root using
the full path from the root of the web application context.
e.g. given a web application structure:
/context
/images
tomcat2.jpg
/static
/images
tomcat.jpg
... and a servlet mapping that maps only /static/* to the default servlet:
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/static/*</url-pattern>
</servlet-mapping>
Then a request to /context/static/images/tomcat.jpg will succeed while a request to
/context/images/tomcat2.jpg will fail.
- Author:
- Craig R. McClanahan, Remy Maucherat
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classprotected static classprotected static classA class encapsulating the sorting of resources. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intSize of file transfer buffer in bytes.protected DefaultServlet.CompressionFormat[]List of compression formats to serve and their preference order.protected StringAllow customized directory listing per context.protected intThe debugging detail level for this servlet.protected StringFile encoding to be used when reading static files.protected static final ArrayList<DefaultServlet.Range> Full range marker.protected StringAllow customized directory listing per instance.protected intThe input buffer size to use when serving resources.protected booleanShould we generate directory listings?protected StringAllow customized directory listing per directory.protected static final StringMIME multipart separation stringprotected intThe output buffer size to use when serving resources.protected StringAllow a readme file to be included.protected booleanRead only flag.protected WebResourceRootThe complete set of web application resourcesprotected intMinimum size for sendfile usage in bytes.protected booleanFlag to determine if server information is presented.protected static final StringManagerThe string manager for this package.protected booleanFlag to determine if resources should be sorted.protected DefaultServlet.SortManagerThe sorting manager for sorting files and directories.protected booleanDeprecated. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancheckIfHeaders(HttpServletRequest request, HttpServletResponse response, WebResource resource) Check if the conditions specified in the optional If headers are satisfied.protected booleancheckIfMatch(HttpServletRequest request, HttpServletResponse response, WebResource resource) Check if the if-match condition is satisfied.protected booleancheckIfModifiedSince(HttpServletRequest request, HttpServletResponse response, WebResource resource) Check if the if-modified-since condition is satisfied.protected booleancheckIfNoneMatch(HttpServletRequest request, HttpServletResponse response, WebResource resource) Check if the if-none-match condition is satisfied.protected booleancheckIfRange(HttpServletRequest request, HttpServletResponse response, WebResource resource) Check if the if-range condition is satisfied.protected booleancheckIfUnmodifiedSince(HttpServletRequest request, HttpServletResponse response, WebResource resource) Check if the if-unmodified-since condition is satisfied.protected booleancheckSendfile(HttpServletRequest request, HttpServletResponse response, WebResource resource, long length, DefaultServlet.Range range) Check if sendfile can be used.protected voidcopy(InputStream is, PrintWriter writer, String encoding) Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).protected voidcopy(InputStream is, ServletOutputStream ostream) Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).protected voidcopy(WebResource resource, ServletOutputStream ostream, Iterator<DefaultServlet.Range> ranges, String contentType) Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).protected voidcopy(WebResource resource, ServletOutputStream ostream, DefaultServlet.Range range) Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).protected IOExceptioncopyRange(InputStream istream, ServletOutputStream ostream) Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).protected IOExceptioncopyRange(InputStream istream, ServletOutputStream ostream, long start, long end) Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).protected IOExceptioncopyRange(Reader reader, PrintWriter writer) Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).voiddestroy()Called by the servlet container to indicate to a servlet that the servlet is being taken out of service.protected StringDetermines the methods normally allowed for the resource.protected voiddoDelete(HttpServletRequest req, HttpServletResponse resp) Called by the server (via theservicemethod) to allow a servlet to handle a DELETE request.protected voiddoGet(HttpServletRequest request, HttpServletResponse response) Called by the server (via theservicemethod) to allow a servlet to handle a GET request.protected voiddoHead(HttpServletRequest request, HttpServletResponse response) Receives an HTTP HEAD request from the protectedservicemethod and handles the request.protected voiddoOptions(HttpServletRequest req, HttpServletResponse resp) Override default implementation to ensure that TRACE is correctly handled.protected voiddoPost(HttpServletRequest request, HttpServletResponse response) Called by the server (via theservicemethod) to allow a servlet to handle a POST request.protected voiddoPut(HttpServletRequest req, HttpServletResponse resp) Called by the server (via theservicemethod) to allow a servlet to handle a PUT request.protected FileexecutePartialPut(HttpServletRequest req, DefaultServlet.Range range, String path) Handle a partial PUT.protected SourcefindXsltSource(WebResource directory) Return a Source for the xsl template (if possible).protected StringgenerateETag(WebResource resource) Provides the entity tag (the ETag header) for the given resource.protected StringgetPathPrefix(HttpServletRequest request) Determines the appropriate path to prepend resources with when generating directory listings.protected StringgetReadme(WebResource directory, String encoding) Get the readme file as a string.protected StringgetRelativePath(HttpServletRequest request) Return the relative path associated with this servlet.protected StringgetRelativePath(HttpServletRequest request, boolean allowEmptyPath) voidinit()A convenience method which can be overridden so that there's no need to callsuper.init(config).protected booleanprotected booleanChecks if range request is supported by serverprotected booleanprotected DefaultServlet.RangeparseContentRange(HttpServletRequest request, HttpServletResponse response) Parse the content-range header.protected ArrayList<DefaultServlet.Range> parseRange(HttpServletRequest request, HttpServletResponse response, WebResource resource) Parse the range header.protected InputStreamrender(String contextPath, WebResource resource, String encoding) Deprecated.protected InputStreamrender(HttpServletRequest request, String contextPath, WebResource resource, String encoding) Decide which way to render.protected InputStreamrenderHtml(String contextPath, WebResource resource, String encoding) Deprecated.Unused.protected InputStreamrenderHtml(HttpServletRequest request, String contextPath, WebResource resource, String encoding) Return an InputStream to an HTML representation of the contents of this directory.protected StringrenderSize(long size) Render the specified file size (in bytes).protected StringrenderTimestamp(long timestamp) Render the specified file timestamp.protected InputStreamrenderXml(String contextPath, WebResource resource, Source xsltSource, String encoding) Deprecated.Unused.protected InputStreamrenderXml(HttpServletRequest request, String contextPath, WebResource resource, Source xsltSource, String encoding) Return an InputStream to an XML representation of the contents this directory.protected StringrewriteUrl(String path) URL rewriter.protected voidsendNotAllowed(HttpServletRequest req, HttpServletResponse resp) protected voidserveResource(HttpServletRequest request, HttpServletResponse response, boolean content, String inputEncoding) Serve the specified resource, optionally including the data content.protected voidservice(HttpServletRequest req, HttpServletResponse resp) Receives standard HTTP requests from the publicservicemethod and dispatches them to thedoMethod methods defined in this class.Methods inherited from class javax.servlet.http.HttpServlet
doTrace, getLastModified, serviceMethods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Field Details
-
sm
The string manager for this package. -
FULL
Full range marker. -
mimeSeparation
-
BUFFER_SIZE
protected static final int BUFFER_SIZESize of file transfer buffer in bytes.- See Also:
-
debug
protected int debugThe debugging detail level for this servlet. -
input
protected int inputThe input buffer size to use when serving resources. -
listings
protected boolean listingsShould we generate directory listings? -
readOnly
protected boolean readOnlyRead only flag. By default, it's set to true. -
compressionFormats
List of compression formats to serve and their preference order. -
output
protected int outputThe output buffer size to use when serving resources. -
localXsltFile
Allow customized directory listing per directory. -
contextXsltFile
Allow customized directory listing per context. -
globalXsltFile
Allow customized directory listing per instance. -
readmeFile
Allow a readme file to be included. -
resources
The complete set of web application resources -
fileEncoding
File encoding to be used when reading static files. If none is specified the platform default is used. -
sendfileSize
protected int sendfileSizeMinimum size for sendfile usage in bytes. -
useAcceptRanges
Deprecated.This option will be removed without replacement in Tomcat 12 onwards where it will effectively be hard coded totrue.Should the Accept-Ranges: bytes header be send with static resources? -
showServerInfo
protected boolean showServerInfoFlag to determine if server information is presented. -
sortListings
protected boolean sortListingsFlag to determine if resources should be sorted. -
sortManager
The sorting manager for sorting files and directories.
-
-
Constructor Details
-
DefaultServlet
public DefaultServlet()
-
-
Method Details
-
destroy
public void destroy()Description copied from class:javax.servlet.GenericServletCalled by the servlet container to indicate to a servlet that the servlet is being taken out of service. SeeServlet.destroy().- Specified by:
destroyin interfaceServlet- Overrides:
destroyin classGenericServlet
-
init
Description copied from class:javax.servlet.GenericServletA convenience method which can be overridden so that there's no need to callsuper.init(config).Instead of overriding
GenericServlet.init(ServletConfig), simply override this method and it will be called byGenericServlet.init(ServletConfig config). TheServletConfigobject can still be retrieved viaGenericServlet.getServletConfig().- Overrides:
initin classGenericServlet- Throws:
ServletException- if an exception occurs that interrupts the servlet's normal operation
-
getRelativePath
Return the relative path associated with this servlet.- Parameters:
request- The servlet request we are processing- Returns:
- the relative path
-
getRelativePath
-
getPathPrefix
Determines the appropriate path to prepend resources with when generating directory listings. Depending on the behaviour ofgetRelativePath(HttpServletRequest)this will change.- Parameters:
request- the request to determine the path for- Returns:
- the prefix to apply to all resources in the listing.
-
isListings
protected boolean isListings() -
isReadOnly
protected boolean isReadOnly() -
service
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException Description copied from class:javax.servlet.http.HttpServletReceives standard HTTP requests from the publicservicemethod and dispatches them to thedoMethod methods defined in this class. This method is an HTTP-specific version of theServlet.service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)method. There's no need to override this method.- Overrides:
servicein classHttpServlet- Parameters:
req- theHttpServletRequestobject that contains the request the client made of the servletresp- theHttpServletResponseobject that contains the response the servlet returns to the client- Throws:
ServletException- if the HTTP request cannot be handledIOException- if an input or output error occurs while the servlet is handling the HTTP request- See Also:
-
doGet
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException Description copied from class:javax.servlet.http.HttpServletCalled by the server (via theservicemethod) to allow a servlet to handle a GET request.Overriding this method to support a GET request also automatically supports an HTTP HEAD request. A HEAD request is a GET request that returns no body in the response, only the request header fields.
When overriding this method, read the request data, write the response headers, get the response's Writer or output stream object, and finally, write the response data. It's best to include content type and encoding. When using a
PrintWriterobject to return the response, set the content type before accessing thePrintWriterobject.The servlet container must write the headers before committing the response, because in HTTP the headers must be sent before the response body.
Where possible, set the Content-Length header (with the
ServletResponse.setContentLength(int)method), to allow the servlet container to use a persistent connection to return its response to the client, improving performance. The content length is automatically set if the entire response fits inside the response buffer.When using HTTP 1.1 chunked encoding (which means that the response has a Transfer-Encoding header), do not set the Content-Length header.
The GET method should be safe, that is, without any side effects for which users are held responsible. For example, most form queries have no side effects. If a client request is intended to change stored data, the request should use some other HTTP method.
The GET method should also be idempotent, meaning that it can be safely repeated. Sometimes making a method safe also makes it idempotent. For example, repeating queries is both safe and idempotent, but buying a product online or modifying data is neither safe nor idempotent.
If the request is incorrectly formatted,
doGetreturns an HTTP "Bad Request" message.- Overrides:
doGetin classHttpServlet- Parameters:
request- anHttpServletRequestobject that contains the request the client has made of the servletresponse- anHttpServletResponseobject that contains the response the servlet sends to the client- Throws:
IOException- if an input or output error is detected when the servlet handles the GET requestServletException- if the request for the GET could not be handled- See Also:
-
doHead
protected void doHead(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException Description copied from class:javax.servlet.http.HttpServletReceives an HTTP HEAD request from the protected
servicemethod and handles the request. The client sends a HEAD request when it wants to see only the headers of a response, such as Content-Type or Content-Length. The HTTP HEAD method counts the output bytes in the response to set the Content-Length header accurately.If you override this method, you can avoid computing the response body and just set the response headers directly to improve performance. Make sure that the
doHeadmethod you write is both safe and idempotent (that is, protects itself from being called multiple times for one HTTP HEAD request).If the HTTP HEAD request is incorrectly formatted,
doHeadreturns an HTTP "Bad Request" message.- Overrides:
doHeadin classHttpServlet- Parameters:
request- the request object that is passed to the servletresponse- the response object that the servlet uses to return the headers to the client- Throws:
IOException- if an input or output error occursServletException- if the request for the HEAD could not be handled
-
doOptions
protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException Override default implementation to ensure that TRACE is correctly handled.- Overrides:
doOptionsin classHttpServlet- Parameters:
req- theHttpServletRequestobject that contains the request the client made of the servletresp- theHttpServletResponseobject that contains the response the servlet returns to the client- Throws:
IOException- if an input or output error occurs while the servlet is handling the OPTIONS requestServletException- if the request for the OPTIONS cannot be handled
-
determineMethodsAllowed
Determines the methods normally allowed for the resource.- Parameters:
req- The Servlet request- Returns:
- The allowed HTTP methods
-
sendNotAllowed
- Throws:
IOException
-
doPost
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException Description copied from class:javax.servlet.http.HttpServletCalled by the server (via theservicemethod) to allow a servlet to handle a POST request. The HTTP POST method allows the client to send data of unlimited length to the Web server a single time and is useful when posting information such as credit card numbers.When overriding this method, read the request data, write the response headers, get the response's Writer or output stream object, and finally, write the response data. It's best to include content type and encoding. When using a
PrintWriterobject to return the response, set the content type before accessing thePrintWriterobject.The servlet container must write the headers before committing the response, because in HTTP the headers must be sent before the response body.
Where possible, set the Content-Length header (with the
ServletResponse.setContentLength(int)method), to allow the servlet container to use a persistent connection to return its response to the client, improving performance. The content length is automatically set if the entire response fits inside the response buffer.When using HTTP 1.1 chunked encoding (which means that the response has a Transfer-Encoding header), do not set the Content-Length header.
This method does not need to be either safe or idempotent. Operations requested through POST can have side effects for which the user can be held accountable, for example, updating stored data or buying items online.
If the HTTP POST request is incorrectly formatted,
doPostreturns an HTTP "Bad Request" message.- Overrides:
doPostin classHttpServlet- Parameters:
request- anHttpServletRequestobject that contains the request the client has made of the servletresponse- anHttpServletResponseobject that contains the response the servlet sends to the client- Throws:
IOException- if an input or output error is detected when the servlet handles the requestServletException- if the request for the POST could not be handled- See Also:
-
doPut
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException Description copied from class:javax.servlet.http.HttpServletCalled by the server (via theservicemethod) to allow a servlet to handle a PUT request. The PUT operation allows a client to place a file on the server and is similar to sending a file by FTP.When overriding this method, leave intact any content headers sent with the request (including Content-Length, Content-Type, Content-Transfer-Encoding, Content-Encoding, Content-Base, Content-Language, Content-Location, Content-MD5, and Content-Range). If your method cannot handle a content header, it must issue an error message (HTTP 501 - Not Implemented) and discard the request. For more information on HTTP 1.1, see RFC 2616 .
This method does not need to be either safe or idempotent. Operations that
doPutperforms can have side effects for which the user can be held accountable. When using this method, it may be useful to save a copy of the affected URL in temporary storage.If the HTTP PUT request is incorrectly formatted,
doPutreturns an HTTP "Bad Request" message.- Overrides:
doPutin classHttpServlet- Parameters:
req- theHttpServletRequestobject that contains the request the client made of the servletresp- theHttpServletResponseobject that contains the response the servlet returns to the client- Throws:
ServletException- if the request for the PUT cannot be handledIOException- if an input or output error occurs while the servlet is handling the PUT request
-
executePartialPut
protected File executePartialPut(HttpServletRequest req, DefaultServlet.Range range, String path) throws IOException Handle a partial PUT. New content specified in request is appended to existing content in oldRevisionContent (if present). This code does not support simultaneous partial updates to the same resource.- Parameters:
req- The Servlet requestrange- The range that will be writtenpath- The path- Returns:
- the associated file object
- Throws:
IOException- an IO error occurred
-
doDelete
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException Description copied from class:javax.servlet.http.HttpServletCalled by the server (via theservicemethod) to allow a servlet to handle a DELETE request. The DELETE operation allows a client to remove a document or Web page from the server.This method does not need to be either safe or idempotent. Operations requested through DELETE can have side effects for which users can be held accountable. When using this method, it may be useful to save a copy of the affected URL in temporary storage.
If the HTTP DELETE request is incorrectly formatted,
doDeletereturns an HTTP "Bad Request" message.- Overrides:
doDeletein classHttpServlet- Parameters:
req- theHttpServletRequestobject that contains the request the client made of the servletresp- theHttpServletResponseobject that contains the response the servlet returns to the client- Throws:
ServletException- if the request for the DELETE cannot be handledIOException- if an input or output error occurs while the servlet is handling the DELETE request
-
checkIfHeaders
protected boolean checkIfHeaders(HttpServletRequest request, HttpServletResponse response, WebResource resource) throws IOException Check if the conditions specified in the optional If headers are satisfied.- Parameters:
request- The servlet request we are processingresponse- The servlet response we are creatingresource- The resource- Returns:
trueif the resource meets all the specified conditions, andfalseif any of the conditions is not satisfied, in which case request processing is stopped- Throws:
IOException- an IO error occurred
-
rewriteUrl
-
serveResource
protected void serveResource(HttpServletRequest request, HttpServletResponse response, boolean content, String inputEncoding) throws IOException, ServletException Serve the specified resource, optionally including the data content.- Parameters:
request- The servlet request we are processingresponse- The servlet response we are creatingcontent- Should the content be included?inputEncoding- The encoding to use if it is necessary to access the source as characters rather than as bytes- Throws:
IOException- if an input/output error occursServletException- if a servlet-specified error occurs
-
parseContentRange
protected DefaultServlet.Range parseContentRange(HttpServletRequest request, HttpServletResponse response) throws IOException Parse the content-range header.- Parameters:
request- The servlet request we are processingresponse- The servlet response we are creating- Returns:
- the partial content-range,
nullif the content-range header was invalid or#IGNOREif there is no header to process - Throws:
IOException- an IO error occurred
-
parseRange
protected ArrayList<DefaultServlet.Range> parseRange(HttpServletRequest request, HttpServletResponse response, WebResource resource) throws IOException Parse the range header.The caller is required to have confirmed that the requested resource exists and is a file before calling this method.
- Parameters:
request- The servlet request we are processingresponse- The servlet response we are creatingresource- The resource- Returns:
- a list of ranges,
nullif the range header was invalid or#FULLif the Range header should be ignored. - Throws:
IOException- an IO error occurred
-
render
@Deprecated protected InputStream render(String contextPath, WebResource resource, String encoding) throws IOException, ServletException Deprecated.Decide which way to render. HTML or XML.- Parameters:
contextPath- The pathresource- The resourceencoding- The encoding to use to process the readme (if any)- Returns:
- the input stream with the rendered output
- Throws:
IOException- an IO error occurredServletException- rendering error
-
render
protected InputStream render(HttpServletRequest request, String contextPath, WebResource resource, String encoding) throws IOException, ServletException Decide which way to render. HTML or XML.- Parameters:
request- The HttpServletRequest being servedcontextPath- The pathresource- The resourceencoding- The encoding to use to process the readme (if any)- Returns:
- the input stream with the rendered output
- Throws:
IOException- an IO error occurredServletException- rendering error
-
renderXml
@Deprecated protected InputStream renderXml(String contextPath, WebResource resource, Source xsltSource, String encoding) throws ServletException, IOException Deprecated.Unused. Will be removed in Tomcat 10Return an InputStream to an XML representation of the contents this directory.- Parameters:
contextPath- Context path to which our internal paths are relativeresource- The associated resourcexsltSource- The XSL stylesheetencoding- The encoding to use to process the readme (if any)- Returns:
- the XML data
- Throws:
IOException- an IO error occurredServletException- rendering error
-
renderXml
protected InputStream renderXml(HttpServletRequest request, String contextPath, WebResource resource, Source xsltSource, String encoding) throws IOException, ServletException Return an InputStream to an XML representation of the contents this directory.- Parameters:
request- The HttpServletRequest being servedcontextPath- Context path to which our internal paths are relativeresource- The associated resourcexsltSource- The XSL stylesheetencoding- The encoding to use to process the readme (if any)- Returns:
- the XML data
- Throws:
IOException- an IO error occurredServletException- rendering error
-
renderHtml
@Deprecated protected InputStream renderHtml(String contextPath, WebResource resource, String encoding) throws IOException Deprecated.Unused. Will be removed in Tomcat 10Return an InputStream to an HTML representation of the contents of this directory.- Parameters:
contextPath- Context path to which our internal paths are relativeresource- The associated resourceencoding- The encoding to use to process the readme (if any)- Returns:
- the HTML data
- Throws:
IOException- an IO error occurred
-
renderHtml
protected InputStream renderHtml(HttpServletRequest request, String contextPath, WebResource resource, String encoding) throws IOException Return an InputStream to an HTML representation of the contents of this directory.- Parameters:
request- The HttpServletRequest being servedcontextPath- Context path to which our internal paths are relativeresource- The associated resourceencoding- The encoding to use to process the readme (if any)- Returns:
- the HTML data
- Throws:
IOException- an IO error occurred
-
renderSize
Render the specified file size (in bytes).- Parameters:
size- File size (in bytes)- Returns:
- the formatted size
-
renderTimestamp
Render the specified file timestamp.- Parameters:
timestamp- File timestamp- Returns:
- the formatted timestamp
-
getReadme
Get the readme file as a string.- Parameters:
directory- The directory to searchencoding- The readme encoding- Returns:
- the readme for the specified directory
-
findXsltSource
Return a Source for the xsl template (if possible).- Parameters:
directory- The directory to search- Returns:
- the source for the specified directory
- Throws:
IOException- an IO error occurred
-
checkSendfile
protected boolean checkSendfile(HttpServletRequest request, HttpServletResponse response, WebResource resource, long length, DefaultServlet.Range range) Check if sendfile can be used.- Parameters:
request- The Servlet requestresponse- The Servlet responseresource- The resourcelength- The length which will be written (will be used only if range is null)range- The range that will be written- Returns:
trueif sendfile should be used (writing is then delegated to the endpoint)
-
checkIfMatch
protected boolean checkIfMatch(HttpServletRequest request, HttpServletResponse response, WebResource resource) throws IOException Check if the if-match condition is satisfied.- Parameters:
request- The servlet request we are processingresponse- The servlet response we are creatingresource- The resource- Returns:
trueif the resource meets the specified condition, andfalseif the condition is not satisfied, in which case request processing is stopped- Throws:
IOException- an IO error occurred
-
checkIfModifiedSince
protected boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response, WebResource resource) Check if the if-modified-since condition is satisfied.- Parameters:
request- The servlet request we are processingresponse- The servlet response we are creatingresource- The resource- Returns:
trueif the resource meets the specified condition, andfalseif the condition is not satisfied, in which case request processing is stopped
-
checkIfNoneMatch
protected boolean checkIfNoneMatch(HttpServletRequest request, HttpServletResponse response, WebResource resource) throws IOException Check if the if-none-match condition is satisfied.- Parameters:
request- The servlet request we are processingresponse- The servlet response we are creatingresource- The resource- Returns:
trueif the resource meets the specified condition, andfalseif the condition is not satisfied, in which case request processing is stopped- Throws:
IOException- an IO error occurred
-
checkIfUnmodifiedSince
protected boolean checkIfUnmodifiedSince(HttpServletRequest request, HttpServletResponse response, WebResource resource) throws IOException Check if the if-unmodified-since condition is satisfied.- Parameters:
request- The servlet request we are processingresponse- The servlet response we are creatingresource- The resource- Returns:
trueif the resource meets the specified condition, andfalseif the condition is not satisfied, in which case request processing is stopped- Throws:
IOException- an IO error occurred
-
checkIfRange
protected boolean checkIfRange(HttpServletRequest request, HttpServletResponse response, WebResource resource) throws IOException Check if the if-range condition is satisfied. The calling method is required to ensure a Range header is present and that Range requests are supported for the current resource.- Parameters:
request- The servlet request we are processingresponse- The servlet response we are creatingresource- The resource- Returns:
trueif the resource meets the specified condition, andfalseif the condition is not satisfied, resulting in transfer of the new selected representation instead of a 412 (Precondition Failed) response. If the if-range condition is not valid then an appropriate status code will be set, the response will be committed and this method will returnfalse- Throws:
IOException- an IO error occurred
-
isRangeRequestsSupported
protected boolean isRangeRequestsSupported()Checks if range request is supported by server- Returns:
trueserver supports range requests feature.
-
generateETag
Provides the entity tag (the ETag header) for the given resource. Intended to be over-ridden by custom DefaultServlet implementations that wish to use an alternative format for the entity tag.- Parameters:
resource- The resource for which an entity tag is required.- Returns:
- The result of calling
WebResource.getETag()on the given resource
-
copy
Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).- Parameters:
is- The input stream to read the source resource fromostream- The output stream to write to- Throws:
IOException- if an input/output error occurs
-
copy
Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).- Parameters:
is- The input stream to read the source resource fromwriter- The writer to write toencoding- The encoding to use when reading the source input stream- Throws:
IOException- if an input/output error occurs
-
copy
protected void copy(WebResource resource, ServletOutputStream ostream, DefaultServlet.Range range) throws IOException Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).- Parameters:
resource- The source resourceostream- The output stream to write torange- Range the client wanted to retrieve- Throws:
IOException- if an input/output error occurs
-
copy
protected void copy(WebResource resource, ServletOutputStream ostream, Iterator<DefaultServlet.Range> ranges, String contentType) throws IOException Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).- Parameters:
resource- The source resourceostream- The output stream to write toranges- Enumeration of the ranges the client wanted to retrievecontentType- Content type of the resource- Throws:
IOException- if an input/output error occurs
-
copyRange
Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).- Parameters:
istream- The input stream to read fromostream- The output stream to write to- Returns:
- Exception which occurred during processing
-
copyRange
Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).- Parameters:
reader- The reader to read fromwriter- The writer to write to- Returns:
- Exception which occurred during processing
-
copyRange
protected IOException copyRange(InputStream istream, ServletOutputStream ostream, long start, long end) Copy the contents of the specified input stream to the specified output stream, and ensure that both streams are closed before returning (even in the face of an exception).- Parameters:
istream- The input stream to read fromostream- The output stream to write tostart- Start of the range which will be copiedend- End of the range which will be copied- Returns:
- Exception which occurred during processing
-
true.