|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.w3c.mwi.mobileok.basic.HttpRetrievalElement
public class HttpRetrievalElement
An instance of the class represents an HTTP client/server exchange, i.e. an HTTP request and an HTTP response.
Field Summary | |
---|---|
private HTTPErrorsType |
httpsOutcome
The HTTPS outcome, as defined in the HTTPS section of the W3C mobileOK Basic Tests 1.0 standard. |
private static int |
MAX_BODY_SIZE_BYTES
Maximum size of an HTTP response before giving up retrieval. |
static int |
NETWORK_ERROR
Specific HTTP status code that indicates that a network error occurred. |
private static org.apache.commons.httpclient.Header[] |
NO_HEADERS
Empty list of HTTP headers |
private byte[] |
rawBody
HTTP Response body, null when reponse is too large. |
private int |
rawBodySize
HTTP Response body size. |
private org.apache.commons.httpclient.Header[] |
rawRequestHeaders
The list of HTTP request headers that were sent. |
private org.apache.commons.httpclient.Header[] |
rawResponseHeaders
The list of HTTP response headers that were received. |
private java.util.Map<java.lang.String,java.lang.String> |
requestHeaders
The list of HTTP request headers that were sent. |
private java.util.Map<java.lang.String,java.lang.String> |
responseHeaders
The list of HTTP response headers that were received. |
private java.lang.String |
responseProtocol
HTTP protocol of the response. |
private java.lang.String |
responseReason
Error message that details the network error that may have occurred. |
private int |
statusCode
HTTP Response status code. |
private java.net.URI |
uri
URI of the retrieved resource. |
Constructor Summary | |
---|---|
HttpRetrievalElement(org.apache.commons.httpclient.HttpMethod httpMethod)
Creates a class instance bound to an HTTP exchange. |
|
HttpRetrievalElement(org.apache.commons.httpclient.HttpMethod httpMethod,
HTTPErrorsType httpsErrorCode)
Creates a class instance bound to an HTTP exchange and initializes the HTTPS outcome to the given one. |
|
HttpRetrievalElement(java.net.URI uri,
java.lang.String errorReason)
Creates a "fake" class instance bound to a URI with a message that explains why it could not be retrieved. |
Method Summary | |
---|---|
private static void |
addHeaderElements(java.util.Map<java.lang.String,java.lang.String> headers,
org.w3c.dom.Node request,
org.w3c.dom.Document document)
Adds a representation of the given list of HTTP header fields to the given Node . |
private void |
addHTTPResponseError(org.w3c.dom.Document document,
org.w3c.dom.Node parent,
ResourceContext context)
Adds information about the HTTP error that may have been received if the resource could not be retrieved. |
java.lang.String |
getContentType()
Returns the content-type of the retrieved resource, as defined in the Content-Type HTTP header. |
java.lang.String |
getContentTypeEncoding()
Extracts the encoding from the Content-Type HTTP header
received in the HTTP Response. |
HTTPErrorsType |
getHttpsError()
Returns the outcome of running the HTTPS tests defined in the HTTPS section of the W3C mobileOK Basic Tests 1.0 standard. |
byte[] |
getRawBody()
Returns the HTTP response body. |
int |
getRawBodySize()
Returns the size of the HTTP response body. |
(package private) org.apache.commons.httpclient.Header[] |
getRawRequestHeaders()
Returns the list of HTTP request headers that were sent to retrieve the final resource. |
(package private) org.apache.commons.httpclient.Header[] |
getRawResponseHeaders()
Returns the list of HTTP response headers that were received with the final resource. |
(package private) java.util.Map<java.lang.String,java.lang.String> |
getRequestHeaders()
Returns the list of HTTP request headers that were sent to retrieve the final resource. |
(package private) java.util.Map<java.lang.String,java.lang.String> |
getResponseHeaders()
Returns the list of HTTP response headers that were received with the final resource. |
(package private) java.lang.String |
getResponseProtocol()
Returns the HTTP protocol of the response. |
(package private) java.lang.String |
getResponseReason()
When a network error occurred and getResponseStatus() returns
NETWORK_ERROR , this method returns the exception error message. |
(package private) int |
getResponseStatus()
Returns the HTTP Response status code. |
java.net.URI |
getUri()
Returns the absolute URI of the retrieved resource. |
private static void |
parameterize(java.lang.String parameters,
org.w3c.dom.Node parent,
org.w3c.dom.Document document,
HeaderParseMethod parseMethod)
|
private static java.util.Map<java.lang.String,java.lang.String> |
parseHTTPHeaders(org.apache.commons.httpclient.Header[] headers)
Converts a list of HTTP headers to a (name, value) map. |
private static java.lang.String |
serializeHTTPHeaders(org.apache.commons.httpclient.Header[] headers)
Static helper method that serializes a list of HTTP Header fields. |
org.w3c.dom.Node |
toMokiNode(org.w3c.dom.Document document,
org.w3c.dom.Node parent,
ResourceContext context)
Serializes the retrieval element to its moki representation as a DOM node. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int NETWORK_ERROR
private static final int MAX_BODY_SIZE_BYTES
private static final org.apache.commons.httpclient.Header[] NO_HEADERS
private final int statusCode
private final java.lang.String responseProtocol
private final java.lang.String responseReason
private java.net.URI uri
private final byte[] rawBody
null
when reponse is too large.
private final int rawBodySize
private final org.apache.commons.httpclient.Header[] rawRequestHeaders
private final org.apache.commons.httpclient.Header[] rawResponseHeaders
private final java.util.Map<java.lang.String,java.lang.String> requestHeaders
private final java.util.Map<java.lang.String,java.lang.String> responseHeaders
private HTTPErrorsType httpsOutcome
Constructor Detail |
---|
HttpRetrievalElement(org.apache.commons.httpclient.HttpMethod httpMethod) throws java.io.IOException
Note that the instantiation may take some time as the constructor retrieves information needed to create the instance on the network.
httpMethod
- HTTP exchange to wrap in the created instance.
java.io.IOException
- a network error occurred.HttpRetrievalElement(org.apache.commons.httpclient.HttpMethod httpMethod, HTTPErrorsType httpsErrorCode) throws java.io.IOException
httpMethod
- HTTP exchange to wrap in the created instance.httpsErrorCode
- outcome of running the HTTPS tests.
java.io.IOException
- a network error occurred.HttpRetrievalElement(java.net.URI uri, java.lang.String errorReason)
This constructor should only be used when the HTTP request could not process at all due to some network error.
getResponseStatus()
returns NETWORK_ERROR
for the
created instance.
uri
- absolute URI of the resource that could not be retrieved.errorReason
- details of the network error that occurred.Method Detail |
---|
public byte[] getRawBody()
getRawBody
in interface RetrievalElement
null
when the
response was too large, or when a network error occurred.public int getRawBodySize()
The size is computed even when the response was too large.
getRawBodySize
in interface RetrievalElement
org.apache.commons.httpclient.Header[] getRawRequestHeaders()
org.apache.commons.httpclient.Header[] getRawResponseHeaders()
java.util.Map<java.lang.String,java.lang.String> getRequestHeaders()
java.util.Map<java.lang.String,java.lang.String> getResponseHeaders()
int getResponseStatus()
NETWORK_ERROR
may be returned.java.lang.String getResponseProtocol()
java.lang.String getResponseReason()
getResponseStatus()
returns
NETWORK_ERROR
, this method returns the exception error message.
public java.net.URI getUri()
getUri
in interface RetrievalElement
private static java.util.Map<java.lang.String,java.lang.String> parseHTTPHeaders(org.apache.commons.httpclient.Header[] headers)
headers
- list of HTTP headers to convert
public HTTPErrorsType getHttpsError()
HTTPS
,
the returned value is undefined when that's not the case.public java.lang.String getContentType()
getContentType
in interface RetrievalElement
public java.lang.String getContentTypeEncoding()
Content-Type
HTTP header
received in the HTTP Response.
getContentTypeEncoding
in interface RetrievalElement
Content-Type
header,
null
if not found.public org.w3c.dom.Node toMokiNode(org.w3c.dom.Document document, org.w3c.dom.Node parent, ResourceContext context)
RetrievalElement
Note that in an ideal world, there should be no need to pass the context that gave birth to the creation of the retrieval element as an argument, but HTTP error codes defined in mobileOK depend on the context, so it seems easier to issue the appropriate error code in the serialization rather than having to compute it afterwards depending on the location of the error code in the moki representation.
toMokiNode
in interface RetrievalElement
document
- DOM document the created node should belong toparent
- DOM node to which the representation should be appended.context
- context under which the retrieval element was created.
The context is needed to return the appropriate error
messages when the resource could not be retrieved.
private void addHTTPResponseError(org.w3c.dom.Document document, org.w3c.dom.Node parent, ResourceContext context)
The context under which the resource that contains the retrieval element is required because mobileOK defines specific error codes that depend on whether the error occurred for the primary resource, an image, a linked resource, ...
document
- the document containing the Node
to completeparent
- the Node
that is to contain the description of the error.context
- the context that gave birth to the resource.private static void addHeaderElements(java.util.Map<java.lang.String,java.lang.String> headers, org.w3c.dom.Node request, org.w3c.dom.Document document)
Node
.
headers
- the list of HTTP header fields to represent as a DOM tree.request
- the Node
that is to contain the representation of the list.document
- the document containing the Node
to completeprivate static java.lang.String serializeHTTPHeaders(org.apache.commons.httpclient.Header[] headers)
headers
- list of HTTP header fields to serialize.
private static void parameterize(java.lang.String parameters, org.w3c.dom.Node parent, org.w3c.dom.Document document, HeaderParseMethod parseMethod)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |