Interface EntityTags
-
public interface EntityTagsProvides services for validating "If-Match" and "If-None-Match" request headers. Also provides a facility for generating an "ETag" header automatically from a secure digest of aHttpServletResponse.- Author:
- cdivilly
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classEntityTags.EntityTagType
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringETAGstatic java.lang.StringIF_MATCHstatic java.lang.StringIF_NONE_MATCH
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description EntityTag.Builderbuilder()Return a new instance of anEntityTag.BuilderEntityTagentityTag(java.lang.String text)This method formats a textual value into a digested, strongEntityTagvalue.EntityTagentityTag(javax.servlet.http.HttpServletRequest request, java.lang.String headerName)Parses anEntityTagvalue from the specified header.booleanetag(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, HasGetMethod servlet)Adapt aHttpServletResponseto produce a strong "ETag" generated from a secure digest of the response headers and body.booleanetag(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, HasGetMethod servlet, EntityTags.EntityTagType etagType)Adapt aHttpServletResponseto produce a strong "ETag" generated from a secure digest of the response headers and body.booleanhasPrecondition(javax.servlet.http.HttpServletRequest request)Determine if the specified request is a conditional HTTP request.booleanhasPrecondition(javax.servlet.http.HttpServletRequest request, EntityTags.EntityTagType etagType)Determine if the specified request is a conditional HTTP request.EntityTagparse(java.lang.CharSequence text)Parses text into anEntityTagvalue.voidvalidatePrecondition(javax.servlet.http.HttpServletRequest request, java.lang.CharSequence currentEntityTag)Validate whether the pre-condition in the request matches the current "ETag" value of the requested resource.
-
-
-
Field Detail
-
IF_MATCH
static final java.lang.String IF_MATCH
- See Also:
- RFC 2616 Section 14.24, Constant Field Values
-
IF_NONE_MATCH
static final java.lang.String IF_NONE_MATCH
- See Also:
- RFC 2616 Section 14.26, Constant Field Values
-
ETAG
static final java.lang.String ETAG
- See Also:
- RFC 2616 Section 14.19, Constant Field Values
-
-
Method Detail
-
hasPrecondition
boolean hasPrecondition(javax.servlet.http.HttpServletRequest request)
Determine if the specified request is a conditional HTTP request. A request is conditional if it containsIF_MATCHfor a PUT,POST,PATCH or DELETE method, andIF_NONE_MATCHfor a GET or HEAD method- Parameters:
request- The HTTP request to check for presence of a pre-condition- Returns:
- true if request has a precondition, false otherwise
-
hasPrecondition
boolean hasPrecondition(javax.servlet.http.HttpServletRequest request, EntityTags.EntityTagType etagType)Determine if the specified request is a conditional HTTP request. A request is conditional if it containsIF_MATCHfor a PUT,POST,PATCH or DELETE method, andIF_NONE_MATCHfor a GET or HEAD method- Parameters:
request- The HTTP request to check for presence of a pre-conditionetagType- The type of the EntityTag- Returns:
- true if request has a precondition, false otherwise
-
validatePrecondition
void validatePrecondition(javax.servlet.http.HttpServletRequest request, java.lang.CharSequence currentEntityTag)Validate whether the pre-condition in the request matches the current "ETag" value of the requested resource.- Parameters:
request- The request to be validatedcurrentEntityTag- The current "ETag" value of the requested resource
-
parse
EntityTag parse(java.lang.CharSequence text)
Parses text into anEntityTagvalue. The value must be correctly formatted as a quoted ETag value.- Parameters:
text- The text value to parse- Returns:
- EntityTag instance, or null if the supplied parameter is null or "*"
- Throws:
java.lang.IllegalArgumentException- if the value is not correctly formatted
-
entityTag
EntityTag entityTag(java.lang.String text)
This method formats a textual value into a digested, strongEntityTagvalue. This method is equivalent to:String text = ...; EntityTags tags = ...; EntityTag tag = tags.builder().append(text).build();
-
entityTag
EntityTag entityTag(javax.servlet.http.HttpServletRequest request, java.lang.String headerName)
Parses anEntityTagvalue from the specified header. If the header is "If-Match" orIF_NONE_MATCHand the value is*then a null value will be returned.- Parameters:
request- The request to examineheaderName- The name of the HTTP Header- Returns:
- The
EntityTagvalue or null if the header is absent or has no value
-
builder
EntityTag.Builder builder()
Return a new instance of anEntityTag.Builder- Returns:
EntityTag.Builderinstance
-
etag
boolean etag(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, HasGetMethod servlet, EntityTags.EntityTagType etagType) throws javax.servlet.ServletException, java.io.IOExceptionAdapt aHttpServletResponseto produce a strong "ETag" generated from a secure digest of the response headers and body. This method also performs any validation This provides a simple mechanism to produce a guaranteed correct "ETag", however the simplicity has some costs:- The CPU overhead of generating the secure digest
- The memory overhead of buffering the entire response in order to produce the digest
HasGetMethodinterface and pass a reference to themselves as the final parameter.- Parameters:
request- The request being processedresponse- The response object provided by the servlet containerservlet- The servlet which will produce the responseetagType- The type of the EntityTag- Returns:
- true if the servlet should proceed with processing the request, false otherwise
- Throws:
javax.servlet.ServletException- if the HTTP request cannot be handledjava.io.IOException- if an input or output error occurs while the request is being handled- See Also:
HasGetMethod
-
etag
boolean etag(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, HasGetMethod servlet) throws javax.servlet.ServletException, java.io.IOExceptionAdapt aHttpServletResponseto produce a strong "ETag" generated from a secure digest of the response headers and body. This method also performs any validation This provides a simple mechanism to produce a guaranteed correct "ETag", however the simplicity has some costs:- The CPU overhead of generating the secure digest
- The memory overhead of buffering the entire response in order to produce the digest
HasGetMethodinterface and pass a reference to themselves as the final parameter. All methods will be processed- Parameters:
request- The request being processedresponse- The response object provided by the servlet containerservlet- The servlet which will produce the response- Returns:
- true if the servlet should proceed with processing the request, false otherwise
- Throws:
javax.servlet.ServletException- if the HTTP request cannot be handledjava.io.IOException- if an input or output error occurs while the request is being handled- See Also:
HasGetMethod
-
-