|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.xlightweb.Part
org.xlightweb.HttpRequest
public class HttpRequest
http request
Field Summary |
---|
Fields inherited from interface org.xlightweb.IHttpMessage |
---|
CONNECT_METHOD, DEFAULT_ENCODING, DEFAULT_ENCODING_KEY, DELETE_METHOD, GET_METHOD, HEAD_METHOD, OPTIONS_METHOD, POST_METHOD, PUT_METHOD, TRACE_METHOD |
Constructor Summary | |
---|---|
HttpRequest(IHttpRequestHeader requestHeader)
constructor |
|
HttpRequest(IHttpRequestHeader requestHeader,
byte[] bodyData)
constructor |
|
HttpRequest(IHttpRequestHeader requestHeader,
ByteBuffer[] bodyData)
constructor |
|
HttpRequest(IHttpRequestHeader requestHeader,
ByteBuffer[] bodyData,
boolean compress)
constructor |
|
HttpRequest(IHttpRequestHeader requestHeader,
InputStream is)
constructor. |
|
HttpRequest(IHttpRequestHeader requestHeader,
List<ByteBuffer> bodyData)
constructor |
|
HttpRequest(IHttpRequestHeader requestHeader,
List<ByteBuffer> bodyData,
boolean compress)
constructor |
|
HttpRequest(IHttpRequestHeader requestHeader,
NonBlockingBodyDataSource bodyDataSource)
constructor |
|
HttpRequest(IHttpRequestHeader requestHeader,
String body)
constructor |
|
HttpRequest(IHttpRequestHeader requestHeader,
String body,
boolean compress)
constructor |
|
HttpRequest(String method,
String url)
constructor |
|
HttpRequest(String method,
String url,
String contentType,
byte[] body)
constructor |
|
HttpRequest(String method,
String url,
String contentType,
byte[] body,
boolean compress)
constructor |
|
HttpRequest(String method,
String url,
String contentType,
ByteBuffer[] body)
constructor |
|
HttpRequest(String method,
String url,
String contentType,
ByteBuffer[] body,
boolean compress)
constructor |
|
HttpRequest(String method,
String url,
String contentType,
String body)
constructor |
|
HttpRequest(String method,
String url,
String contentType,
String body,
boolean compress)
constructor |
|
HttpRequest(String method,
String url,
String contentType,
String encoding,
String body)
constructor |
|
HttpRequest(String method,
String url,
String contentType,
String encoding,
String body,
boolean compress)
constructor |
Method Summary | |
---|---|
void |
addMatrixParameter(String parameterName,
String parameterValue)
adds a matrix parameter |
void |
addParameter(String parameterName,
String parameterValue)
adds a parameter |
List<ContentType> |
getAccept()
returns the list of the accepted content types, ordered by the quality factory |
Object |
getAttribute(String name)
Returns the value of the named attribute as an Object ,
or null if no attribute of the given name exists. |
Enumeration |
getAttributeNames()
Returns an Enumeration containing the
names of the attributes available to this message. |
Set<String> |
getAttributeNameSet()
Returns an Set containing the
names of the attributes available to this messaget. |
Boolean |
getBooleanParameter(String name)
Get an Boolean parameter, or null if not present. |
boolean |
getBooleanParameter(String name,
boolean defaultVal)
Get an boolean parameter, with a fallback value. |
int |
getContentLength()
Returns the length, in bytes, of the message body and made available by the input stream, or -1 if the length is not known. |
String |
getContextPath()
Returns the portion of the request URI that indicates the context of the request. |
Double |
getDoubleParameter(String name)
Get an Double parameter, or null if not present. |
double |
getDoubleParameter(String name,
double defaultVal)
Get an double parameter, with a fallback value. |
Float |
getFloatParameter(String name)
Get an Float parameter, or null if not present. |
float |
getFloatParameter(String name,
float defaultVal)
Get an float parameter, with a fallback value. |
String |
getHost()
returns the Host header parameter or null if the header is not set |
Integer |
getIntParameter(String name)
Get an Integer parameter, or null if not present. |
int |
getIntParameter(String name,
int defaultVal)
Get an int parameter, with a fallback value. |
Long |
getLongParameter(String name)
Get an Long parameter, or null if not present. |
long |
getLongParameter(String name,
long defaultVal)
Get an long parameter, with a fallback value. |
String |
getMatrixParameter(String name)
Returns the value of a request matrix parameter as a String, or null if the parameter does not exist. |
Set<String> |
getMatrixParameterNameSet()
returns the matrix parameter name set |
String[] |
getMatrixParameterValues(String name)
Returns an array of String objects containing all of the values the given request matrix parameter has, or null if the parameter does not exist. |
IHttpMessageHeader |
getMessageHeader()
returns the message header |
String |
getMethod()
Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT. |
String |
getParameter(String name)
Returns the value of a request parameter as a String, or null if the parameter does not exist. |
String |
getParameter(String name,
String defaultVal)
Get an String parameter, with a fallback value. |
Enumeration |
getParameterNames()
Returns an Enumeration of String objects containing the names of the parameters contained in this request. |
Set<String> |
getParameterNameSet()
returns the parameter name set |
String[] |
getParameterValues(String name)
Returns an array of String objects containing all of the values the given request parameter has, or null if the parameter does not exist. |
String |
getPathInfo()
Returns any extra path information associated with the URL. |
String |
getPathInfo(boolean removeSurroundingSlashs)
Returns any extra path information associated with the URL. |
String |
getProtocol()
Returns the name and version of the protocol the message uses in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1. |
String |
getProtocolVersion()
Returns the version of the protocol the message uses in the form majorVersion.minorVersion, for example, 1.1. |
String |
getQueryString()
Returns the query string that is contained in the request URL after the path. |
String |
getRemoteAddr()
Returns the Internet Protocol (IP) address of the client or last proxy that sent the message. |
String |
getRemoteHost()
Returns the fully qualified name of the client or the last proxy that sent the request. |
int |
getRemotePort()
Returns the Internet Protocol (IP) source port of the client or last proxy that sent the message. |
String |
getRequestHandlerPath()
returns the request handler path. |
IHttpRequestHeader |
getRequestHeader()
returns the request header |
String |
getRequestURI()
Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. |
URL |
getRequestUrl()
Reconstructs the URL the client used to make the request. |
boolean |
getRequiredBooleanParameter(String name)
Get an boolean parameter or throws an exception if parameter is not present |
double |
getRequiredDoubleParameter(String name)
Get an double parameter or throws an exception if parameter is not present |
float |
getRequiredFloatParameter(String name)
Get an float parameter or throws an exception if parameter is not present |
int |
getRequiredIntParameter(String name)
Get an int parameter or throws an exception if parameter is not present |
long |
getRequiredLongParameter(String name)
Get an long parameter or throws an exception if parameter is not present |
String |
getRequiredStringParameter(String name)
Get an string parameter or throws an exception if parameter is not present |
String |
getScheme()
Returns the name of the scheme used to make this request, for example, http or https. |
String |
getServerName()
Returns the host name of the server to which the request was sent. |
int |
getServerPort()
Returns the port number to which the request was sent. |
String |
getUserAgent()
returns the User-Agent header parameter or null if the header is not set |
boolean |
isSecure()
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS. |
void |
removeHopByHopHeaders()
removes all hop-by-hop headers without Transfer-Encoding if set to chunked |
void |
removeMatrixParameter(String parameterName)
removes a matrix parameter |
void |
removeParameter(String parameterName)
remove a parameter |
void |
setAttribute(String name,
Object o)
Stores an attribute in this header. |
void |
setContentLength(int length)
sets the content length in bytes |
void |
setContextPath(String contextPath)
sets the context path. |
void |
setHost(String host)
sets the Host header |
void |
setMatrixParameter(String parameterName,
String parameterValue)
sets a matrix parameter |
void |
setMethod(String method)
Sets the name of the HTTP method |
void |
setParameter(String parameterName,
String parameterValue)
sets a parameter |
void |
setRequestHandlerPath(String requestHandlerPath)
sets the request handler path |
void |
setRequestURI(String requestUri)
set the request uri part of this request's URL from the protocol name up to the query string in the first line of the HTTP request. |
void |
setRequestUrl(URL url)
set the request url |
void |
setUserAgent(String userAgent)
sets the User-Agent header |
Methods inherited from class org.xlightweb.Part |
---|
addHeader, addHeaderLine, addHeaderlines, containsHeader, getBlockingBody, getBody, getCharacterEncoding, getContentType, getDisposition, getDispositionParam, getDispositionType, getHeader, getHeaderList, getHeaderNames, getHeaderNameSet, getHeaders, getNonBlockingBody, getPartHeader, getTransferEncoding, hasBody, removeHeader, setContentType, setHeader, setTransferEncoding, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.xlightweb.IHttpMessage |
---|
getAttribute, getAttributeNames, getAttributeNameSet, getCharacterEncoding, getContentLength, getContentType, getMessageHeader, getTransferEncoding, removeHopByHopHeaders, setAttribute, setContentLength, setContentType, setTransferEncoding |
Methods inherited from interface org.xlightweb.IPart |
---|
getBlockingBody, getBody, getNonBlockingBody, getPartHeader, hasBody |
Methods inherited from interface org.xlightweb.IHeader |
---|
addHeader, addHeaderLine, addHeaderlines, containsHeader, getDisposition, getDispositionParam, getDispositionType, getHeader, getHeaderList, getHeaderNames, getHeaderNameSet, getHeaders, removeHeader, setHeader |
Constructor Detail |
---|
public HttpRequest(IHttpRequestHeader requestHeader)
requestHeader
- the request headerpublic HttpRequest(IHttpRequestHeader requestHeader, NonBlockingBodyDataSource bodyDataSource) throws IOException
requestHeader
- the request headerbodyDataSource
- the body data source
IOException
- if an exception occurspublic HttpRequest(IHttpRequestHeader requestHeader, ByteBuffer[] bodyData, boolean compress) throws IOException
requestHeader
- the request headerbodyData
- the body datacompress
- true, if the body should be compressed
IOException
- if an exception occurspublic HttpRequest(IHttpRequestHeader requestHeader, InputStream is) throws IOException
requestHeader
- the request headeris
- the body data
IOException
- if an exception occurspublic HttpRequest(String method, String url, String contentType, ByteBuffer[] body, boolean compress) throws IOException
method
- the method (GET, POST, ...)url
- the urlcontentType
- the content typebody
- the bodycompress
- true, if the body should be compressed
IOException
- if an exception occurspublic HttpRequest(String method, String url, String contentType, byte[] body, boolean compress) throws IOException
method
- the method (GET, POST, ...)url
- the urlcontentType
- the content typebody
- the bodycompress
- true, if the body should be compressed
IOException
- if an exception occurspublic HttpRequest(String method, String url, String contentType, String encoding, String body, boolean compress) throws IOException
method
- the method (GET, POST, ...)url
- the urlcontentType
- the content typeencoding
- the encodingbody
- the bodycompress
- true, if the body should be compressed
IOException
- if an exception occurspublic HttpRequest(String method, String url, String contentType, String body, boolean compress) throws IOException
method
- the method (GET, POST, ...)url
- the urlcontentType
- the content typebody
- the bodycompress
- true, if the body should be compressed
IOException
- if an exception occurspublic HttpRequest(IHttpRequestHeader requestHeader, String body, boolean compress) throws IOException
requestHeader
- the request headerbody
- the bodycompress
- true, if the body should be compressed
IOException
- if an exception occurspublic HttpRequest(IHttpRequestHeader requestHeader, String body) throws IOException
requestHeader
- the request headerbody
- the body
IOException
- if an exception occurspublic HttpRequest(IHttpRequestHeader requestHeader, ByteBuffer[] bodyData) throws IOException
requestHeader
- the request headerbodyData
- the body data
IOException
- if an exception occurspublic HttpRequest(IHttpRequestHeader requestHeader, byte[] bodyData) throws IOException
requestHeader
- the request headerbodyData
- the body data
IOException
- if an exception occurspublic HttpRequest(IHttpRequestHeader requestHeader, List<ByteBuffer> bodyData) throws IOException
requestHeader
- the request headerbodyData
- the body data
IOException
- if an exception occurspublic HttpRequest(IHttpRequestHeader requestHeader, List<ByteBuffer> bodyData, boolean compress) throws IOException
requestHeader
- the request headerbodyData
- the body datacompress
- true, if the data should be compressed
IOException
- if an exception occurspublic HttpRequest(String method, String url, String contentType, String body) throws IOException
method
- the method (GET, POST, ...)url
- the urlcontentType
- the content typebody
- the body
IOException
- if an exception occurspublic HttpRequest(String method, String url, String contentType, String encoding, String body) throws IOException
method
- the method (GET, POST, ...)url
- the urlcontentType
- the content typeencoding
- the encodingbody
- the body
IOException
- if an exception occurspublic HttpRequest(String method, String url, String contentType, byte[] body) throws IOException
method
- the method (GET, POST, ...)url
- the urlcontentType
- the content typebody
- the body
IOException
- if an exception occurspublic HttpRequest(String method, String url, String contentType, ByteBuffer[] body) throws IOException
method
- the method (GET, POST, ...)url
- the urlcontentType
- the content typebody
- the body
IOException
- if an exception occurspublic HttpRequest(String method, String url)
method
- the method (GET, POST, ...)url
- the urlMethod Detail |
---|
public IHttpRequestHeader getRequestHeader()
getRequestHeader
in interface IHttpRequest
public String getRequestHandlerPath()
class MyHandler implements IHttpRequestHandler { public void onRequest(IHttpExchange exchange) throws IOException,BadMessageException { IHttpRequest req = exchange.getRequest(); StringBuilder sb = new StringBuilder(); sb.append("path=" + req.getRequestHandlerPath() + "\r\n"); sb.append("ctx=" + req.getContextPath() + "\r\n"); sb.append("uri=" + req.getRequestURI() + "\r\n"); exchange.send(new HttpResponse(200, "text/plain", sb.toString())); } } ... Context ctx = new Context("/ctx/subctx"); ctx.addHandler("/hdlPath/*", new MyHandler()); HttpServer server = new HttpServer(ctx); server.start(); HttpClient httpClient = new HttpClient(); IHttpResponse response = httpClient.call(new GetRequest("http://localhost:" + server.getLocalPort() + "/ctx/subctx/hdlPath/test?param=value")); System.out.println(response.getBlockingBody().readString()); // prints out: // >path=/hdlPath // >ctx=/ctx/subctx // >uri=/ctx/subctx/hdlPath/test ...
getRequestHandlerPath
in interface IHttpRequest
public void setRequestHandlerPath(String requestHandlerPath)
setRequestHandlerPath
in interface IHttpRequest
requestHandlerPath
- the request handler pathpublic String getContextPath()
getContextPath
in interface IHttpRequest
IHttpRequest.getRequestHandlerPath()
public void setContextPath(String contextPath)
setContextPath
in interface IHttpRequest
contextPath
- the context pathpublic void setMethod(String method)
setMethod
in interface IHttpRequest
method
- a String specifying the name of the methodpublic String getMethod()
getMethod
in interface IHttpRequest
public List<ContentType> getAccept()
getAccept
in interface IHttpRequest
public String getScheme()
getScheme
in interface IHttpRequest
public void setHost(String host)
setHost
in interface IHttpRequest
host
- the Host headerpublic String getServerName()
getServerName
in interface IHttpRequest
public int getServerPort()
getServerPort
in interface IHttpRequest
public String getProtocol()
getProtocol
in interface IHttpMessage
public String getProtocolVersion()
getProtocolVersion
in interface IHttpMessage
public URL getRequestUrl()
getRequestUrl
in interface IHttpRequest
public void setRequestUrl(URL url)
setRequestUrl
in interface IHttpRequest
url
- the request urlpublic String getRemoteHost()
getRemoteHost
in interface IHttpRequest
public String getRemoteAddr()
getRemoteAddr
in interface IHttpRequest
public int getRemotePort()
getRemotePort
in interface IHttpRequest
public String getRequestURI()
getRequestURI
in interface IHttpRequest
public void setRequestURI(String requestUri)
IHttpRequest
setRequestURI
in interface IHttpRequest
requestUri
- the request uripublic String getPathInfo()
getPathInfo
in interface IHttpRequest
null
if the URL does not have any extra path informationpublic String getPathInfo(boolean removeSurroundingSlashs)
getPathInfo
in interface IHttpRequest
removeSurroundingSlashs
- true, if surrounding slashs wil lbe removed
null
if the URL does not have any extra path informationpublic String getHost()
null
if the header is not set
getHost
in interface IHttpRequest
null
if the header is not setpublic String getUserAgent()
null
if the header is not set
getUserAgent
in interface IHttpRequest
null
if the header is not setpublic void setUserAgent(String userAgent)
setUserAgent
in interface IHttpRequest
userAgent
- the User-Agent headerpublic String getQueryString()
null
if the URL does not have a query string.
getQueryString
in interface IHttpRequest
null
if the URL contains no query string.public boolean isSecure()
isSecure
in interface IHttpRequest
public String getMatrixParameter(String name)
getMatrixParameter
in interface IHttpRequest
name
- a String specifying the name of the matrix parameter
public Set<String> getMatrixParameterNameSet()
getMatrixParameterNameSet
in interface IHttpRequest
public String[] getMatrixParameterValues(String name)
getMatrixParameterValues
in interface IHttpRequest
name
- a String specifying the name of the matrix parameter
public void setMatrixParameter(String parameterName, String parameterValue)
setMatrixParameter
in interface IHttpRequest
parameterName
- the parameter nameparameterValue
- the parameter valuepublic void addMatrixParameter(String parameterName, String parameterValue)
addMatrixParameter
in interface IHttpRequest
parameterName
- the parameter nameparameterValue
- the parameter valuepublic void removeMatrixParameter(String parameterName)
removeMatrixParameter
in interface IHttpRequest
parameterName
- the parameter namepublic Enumeration getParameterNames()
getParameterNames
in interface IHttpRequest
public Set<String> getParameterNameSet()
getParameterNameSet
in interface IHttpRequest
public String getParameter(String name)
getParameter
in interface IHttpRequest
name
- a String specifying the name of the parameter
public String getParameter(String name, String defaultVal)
getParameter
in interface IHttpRequest
name
- the name of the parameterdefaultVal
- the default value to use as fallback
public String[] getParameterValues(String name)
getParameterValues
in interface IHttpRequest
name
- a String specifying the name of the parameter
public String getRequiredStringParameter(String name) throws BadMessageException
getRequiredStringParameter
in interface IHttpRequest
name
- the parameter name
BadMessageException
- if the parameter is not presentpublic Integer getIntParameter(String name) throws BadMessageException
getIntParameter
in interface IHttpRequest
name
- the name of the parameter
null
BadMessageException
- if the parameter value is not a numberpublic int getRequiredIntParameter(String name) throws BadMessageException
getRequiredIntParameter
in interface IHttpRequest
name
- the parameter name
BadMessageException
- if the parameter is not present or the parameter is not a numberpublic int getIntParameter(String name, int defaultVal)
getIntParameter
in interface IHttpRequest
name
- the name of the parameterdefaultVal
- the default value to use as fallback
null
public Long getLongParameter(String name) throws BadMessageException
getLongParameter
in interface IHttpRequest
name
- the name of the parameter
null
BadMessageException
- if the parameter value is not a numberpublic long getRequiredLongParameter(String name) throws BadMessageException
getRequiredLongParameter
in interface IHttpRequest
name
- the parameter name
BadMessageException
- if the parameter is not present or the parameter is not a numberpublic long getLongParameter(String name, long defaultVal)
getLongParameter
in interface IHttpRequest
name
- the name of the parameterdefaultVal
- the default value to use as fallback
public Double getDoubleParameter(String name) throws BadMessageException
getDoubleParameter
in interface IHttpRequest
name
- the name of the parameter
null
BadMessageException
- if the parameter is not a numberpublic double getRequiredDoubleParameter(String name) throws BadMessageException
getRequiredDoubleParameter
in interface IHttpRequest
name
- the parameter name
BadMessageException
- if the parameter is not present or the parameter value is not a numberpublic double getDoubleParameter(String name, double defaultVal)
getDoubleParameter
in interface IHttpRequest
name
- the name of the parameterdefaultVal
- the default value to use as fallback
public Float getFloatParameter(String name) throws BadMessageException
getFloatParameter
in interface IHttpRequest
name
- the name of the parameter
null
BadMessageException
- if the parameter value is not a numberpublic float getRequiredFloatParameter(String name) throws BadMessageException
getRequiredFloatParameter
in interface IHttpRequest
name
- the parameter name
BadMessageException
- if the parameter is not present or the parameter value is not a numberpublic float getFloatParameter(String name, float defaultVal)
getFloatParameter
in interface IHttpRequest
name
- the name of the parameterdefaultVal
- the default value to use as fallback
public Boolean getBooleanParameter(String name)
getBooleanParameter
in interface IHttpRequest
name
- the name of the parameter
null
public boolean getRequiredBooleanParameter(String name) throws BadMessageException
getRequiredBooleanParameter
in interface IHttpRequest
name
- the parameter name
BadMessageException
- if the parameter is not presentpublic boolean getBooleanParameter(String name, boolean defaultVal)
getBooleanParameter
in interface IHttpRequest
name
- the name of the parameterdefaultVal
- the default value to use as fallback
public void setParameter(String parameterName, String parameterValue)
setParameter
in interface IHttpRequest
parameterName
- the parameter nameparameterValue
- the parameter valuepublic void removeParameter(String parameterName)
removeParameter
in interface IHttpRequest
parameterName
- the parameter namepublic void addParameter(String parameterName, String parameterValue)
addParameter
in interface IHttpRequest
parameterName
- the parameter nameparameterValue
- the parameter valuepublic final IHttpMessageHeader getMessageHeader()
getMessageHeader
in interface IHttpMessage
public final void setAttribute(String name, Object o)
setAttribute
in interface IHttpMessage
name
- a String
specifying
the name of the attributeo
- the Object
to be storedpublic final Object getAttribute(String name)
Object
,
or null
if no attribute of the given name exists.
getAttribute
in interface IHttpMessage
name
- a String
specifying the name of the attribute
Object
containing the value of the attribute,
or null
if the attribute does not existpublic final Enumeration getAttributeNames()
Enumeration
containing the
names of the attributes available to this message.
This method returns an empty Enumeration
if the message has no attributes available to it.
getAttributeNames
in interface IHttpMessage
Enumeration
of strings containing the names
of the message's attributespublic final Set<String> getAttributeNameSet()
Set
containing the
names of the attributes available to this messaget.
This method returns an empty Set
if the request has no attributes available to it.
getAttributeNameSet
in interface IHttpMessage
Set
of strings
containing the names of the message's attributespublic final int getContentLength()
getContentLength
in interface IHttpMessage
public final void setContentLength(int length)
setContentLength
in interface IHttpMessage
length
- the content length in bytespublic final void removeHopByHopHeaders()
removeHopByHopHeaders
in interface IHttpMessage
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |