|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.xlightweb.HttpRequestHeaderWrapper
org.xlightweb.HttpRequestWrapper
public class HttpRequestWrapper
Provides a convenient implementation of the HttpRequest interface that can be subclassed by developers wishing to adapt the request. This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped request object.
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 |
Fields inherited from interface org.xlightweb.IHttpMessageHeader |
---|
DEFAULT_ENCODING |
Constructor Summary | |
---|---|
HttpRequestWrapper(IHttpRequest request)
constructor |
Method Summary | |
---|---|
void |
addHeader(String headername,
String headervalue)
Adds a header with the given name and value. |
void |
addHeaderLine(String line)
adds a raw header line |
void |
addHeaderlines(String... lines)
adds raw header lines |
boolean |
containsHeader(String headername)
Returns a boolean indicating whether the named header has already been set. |
BlockingBodyDataSource |
getBlockingBody()
|
BodyDataSource |
getBody()
returns the blocking body |
String |
getCharacterEncoding()
Returns the name of the character encoding used in the body of this message. |
String |
getContentType()
Returns the MIME type of the body of the messag, or null if the type is not known. |
String |
getContextPath()
Returns the portion of the request URI that indicates the context of the request. |
String |
getDisposition()
returns the content disposition header of the part, or null if the type is not known. |
String |
getDispositionParam(String name)
returns the content disposition param value or null if not setsee also rfc2183 |
String |
getDispositionType()
returns the content disposition type or null if not setsee also rfc2183 |
String |
getHeader(String headername)
Returns the value of the specified header as a String . |
List<String> |
getHeaderList(String headername)
Returns all the values of the specified header as an List of String objects. |
Enumeration |
getHeaderNames()
Returns an enumeration of all the header names. |
Set<String> |
getHeaderNameSet()
Returns an set of all the header names. |
Enumeration |
getHeaders(String headername)
Returns all the values of the specified header as an Enumeration of String objects. |
String |
getHost()
returns the Host header parameter or null if the header is not set |
IHttpMessageHeader |
getMessageHeader()
returns the message header |
NonBlockingBodyDataSource |
getNonBlockingBody()
returns the non-blocking body |
IHeader |
getPartHeader()
returns the part header |
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 |
getRequestHandlerPath()
returns the request handler path. |
IHttpRequestHeader |
getRequestHeader()
returns the request header |
String |
getUserAgent()
returns the User-Agent header parameter or null if the header is not set |
protected IHeader |
getWrappedHeader()
|
boolean |
hasBody()
returns true if the part has a body |
void |
removeHeader(String headername)
removes a header with the given name |
void |
removeParameter(String parameterName)
remove a parameter |
void |
setContextPath(String contextPath)
sets the context path. |
void |
setHeader(String headername,
String headervalue)
Sets a header with the given name and value. |
void |
setHost(String host)
sets the Host header (e.g. www.gmx.com or www.gmx.com:9900). |
void |
setParameter(String parameterName,
String parameterValue)
sets a parameter |
void |
setRequestHandlerPath(String requestHandlerPath)
sets the request handler path |
void |
setUserAgent(String userAgent)
sets the User-Agent header |
String |
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, getProtocol, getProtocolVersion, getTransferEncoding, removeHopByHopHeaders, setAttribute, setContentLength, setContentType, setTransferEncoding |
Methods inherited from interface org.xlightweb.IHeader |
---|
addHeader, addHeaderLine, addHeaderlines, containsHeader, getDisposition, getDispositionParam, getDispositionType, getHeader, getHeaderList, getHeaderNames, getHeaderNameSet, getHeaders, removeHeader, setHeader |
Constructor Detail |
---|
public HttpRequestWrapper(IHttpRequest request)
request
- the request to wrapMethod Detail |
---|
public String getContextPath()
getContextPath
in interface IHttpRequest
IHttpRequest.getRequestHandlerPath()
public 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 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 IHttpRequestHeader getRequestHeader()
getRequestHeader
in interface IHttpRequest
public String getHost()
null
if the header is not set
getHost
in interface IHttpRequest
getHost
in interface IHttpRequestHeader
getHost
in class HttpRequestHeaderWrapper
null
if the header is not setpublic String getUserAgent()
null
if the header is not set
getUserAgent
in interface IHttpRequest
getUserAgent
in interface IHttpRequestHeader
getUserAgent
in class HttpRequestHeaderWrapper
null
if the header is not setpublic void setHost(String host)
setHost
in interface IHttpRequest
setHost
in interface IHttpRequestHeader
setHost
in class HttpRequestHeaderWrapper
host
- the Host headerpublic void setUserAgent(String userAgent)
setUserAgent
in interface IHttpRequest
setUserAgent
in interface IHttpRequestHeader
setUserAgent
in class HttpRequestHeaderWrapper
userAgent
- the User-Agent headerpublic void setContextPath(String contextPath)
setContextPath
in interface IHttpRequest
contextPath
- the context pathpublic void setParameter(String parameterName, String parameterValue)
setParameter
in interface IHttpRequest
setParameter
in interface IHttpRequestHeader
setParameter
in class HttpRequestHeaderWrapper
parameterName
- the parameter nameparameterValue
- the parameter valuepublic void removeParameter(String parameterName)
removeParameter
in interface IHttpRequest
removeParameter
in interface IHttpRequestHeader
removeParameter
in class HttpRequestHeaderWrapper
parameterName
- the parameter namepublic void setRequestHandlerPath(String requestHandlerPath)
setRequestHandlerPath
in interface IHttpRequest
requestHandlerPath
- the request handler pathpublic BlockingBodyDataSource getBlockingBody() throws IOException
getBlockingBody
in interface IPart
IOException
public BodyDataSource getBody() throws IOException
IPart
getBody
in interface IPart
null
if part is bodyless
IOException
public IHttpMessageHeader getMessageHeader()
getMessageHeader
in interface IHttpMessage
public IHeader getPartHeader()
getPartHeader
in interface IPart
public NonBlockingBodyDataSource getNonBlockingBody() throws IOException
getNonBlockingBody
in interface IPart
null
if parte is bodyless
IOException
public boolean hasBody()
hasBody
in interface IPart
public String toString()
toString
in class HttpRequestHeaderWrapper
protected IHeader getWrappedHeader()
public void addHeader(String headername, String headervalue)
addHeader
in interface IHeader
headername
- the name of the headerheadervalue
- the additional header value. If it contains octet string, it should be encoded
according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)public void addHeaderLine(String line)
addHeaderLine
in interface IHeader
line
- the headerlinepublic void addHeaderlines(String... lines)
addHeaderlines
in interface IHeader
lines
- the headerlinespublic boolean containsHeader(String headername)
containsHeader
in interface IHeader
true
if the named header has already been set; false
otherwisepublic String getCharacterEncoding()
getCharacterEncoding
in interface IHeader
String
containing the name of the character encodingpublic String getContentType()
null
if the type is not known.
getContentType
in interface IHeader
String
containing the name of the MIME type of
the message, or null if the type is not knownpublic String getDisposition()
null
if the type is not known.
getDisposition
in interface IHeader
String
containing the name of the content disposition of
the part, or null if the type is not knownpublic String getDispositionType()
null
if not set
getDispositionType
in interface IHeader
null
if not setpublic String getDispositionParam(String name)
null
if not set
getDispositionParam
in interface IHeader
name
- the parameter name
null
if not setpublic String getHeader(String headername)
String
.
If the part did not include a header of the specified name,
this method returns null
.
If there are multiple headers with the same name, this method
returns the first head in the part.
getHeader
in interface IHeader
headername
- a String
specifying the header name
String
containing the value of the
requested header, or null
if the part
does not have a header of that namepublic List<String> getHeaderList(String headername)
List
of String
objects.
Some headers, such as Accept-Language
can be set
by part producer as several headers each with a different value rather than
sending the header as a comma separated list.
getHeaderList
in interface IHeader
headername
- a String
specifying the header name
List
containing the values of the requested header.
If the part does not have any headers of that name return an empty enumeration.public Set<String> getHeaderNameSet()
getHeaderNameSet
in interface IHeader
public Enumeration getHeaderNames()
getHeaderNames
in interface IHeader
public Enumeration getHeaders(String headername)
Enumeration
of String
objects.
Some headers, such as Accept-Language
can be set
by part producer as several headers each with a different value rather than
sending the header as a comma separated list.
getHeaders
in interface IHeader
headername
- a String
specifying the header name
Enumeration
containing the values of the requested header.
If the part does not have any headers of that name return an empty enumeration.public void removeHeader(String headername)
removeHeader
in interface IHeader
headername
- the name of the headerpublic void setHeader(String headername, String headervalue)
setHeader
in interface IHeader
headername
- the name of the headerheadervalue
- the header value If it contains octet string,
it should be encoded according to RFC 2047 (http://www.ietf.org/rfc/rfc2047.txt)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |