|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.xlightweb.HttpRequestHeaderWrapper
public class HttpRequestHeaderWrapper
Provides a convenient implementation of the HttpRequestHeader interface that can be subclassed by developers wishing to adapt the request header. This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped request header object.
Field Summary |
---|
Fields inherited from interface org.xlightweb.IHttpMessageHeader |
---|
DEFAULT_ENCODING |
Constructor Summary | |
---|---|
HttpRequestHeaderWrapper(IHttpRequestHeader requestHeader)
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 |
void |
addMatrixParameter(String parameterName,
String parameterValue)
adds a matrix parameter |
void |
addParameter(String parameterName,
String parameterValue)
adds a parameter |
boolean |
containsHeader(String headername)
Returns a boolean indicating whether the named header has already been set. |
IHttpRequestHeader |
copy()
creates a copy of this header |
void |
copyHeaderFrom(IHttpMessageHeader otherHeader,
String... upperExcludenames)
copy the headers |
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. |
String |
getCharacterEncoding()
Returns the name of the character encoding used in the body of this message. |
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 |
getContentType()
Returns the MIME type of the body of the messag, or null if the type is not known. |
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 |
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 |
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 |
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. |
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 |
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 request. |
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 request. |
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 |
getTransferEncoding()
returns the Transfer-Encoding header parameter or null if the header is not set |
String |
getUserAgent()
returns the User-Agent header parameter or null if the header is not set |
protected IHeader |
getWrappedHeader()
|
protected IHttpRequestHeader |
getWrappedRequestHeader()
|
boolean |
isSecure()
Returns a boolean indicating whether this request was made using a secure channel, such as HTTPS. |
void |
removeHeader(String headername)
removes a header with the given name |
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 |
setContentType(String type)
sets the MIME type of the body of the part |
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 |
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 |
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 |
setTransferEncoding(String transferEncoding)
sets the Transfer-Encoding parameter |
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.IHeader |
---|
addHeader, addHeaderLine, addHeaderlines, containsHeader, getCharacterEncoding, getContentType, getDisposition, getDispositionParam, getDispositionType, getHeader, getHeaderList, getHeaderNames, getHeaderNameSet, getHeaders, removeHeader, setHeader |
Constructor Detail |
---|
public HttpRequestHeaderWrapper(IHttpRequestHeader requestHeader)
request
- the request header to wrapMethod Detail |
---|
protected IHttpRequestHeader getWrappedRequestHeader()
public Boolean getBooleanParameter(String name)
getBooleanParameter
in interface IHttpRequestHeader
name
- the name of the parameter
null
public boolean getBooleanParameter(String name, boolean defaultVal)
getBooleanParameter
in interface IHttpRequestHeader
name
- the name of the parameterdefaultVal
- the default value to use as fallback
public Double getDoubleParameter(String name) throws BadMessageException
getDoubleParameter
in interface IHttpRequestHeader
name
- the name of the parameter
null
BadMessageException
- if the parameter is not a numberpublic double getDoubleParameter(String name, double defaultVal)
getDoubleParameter
in interface IHttpRequestHeader
name
- the name of the parameterdefaultVal
- the default value to use as fallback
public Float getFloatParameter(String name) throws BadMessageException
getFloatParameter
in interface IHttpRequestHeader
name
- the name of the parameter
null
BadMessageException
- if the parameter value is not a numberpublic float getFloatParameter(String name, float defaultVal)
getFloatParameter
in interface IHttpRequestHeader
name
- the name of the parameterdefaultVal
- the default value to use as fallback
public Integer getIntParameter(String name) throws BadMessageException
getIntParameter
in interface IHttpRequestHeader
name
- the name of the parameter
null
BadMessageException
- if the parameter value is not a numberpublic int getIntParameter(String name, int defaultVal)
getIntParameter
in interface IHttpRequestHeader
name
- the name of the parameterdefaultVal
- the default value to use as fallback
public Long getLongParameter(String name) throws BadMessageException
getLongParameter
in interface IHttpRequestHeader
name
- the name of the parameter
null
BadMessageException
- if the parameter value is not a numberpublic long getLongParameter(String name, long defaultVal)
getLongParameter
in interface IHttpRequestHeader
name
- the name of the parameterdefaultVal
- the default value to use as fallback
public String getMethod()
getMethod
in interface IHttpRequestHeader
public String getMatrixParameter(String name)
getMatrixParameter
in interface IHttpRequestHeader
name
- a String specifying the name of the matrix parameter
public Set<String> getMatrixParameterNameSet()
getMatrixParameterNameSet
in interface IHttpRequestHeader
public String[] getMatrixParameterValues(String name)
getMatrixParameterValues
in interface IHttpRequestHeader
name
- a String specifying the name of the matrix parameter
public void setMatrixParameter(String parameterName, String parameterValue)
setMatrixParameter
in interface IHttpRequestHeader
parameterName
- the parameter nameparameterValue
- the parameter valuepublic void addMatrixParameter(String parameterName, String parameterValue)
addMatrixParameter
in interface IHttpRequestHeader
parameterName
- the parameter nameparameterValue
- the parameter valuepublic void removeMatrixParameter(String parameterName)
removeMatrixParameter
in interface IHttpRequestHeader
parameterName
- the parameter namepublic void removeParameter(String parameterName)
removeParameter
in interface IHttpRequestHeader
parameterName
- the parameter namepublic String getParameter(String name)
getParameter
in interface IHttpRequestHeader
name
- a String specifying the name of the parameter
public String getParameter(String name, String defaultVal)
getParameter
in interface IHttpRequestHeader
name
- the name of the parameterdefaultVal
- the default value to use as fallback
public Set<String> getParameterNameSet()
getParameterNameSet
in interface IHttpRequestHeader
public Enumeration getParameterNames()
getParameterNames
in interface IHttpRequestHeader
public String[] getParameterValues(String name)
getParameterValues
in interface IHttpRequestHeader
name
- a String specifying the name of the parameter
public String getQueryString()
null
if the URL does not have a query string.
getQueryString
in interface IHttpRequestHeader
public String getRemoteAddr()
getRemoteAddr
in interface IHttpRequestHeader
public String getRemoteHost()
getRemoteHost
in interface IHttpRequestHeader
public int getRemotePort()
getRemotePort
in interface IHttpRequestHeader
public String getRequestURI()
getRequestURI
in interface IHttpRequestHeader
public void setRequestURI(String requestUri)
setRequestURI
in interface IHttpRequestHeader
requestUri
- the request uripublic URL getRequestUrl()
getRequestUrl
in interface IHttpRequestHeader
public boolean getRequiredBooleanParameter(String name) throws BadMessageException
getRequiredBooleanParameter
in interface IHttpRequestHeader
name
- the parameter name
BadMessageException
- if the parameter is not presentpublic double getRequiredDoubleParameter(String name) throws BadMessageException
getRequiredDoubleParameter
in interface IHttpRequestHeader
name
- the parameter name
BadMessageException
- if the parameter is not present or the parameter value is not a numberpublic float getRequiredFloatParameter(String name) throws BadMessageException
getRequiredFloatParameter
in interface IHttpRequestHeader
name
- the parameter name
BadMessageException
- if the parameter is not present or the parameter value is not a numberpublic int getRequiredIntParameter(String name) throws BadMessageException
getRequiredIntParameter
in interface IHttpRequestHeader
name
- the parameter name
BadMessageException
- if the parameter is not present or the parameter is not a numberpublic long getRequiredLongParameter(String name) throws BadMessageException
getRequiredLongParameter
in interface IHttpRequestHeader
name
- the parameter name
BadMessageException
- if the parameter is not present or the parameter is not a numberpublic String getRequiredStringParameter(String name) throws BadMessageException
getRequiredStringParameter
in interface IHttpRequestHeader
name
- the parameter name
BadMessageException
- if the parameter is not presentpublic String getServerName()
getServerName
in interface IHttpRequestHeader
public int getServerPort()
getServerPort
in interface IHttpRequestHeader
public int getContentLength()
getContentLength
in interface IHttpMessageHeader
public boolean isSecure()
isSecure
in interface IHttpRequestHeader
public void setMethod(String method)
setMethod
in interface IHttpRequestHeader
method
- a String specifying the name of the methodpublic void setParameter(String parameterName, String parameterValue)
setParameter
in interface IHttpRequestHeader
parameterName
- the parameter nameparameterValue
- the parameter valuepublic void addParameter(String parameterName, String parameterValue)
addParameter
in interface IHttpRequestHeader
parameterName
- the parameter nameparameterValue
- the parameter valuepublic void setRequestUrl(URL url)
setRequestUrl
in interface IHttpRequestHeader
url
- the request urlpublic Object getAttribute(String name)
Object
,
or null
if no attribute of the given name exists.
getAttribute
in interface IHttpMessageHeader
name
- a String
specifying the name of the attribute
Object
containing the value of the attribute,
or null
if the attribute does not existpublic 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 IHttpMessageHeader
Set
of strings
containing the names of the message's attributespublic 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 IHttpMessageHeader
Enumeration
of strings containing the names
of the message's attributespublic List<ContentType> getAccept()
getAccept
in interface IHttpRequestHeader
public String getScheme()
getScheme
in interface IHttpRequestHeader
public String getHost()
null
if the header is not set
getHost
in interface IHttpRequestHeader
null
if the header is not setpublic String getUserAgent()
null
if the header is not set
getUserAgent
in interface IHttpRequestHeader
null
if the header is not setpublic void setHost(String host)
setHost
in interface IHttpRequestHeader
host
- the Host headerpublic void setUserAgent(String userAgent)
setUserAgent
in interface IHttpRequestHeader
userAgent
- the User-Agent headerpublic IHttpRequestHeader copy()
copy
in interface IHttpMessageHeader
copy
in interface IHttpRequestHeader
public void copyHeaderFrom(IHttpMessageHeader otherHeader, String... upperExcludenames)
copyHeaderFrom
in interface IHttpMessageHeader
otherHeader
- the other headerupperExcludenames
- the header names to excludepublic String getProtocol()
getProtocol
in interface IHttpMessageHeader
public String getProtocolVersion()
getProtocolVersion
in interface IHttpMessageHeader
public String getTransferEncoding()
null
if the header is not set
getTransferEncoding
in interface IHeader
null
if the header is not setpublic void removeHopByHopHeaders()
removeHopByHopHeaders
in interface IHttpMessageHeader
public void setAttribute(String name, Object o)
setAttribute
in interface IHttpMessageHeader
name
- a String
specifying
the name of the attributeo
- the Object
to be storedpublic void setContentLength(int length)
setContentLength
in interface IHttpMessageHeader
length
- the content length in bytespublic void setContentType(String type)
setContentType
in interface IHeader
type
- the MIME type of the body of the partpublic void setTransferEncoding(String transferEncoding)
setTransferEncoding
in interface IHeader
transferEncoding
- the Transfer-Encoding parameterpublic String toString()
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 |