org.w3c.mwi.mobileok.basic
Class HTTPResource

java.lang.Object
  extended by org.w3c.mwi.mobileok.basic.HTTPResource
Direct Known Subclasses:
HTTPImageResource, HTTPObjectResource, HTTPTextResource

public abstract class HTTPResource
extends java.lang.Object

Abstract class that encapsulates information and basic functionality to represent resources that are retrieved using HTTP (or HTTPS).

The information includes the headers returned in the HTTP(S) Response as well as the body of the response and any intermediary redirection that might have been required to retrieved the resource from its initial URI.

The HTTP resource is retrieved when the instance is created. Since there is no way to ensure that the retrieval will take a given amount of time, the instanciation of the class may thus take more than a minute.

The HTTP request sent to retrieve the HTTP resource contains precise HTTP header fields that identify the mobileOK Checker. The specific values are hard-coded in the class, and defined in the W3C mobileOK Basic Tests 1.0 standard. They are:

The final HTTP status code is accessible through the getStatusCode() method. A network error is represented by the specific status HTTPRedirect.NETWORK_ERROR.

The final response is accessible through the getLastRedirect() method. When a network error occurred, a fake HTTPRedirect instance is created (with status code HTTPRedirect.NETWORK_ERROR).

If the scheme of the resource's URI is HTTPS, the MobileOKSSLProtocolSocketFactory and the MobileOKTrustManager classes are used to create and check the secure socket. The final HTTPS outcome is accessible through the corresponding HTTPRedirect instance and the HTTPRedirect.getHttpsError() method.

The class does not contain any abstract method per se. The class is defined as abstract to emphasize the fact that the Checker never deals with generic HTTP/HTTPS resources in practice, but rather with specific HTTPCSSResource, HTTPXHTMLResource, HTTPImageResource, etc.

Version:
$Revision: 1.1 $
Author:
The W3C mobileOK Checker Task Force

Constructor Summary
HTTPResource(java.net.URI uri)
           
HTTPResource(java.net.URI uri, java.util.Map<java.lang.String,java.lang.String> additionalRequestHeaders)
           
 
Method Summary
(package private) static void configureHTTPMethod(org.apache.commons.httpclient.HttpMethod method, java.util.Map<java.lang.String,java.lang.String> additionalRequestHeaders)
           
(package private) static void executeMethod(org.apache.commons.httpclient.HttpMethod method)
           
(package private)  HTTPRedirect getLastRedirect()
           
(package private)  org.apache.commons.httpclient.Header[] getRawRequestHeaders()
           
(package private)  byte[] getRawResponseBody()
           
(package private)  org.apache.commons.httpclient.Header[] getRawResponseHeaders()
           
(package private)  HTTPRedirect getRedirect(int redirect)
           
(package private)  int getRedirectCount()
           
(package private)  java.util.Map<java.lang.String,java.lang.String> getRequestHeaders()
           
(package private)  java.util.Map<java.lang.String,java.lang.String> getResponseHeaders()
           
(package private)  java.lang.String getResponseProtocol()
           
(package private)  java.lang.String getResponseReason()
           
(package private)  int getResponseStatus()
           
 int getStatusCode()
           
 java.net.URI getURI()
           
 java.lang.String getURI(int redirect)
           
(package private) static boolean isValidDateHeader(java.lang.String dateHeader)
           
static boolean isValidExpirationDate(java.lang.String currentDateStr, java.lang.String expirationDateStr)
           
(package private) static java.net.URI massageURI(java.net.URI uri)
           
(package private) static java.net.URI parseURI(java.net.URI baseURI, java.lang.String uriString)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HTTPResource

public HTTPResource(java.net.URI uri)
             throws TestException
Throws:
TestException

HTTPResource

public HTTPResource(java.net.URI uri,
                    java.util.Map<java.lang.String,java.lang.String> additionalRequestHeaders)
             throws TestException
Throws:
TestException
Method Detail

massageURI

static java.net.URI massageURI(java.net.URI uri)

configureHTTPMethod

static void configureHTTPMethod(org.apache.commons.httpclient.HttpMethod method,
                                java.util.Map<java.lang.String,java.lang.String> additionalRequestHeaders)

executeMethod

static void executeMethod(org.apache.commons.httpclient.HttpMethod method)
                   throws java.io.IOException
Throws:
java.io.IOException

getRedirectCount

final int getRedirectCount()

getStatusCode

public final int getStatusCode()

getURI

public final java.net.URI getURI()

getURI

public final java.lang.String getURI(int redirect)

getRedirect

final HTTPRedirect getRedirect(int redirect)

getLastRedirect

final HTTPRedirect getLastRedirect()

getRawRequestHeaders

final org.apache.commons.httpclient.Header[] getRawRequestHeaders()

getRequestHeaders

final java.util.Map<java.lang.String,java.lang.String> getRequestHeaders()

getRawResponseHeaders

final org.apache.commons.httpclient.Header[] getRawResponseHeaders()

getResponseHeaders

final java.util.Map<java.lang.String,java.lang.String> getResponseHeaders()

getResponseStatus

final int getResponseStatus()

getResponseProtocol

final java.lang.String getResponseProtocol()

getResponseReason

final java.lang.String getResponseReason()

getRawResponseBody

final byte[] getRawResponseBody()

isValidExpirationDate

public static boolean isValidExpirationDate(java.lang.String currentDateStr,
                                            java.lang.String expirationDateStr)

isValidDateHeader

static boolean isValidDateHeader(java.lang.String dateHeader)

parseURI

static java.net.URI parseURI(java.net.URI baseURI,
                             java.lang.String uriString)