Package ej.hoka.http
Class HttpRequest
- java.lang.Object
-
- ej.hoka.http.HttpRequest
-
public class HttpRequest extends java.lang.ObjectRepresents a HTTP Request.
-
-
Field Summary
Fields Modifier and Type Field Description protected static intAFTERafter filter code.protected static intAFTER_ALLafter all filter code.protected static intBEFOREbefore filter code.protected static intBEFORE_ALLbefore all filter code.static intCONNECTValue returned bygetMethod()if the request method isCONNECT.static intDELETEValue returned bygetMethod()if the request method isDELETE.static intGETValue returned bygetMethod()if the request method isGET.static intHEADValue returned bygetMethod()if the request method isHEAD.static intOPTIONSValue returned bygetMethod()if the request method isOPTIONS.static intPATCHValue returned bygetMethod()if the request method isPATCH.static intPOSTValue returned bygetMethod()if the request method isPOST.static intPUTValue returned bygetMethod()if the request method isPUT.static intTRACEValue returned bygetMethod()if the request method isTRACE.
-
Constructor Summary
Constructors Modifier Constructor Description protectedHttpRequest(java.io.InputStream inputStream, EncodingRegistry encodingRegistry)Constructs a new instance of HTTPRequest.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddPathParameters(java.util.Map<java.lang.String,java.lang.String> parameters)Adds path parameters from a given list to the list of path path parameters of the request.protected voidaddSplatParameters(java.util.List<java.lang.String> splatParameters)Sets the splat Parameters.java.lang.ObjectgetAttribute(java.lang.String key)Get request server-side attribute by key.java.lang.StringgetCookie(java.lang.String name)Return the cookie of the request with given name.java.util.Map<java.lang.String,java.lang.String>getCookies()Returns the cookies of the request.java.lang.StringgetHeader(java.lang.String name)Returns the header field value associated to the given header fieldname.java.util.Map<java.lang.String,java.lang.String>getHeaders()Returns all HTTP header fields of the request.intgetMethod()java.lang.StringgetPathParam(java.lang.String param)Returns the path parameter value mapped to the given name.java.lang.StringgetQueryParam(java.lang.String name)Returns the query parameter mapped to the given name.java.util.Map<java.lang.String,java.lang.String>getQueryParams()Returns the Query parameters asMap.java.io.InputStreamgetRequestBody()useparseBody(BodyParser)for more option on request body provided parsers.java.util.List<java.lang.String>getSplatParams()Returns the list of splat parameters.java.lang.StringgetURI()Returns the request URI.java.lang.StringgetVersion()Returns the HTTP version request.<T> TparseBody(BodyParser<T> bodyParser)Request the body to be parsed.voidsetAttribute(java.lang.String key, java.lang.Object value)Set a request server-side attribute.
-
-
-
Field Detail
-
POST
public static final int POST
Value returned bygetMethod()if the request method isPOST.- See Also:
- Constant Field Values
-
GET
public static final int GET
Value returned bygetMethod()if the request method isGET.- See Also:
- Constant Field Values
-
PUT
public static final int PUT
Value returned bygetMethod()if the request method isPUT.- See Also:
- Constant Field Values
-
DELETE
public static final int DELETE
Value returned bygetMethod()if the request method isDELETE.- See Also:
- Constant Field Values
-
HEAD
public static final int HEAD
Value returned bygetMethod()if the request method isHEAD.- See Also:
- Constant Field Values
-
CONNECT
public static final int CONNECT
Value returned bygetMethod()if the request method isCONNECT.- See Also:
- Constant Field Values
-
OPTIONS
public static final int OPTIONS
Value returned bygetMethod()if the request method isOPTIONS.- See Also:
- Constant Field Values
-
TRACE
public static final int TRACE
Value returned bygetMethod()if the request method isTRACE.- See Also:
- Constant Field Values
-
PATCH
public static final int PATCH
Value returned bygetMethod()if the request method isPATCH.- See Also:
- Constant Field Values
-
BEFORE_ALL
protected static final int BEFORE_ALL
before all filter code.- See Also:
- Constant Field Values
-
BEFORE
protected static final int BEFORE
before filter code.- See Also:
- Constant Field Values
-
AFTER
protected static final int AFTER
after filter code.- See Also:
- Constant Field Values
-
AFTER_ALL
protected static final int AFTER_ALL
after all filter code.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HttpRequest
protected HttpRequest(java.io.InputStream inputStream, EncodingRegistry encodingRegistry) throws java.io.IOExceptionConstructs a new instance of HTTPRequest.- Parameters:
inputStream- the input stream of the request.encodingRegistry- the register of available encoding and transfer coding handlers.- Throws:
java.io.IOException- if connection is lost during processing the request.java.lang.IllegalArgumentException- if parsing the request failed.
-
-
Method Detail
-
getURI
public java.lang.String getURI()
Returns the request URI.- Returns:
- the request URI string.
-
getQueryParams
public java.util.Map<java.lang.String,java.lang.String> getQueryParams()
Returns the Query parameters asMap.- Returns:
- a
Mapof (String,String) representing the HTTP query parameters.
-
getQueryParam
@Nullable public java.lang.String getQueryParam(java.lang.String name)
Returns the query parameter mapped to the given name.- Parameters:
name- of query parameter- Returns:
- the parameter mapped to name
-
getPathParam
@Nullable public java.lang.String getPathParam(java.lang.String param)
Returns the path parameter value mapped to the given name.- Parameters:
param- path parameter name- Returns:
- path parameter value if exist, null otherwise
-
getSplatParams
public java.util.List<java.lang.String> getSplatParams()
Returns the list of splat parameters.- Returns:
- a
Listof splat parameters.
-
addSplatParameters
protected void addSplatParameters(java.util.List<java.lang.String> splatParameters)
Sets the splat Parameters.- Parameters:
splatParameters- the splat parameters to set.
-
addPathParameters
protected void addPathParameters(java.util.Map<java.lang.String,java.lang.String> parameters)
Adds path parameters from a given list to the list of path path parameters of the request.- Parameters:
parameters- path parameters to be added to the request
-
getAttribute
@Nullable public java.lang.Object getAttribute(java.lang.String key)
Get request server-side attribute by key.- Parameters:
key- attribute key- Returns:
- value mapped to key
-
setAttribute
public void setAttribute(java.lang.String key, java.lang.Object value)Set a request server-side attribute.- Parameters:
key- attribute keyvalue- attribute value
-
getVersion
public java.lang.String getVersion()
Returns the HTTP version request.- Returns:
- the HTTP version request string.
-
getHeaders
public java.util.Map<java.lang.String,java.lang.String> getHeaders()
Returns all HTTP header fields of the request.- Returns:
- a
Mapof (String,String) representing the HTTP header fields (may be empty).
-
getHeader
@Nullable public java.lang.String getHeader(@Nullable java.lang.String name)Returns the header field value associated to the given header fieldname.- Parameters:
name- the header field name.- Returns:
- the requested header field value,
nullif the header field is not found ornameis null.
-
getCookies
public java.util.Map<java.lang.String,java.lang.String> getCookies()
Returns the cookies of the request.Cookies are lazily parsed.
- Returns:
- a
Mapof (String,String) representing the HTTP cookies (may be empty)
-
getCookie
@Nullable public java.lang.String getCookie(@Nullable java.lang.String name)Return the cookie of the request with given name.Cookies are lazily parsed.
- Parameters:
name- the name of the cookie.- Returns:
- the cookie, or
nullifnameisnull.
-
parseBody
public <T> T parseBody(BodyParser<T> bodyParser) throws java.io.IOException
Request the body to be parsed.- Type Parameters:
T- the type of body.- Parameters:
bodyParser- the parser.- Returns:
- the parsed body.
- Throws:
java.io.IOException- if anIOExceptionoccurs during parsing.
-
getRequestBody
public java.io.InputStream getRequestBody()
useparseBody(BodyParser)for more option on request body provided parsers.- Returns:
- request request body as an input stream.
-
-