java.lang.Object
net.i2p.servlet.RequestWrapper
Wraps an HttpServletRequest and adds multipart-aware access to the parameters and files of a
multipart/form-data request, using the Servlet 3.0 Part API. Only the multipart variants of the accessors are wrapped; everything else is passed straight through. The Servlet API container already parses multipart requests, so this class deliberately does not parse them again. A part larger than the 64KB MAX_STRING_SIZE limit is not read into a String, and an IllegalStateException from the container (which signals an oversized request) is logged and rethrown.Field Summary
FieldsModifier and TypeFieldDescriptionParameter values decoded from the body.Parameter names already enumerated.private final HttpServletRequestThe request being wrapped.private final booleanTrue when the body is a multipart form.private static final intLargest parameter value read, in bytes.Constructor Summary
ConstructorsConstructorDescriptionRequestWrapper(HttpServletRequest httpRequest) Wrap a servlet request, noting whether it carries multipart parts.Method Summary
Modifier and TypeMethodDescriptiongetAttribute(String string) Look up a request attribute; multipart parts are not consulted.intThe declared length of the request body.The request's content type header.getContentType(String partName) The content type declared by a single multipart part.getFilename(String partName) The filename the client submitted with a multipart part.getInputStream(String partName) Open a multipart part's body for reading.getParameter(String name) Look up a request parameter, falling back to the multipart part of the same name.getParameter(String name, String defaultValue) Look up a request parameter or multipart part, falling back to a default.The names this request carries, multipart part names included.The session bound to this request, created if it has none.getSession(boolean b) The session bound to this request.private static voidLog a request error.
Field Details
httpRequest
The request being wrapped.isMultiPartRequest
private final boolean isMultiPartRequestTrue when the body is a multipart form.cache
cachedParameterNames
MAX_STRING_SIZE
private static final int MAX_STRING_SIZELargest parameter value read, in bytes.- See Also:
Constructor Details
RequestWrapper
Wrap a servlet request, noting whether it carries multipart parts.- Parameters:
httpRequest- the request to wrap
Method Details
getSession
The session bound to this request.- Parameters:
b- true to create a session when the request has none- Returns:
- the bound session, or a new one when b is true
getParameter
getSession
The session bound to this request, created if it has none.- Returns:
- the bound session, created if the request has none
getParameterNames
The names this request carries, multipart part names included.- Returns:
- List of request parameter names
- Throws:
IllegalStateException- if the request is too large
getContentLength
public int getContentLength()The declared length of the request body.- Returns:
- The total length of the content.
getContentType
The request's content type header.- Returns:
- The content type of the request.
getContentType
The content type declared by a single multipart part.- Parameters:
partName- the multipart part to read the content type from- Returns:
- the content type
- Throws:
IllegalStateException- if the request is too large
getAttribute
getParameter
Look up a request parameter or multipart part, falling back to a default.- Parameters:
name- the request parameter or multipart part name to look updefaultValue- returned when the request carries no value for name; for a multipart part also returned when the part is absent- Returns:
- the value, or defaultValue when the request carries none
- Throws:
IllegalStateException- if the request is too large
getFilename
The filename the client submitted with a multipart part.- Parameters:
partName- the multipart part to read the submitted filename from- Returns:
- the submitted filename, or null when the part is absent
- Throws:
IllegalStateException- if the request is too large
getInputStream
Open a multipart part's body for reading.- Parameters:
partName- the multipart part to open the body of- Returns:
- the input stream
- Throws:
IllegalStateException- if the request is too large
log