|
|||||||||
| 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, 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, getHeader, getHeaderList, getHeaderNames, getHeaderNameSet, getHeaders, removeHeader, setHeader |
| Constructor Detail |
|---|
public HttpRequest(IHttpRequestHeader requestHeader)
requestHeader - the request header
public HttpRequest(IHttpRequestHeader requestHeader,
NonBlockingBodyDataSource bodyDataSource)
throws IOException
requestHeader - the request headerbodyDataSource - the body data source
IOException - if an exception occurs
public 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 occurs
public HttpRequest(IHttpRequestHeader requestHeader,
InputStream is)
throws IOException
requestHeader - the request headeris - the body data
IOException - if an exception occurs
public 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 occurs
public 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 occurs
public 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 occurs
public 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 occurs
public 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 occurs
public HttpRequest(IHttpRequestHeader requestHeader,
String body)
throws IOException
requestHeader - the request headerbody - the body
IOException - if an exception occurs
public HttpRequest(IHttpRequestHeader requestHeader,
ByteBuffer[] bodyData)
throws IOException
requestHeader - the request headerbodyData - the body data
IOException - if an exception occurs
public HttpRequest(IHttpRequestHeader requestHeader,
byte[] bodyData)
throws IOException
requestHeader - the request headerbodyData - the body data
IOException - if an exception occurs
public HttpRequest(IHttpRequestHeader requestHeader,
List<ByteBuffer> bodyData)
throws IOException
requestHeader - the request headerbodyData - the body data
IOException - if an exception occurs
public 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 occurs
public 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 occurs
public 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 occurs
public 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 occurs
public 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 occurs
public HttpRequest(String method,
String url)
method - the method (GET, POST, ...)url - the url| Method Detail |
|---|
public IHttpRequestHeader getRequestHeader()
getRequestHeader in interface IHttpRequestpublic 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 IHttpRequestpublic void setRequestHandlerPath(String requestHandlerPath)
setRequestHandlerPath in interface IHttpRequestrequestHandlerPath - the request handler pathpublic String getContextPath()
getContextPath in interface IHttpRequestIHttpRequest.getRequestHandlerPath()public void setContextPath(String contextPath)
setContextPath in interface IHttpRequestcontextPath - the context pathpublic void setMethod(String method)
setMethod in interface IHttpRequestmethod - a String specifying the name of the methodpublic String getMethod()
getMethod in interface IHttpRequestpublic List<ContentType> getAccept()
getAccept in interface IHttpRequestpublic String getScheme()
getScheme in interface IHttpRequestpublic void setHost(String host)
setHost in interface IHttpRequesthost - the Host headerpublic String getServerName()
getServerName in interface IHttpRequestpublic int getServerPort()
getServerPort in interface IHttpRequestpublic String getProtocol()
getProtocol in interface IHttpMessagepublic String getProtocolVersion()
getProtocolVersion in interface IHttpMessagepublic URL getRequestUrl()
getRequestUrl in interface IHttpRequestpublic void setRequestUrl(URL url)
setRequestUrl in interface IHttpRequesturl - the request urlpublic String getRemoteHost()
getRemoteHost in interface IHttpRequestpublic String getRemoteAddr()
getRemoteAddr in interface IHttpRequestpublic int getRemotePort()
getRemotePort in interface IHttpRequestpublic String getRequestURI()
getRequestURI in interface IHttpRequestpublic void setRequestURI(String requestUri)
IHttpRequest
setRequestURI in interface IHttpRequestrequestUri - the request uripublic String getPathInfo()
getPathInfo in interface IHttpRequestnull if the URL does not have any extra path informationpublic String getPathInfo(boolean removeSurroundingSlashs)
getPathInfo in interface IHttpRequestremoveSurroundingSlashs - 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 IHttpRequestnull if the header is not setpublic String getUserAgent()
null if the header is not set
getUserAgent in interface IHttpRequestnull if the header is not setpublic void setUserAgent(String userAgent)
setUserAgent in interface IHttpRequestuserAgent - the User-Agent headerpublic String getQueryString()
null
if the URL does not have a query string.
getQueryString in interface IHttpRequestnull if the URL contains no query string.public boolean isSecure()
isSecure in interface IHttpRequestpublic String getMatrixParameter(String name)
getMatrixParameter in interface IHttpRequestname - a String specifying the name of the matrix parameter
public Set<String> getMatrixParameterNameSet()
getMatrixParameterNameSet in interface IHttpRequestpublic String[] getMatrixParameterValues(String name)
getMatrixParameterValues in interface IHttpRequestname - a String specifying the name of the matrix parameter
public void setMatrixParameter(String parameterName,
String parameterValue)
setMatrixParameter in interface IHttpRequestparameterName - the parameter nameparameterValue - the parameter value
public void addMatrixParameter(String parameterName,
String parameterValue)
addMatrixParameter in interface IHttpRequestparameterName - the parameter nameparameterValue - the parameter valuepublic void removeMatrixParameter(String parameterName)
removeMatrixParameter in interface IHttpRequestparameterName - the parameter namepublic Enumeration getParameterNames()
getParameterNames in interface IHttpRequestpublic Set<String> getParameterNameSet()
getParameterNameSet in interface IHttpRequestpublic String getParameter(String name)
getParameter in interface IHttpRequestname - a String specifying the name of the parameter
public String getParameter(String name,
String defaultVal)
getParameter in interface IHttpRequestname - the name of the parameterdefaultVal - the default value to use as fallback
public String[] getParameterValues(String name)
getParameterValues in interface IHttpRequestname - a String specifying the name of the parameter
public String getRequiredStringParameter(String name)
throws BadMessageException
getRequiredStringParameter in interface IHttpRequestname - the parameter name
BadMessageException - if the parameter is not present
public Integer getIntParameter(String name)
throws BadMessageException
getIntParameter in interface IHttpRequestname - the name of the parameter
null
BadMessageException - if the parameter value is not a number
public int getRequiredIntParameter(String name)
throws BadMessageException
getRequiredIntParameter in interface IHttpRequestname - the parameter name
BadMessageException - if the parameter is not present or the parameter is not a number
public int getIntParameter(String name,
int defaultVal)
getIntParameter in interface IHttpRequestname - the name of the parameterdefaultVal - the default value to use as fallback
null
public Long getLongParameter(String name)
throws BadMessageException
getLongParameter in interface IHttpRequestname - the name of the parameter
null
BadMessageException - if the parameter value is not a number
public long getRequiredLongParameter(String name)
throws BadMessageException
getRequiredLongParameter in interface IHttpRequestname - the parameter name
BadMessageException - if the parameter is not present or the parameter is not a number
public long getLongParameter(String name,
long defaultVal)
getLongParameter in interface IHttpRequestname - the name of the parameterdefaultVal - the default value to use as fallback
public Double getDoubleParameter(String name)
throws BadMessageException
getDoubleParameter in interface IHttpRequestname - the name of the parameter
null
BadMessageException - if the parameter is not a number
public double getRequiredDoubleParameter(String name)
throws BadMessageException
getRequiredDoubleParameter in interface IHttpRequestname - the parameter name
BadMessageException - if the parameter is not present or the parameter value is not a number
public double getDoubleParameter(String name,
double defaultVal)
getDoubleParameter in interface IHttpRequestname - the name of the parameterdefaultVal - the default value to use as fallback
public Float getFloatParameter(String name)
throws BadMessageException
getFloatParameter in interface IHttpRequestname - the name of the parameter
null
BadMessageException - if the parameter value is not a number
public float getRequiredFloatParameter(String name)
throws BadMessageException
getRequiredFloatParameter in interface IHttpRequestname - the parameter name
BadMessageException - if the parameter is not present or the parameter value is not a number
public float getFloatParameter(String name,
float defaultVal)
getFloatParameter in interface IHttpRequestname - the name of the parameterdefaultVal - the default value to use as fallback
public Boolean getBooleanParameter(String name)
getBooleanParameter in interface IHttpRequestname - the name of the parameter
null
public boolean getRequiredBooleanParameter(String name)
throws BadMessageException
getRequiredBooleanParameter in interface IHttpRequestname - the parameter name
BadMessageException - if the parameter is not present
public boolean getBooleanParameter(String name,
boolean defaultVal)
getBooleanParameter in interface IHttpRequestname - the name of the parameterdefaultVal - the default value to use as fallback
public void setParameter(String parameterName,
String parameterValue)
setParameter in interface IHttpRequestparameterName - the parameter nameparameterValue - the parameter valuepublic void removeParameter(String parameterName)
removeParameter in interface IHttpRequestparameterName - the parameter name
public void addParameter(String parameterName,
String parameterValue)
addParameter in interface IHttpRequestparameterName - the parameter nameparameterValue - the parameter valuepublic final IHttpMessageHeader getMessageHeader()
getMessageHeader in interface IHttpMessage
public final void setAttribute(String name,
Object o)
setAttribute in interface IHttpMessagename - 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 IHttpMessagename - 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 IHttpMessageEnumeration 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 IHttpMessageSet of strings
containing the names of the message's attributespublic final int getContentLength()
getContentLength in interface IHttpMessagepublic final void setContentLength(int length)
setContentLength in interface IHttpMessagelength - 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 | ||||||||