    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class w3c.www.protocol.http.HttpManager

    java.lang.Object
       |
       +----w3c.www.protocol.http.HttpManager

public class HttpManager
extends Object
implements PropertyMonitoring

The client side HTTP request manager. This class is the user interface (along with the other public classes of this package) for the W3C client side library implementing HTTP. A typicall request is launched though the following sequence:

    HttpManager     manager = HttpManager.getManager() ;
    Request request = manager.makeRequest() ;
    request.setMethod(HTTP.GET) ;
    request.setURL(new URL("http://www.w3.org/pub/WWW/"));
    Reply    reply = manager.runRequest(request) ;
    // Get the reply input stream that contains the actual data:
    InputStream in = reply.getInputStream() ;
    ...

##

ACCEPT_ENCODING_P
  Header properties - Set the accept encodings.
ACCEPT_LANGUAGE_P
  Header properties - Set the accept language.
ACCEPT_P
  Header properties - Set the accept header.
conn_count
conn_max
CONN_MAX_P
  The maximum number of simultaneous connections.
connectionsLru
  The LRU list of connections.
DEFAULT_ACCEPT
  The default value for the `Accept` header.
DEFAULT_USER_AGENT
  The default value for the `User-Agent` header.
FILTERS_PROP_P
  The name of the property containing the ProprequestFilter to launch.
MAX_STALE_P
  Header properties - The allowed drift for getting cached resources.
MIN_FRESH_P
  Header properties - The minium freshness required on cached resources.
ONLY_IF_CACHED_P
  Header properties - Set the only if cached flag on requests.
PROXY_HOST_P
  Header properties - What is the proxy host name.
PROXY_PORT_P
  Header properties - What is the proxy port number.
PROXY_SET_P
  Header properties - Should we use a proxy ?
servers
  The server this manager knows about, indexed by FQDN of target servers.
template
  The template request (the request we will clone to create new requests)
USER_AGENT_P
  Header properties - Set the user agent.

##

closeAnyConnection()
  Close one connection, but pickling the least recently used one.
createRequest()
  Create a new default outgoing request.
decrConnCount(HttpServer)
  Decrement the number of established connections.
deleteConnection(HttpConnection)
  The given connection has been deleted.
getConnection(HttpServer)
  Try reusing one of the idle connection of that server, if any.
getGlobalFilter(Class)
  Find back an instance of a global filter.
getGlobalHeader(String)
getManager()
  Get an instance of the HTTP manager.
getReplyFactory()
incrConnCount(HttpServer)
  A new client connection has been established.
lookupServer(String, int)
  Get the appropriate server object for handling request to given target.
main(String[])
  DEBUGGING !
negotiateConnection(HttpServer)
  One of our server handler wants to open a connection.
notifyConnection(HttpConnection)
  The given connection has just been created.
notifyIdle(HttpConnection)
  The given connection can be reused, but is now idle.
notifyUse(HttpConnection)
  The given connection is about to be used.
propertyChanged(String)
  PropertyMonitoring implementation - Update properties on the fly !
runRequest(Request)
  Run the given request, in synchronous mode.
setAllowUserInteraction(boolean)
  Allow the manager to interact with the user if needed.
setFilter(RequestFilter)
  Add a global filter.
setFilter(URL[], URL[], RequestFilter)
  Add a new request filter.
setGlobalHeader(String, String)
  Global settings - Define a global request header.
setMaxConnections(int)
  Global settings - Set the max number of allowed connections.
setProxy(URL)
  Global settings - Set an optional proxy to use.
setRequestTimeout(int)
  Global settings - Set the request timeout.
tooManyConnections()
updateProxy()
  Update the proxy configuration to match current properties setting.
waitForConnection(HttpServer)

##

FILTERS_PROP_P

      public final static String FILTERS_PROP_P

  The name of the property containing the ProprequestFilter to launch.

CONN_MAX_P

      public final static String CONN_MAX_P

  The maximum number of simultaneous connections.

MAX_STALE_P

      public final static String MAX_STALE_P

  Header properties - The allowed drift for getting cached resources.

MIN_FRESH_P

      public final static String MIN_FRESH_P

  Header properties - The minium freshness required on cached resources.

ONLY_IF_CACHED_P

      public final static String ONLY_IF_CACHED_P

  Header properties - Set the only if cached flag on requests.

USER_AGENT_P

      public final static String USER_AGENT_P

  Header properties - Set the user agent.

ACCEPT_P

      public final static String ACCEPT_P

  Header properties - Set the accept header.

ACCEPT_LANGUAGE_P

      public final static String ACCEPT_LANGUAGE_P

  Header properties - Set the accept language.

ACCEPT_ENCODING_P

      public final static String ACCEPT_ENCODING_P

  Header properties - Set the accept encodings.

PROXY_SET_P

      public final static String PROXY_SET_P

  Header properties - Should we use a proxy ?

PROXY_HOST_P

      public final static String PROXY_HOST_P

  Header properties - What is the proxy host name.

PROXY_PORT_P

      public final static String PROXY_PORT_P

  Header properties - What is the proxy port number.

DEFAULT_ACCEPT

      public final static String DEFAULT_ACCEPT

  The default value for the `Accept` header.

DEFAULT_USER_AGENT

      public final static String DEFAULT_USER_AGENT

  The default value for the `User-Agent` header.

servers

      protected Hashtable servers

  The server this manager knows about, indexed by FQDN of target servers.

template

      protected Request template

  The template request (the request we will clone to create new requests)

connectionsLru

      protected LRUList connectionsLru

  The LRU list of connections.

conn_count

      protected int conn_count

conn_max

      protected int conn_max

##

updateProxy

      protected boolean updateProxy()

  Update the proxy configuration to match current properties setting.
  Returns:
    A boolean, true if change was done, false otherwise.

propertyChanged

      public boolean propertyChanged(String name)

  PropertyMonitoring implementation - Update properties on the fly !
  Parameters:
    name - The name of the property that has changed.
  Returns:
    A boolean, true if change is accepted, false otherwise.

setAllowUserInteraction

      public void setAllowUserInteraction(boolean onoff)

  Allow the manager to interact with the user if needed. This will, for example, allow prompting for paswords, etc.
  Parameters:
    onoff - Turn interaction on or off.

getManager

      public static synchronized HttpManager getManager()

  Get an instance of the HTTP manager. This method returns an actual instance of the HTTP manager. It may return different managers, if it decides to distribute the load on different managers (avoid the HttpManager being a bottleneck).
  Returns:
    An application wide instance of the HTTP manager.

lookupServer

      protected synchronized HttpServer lookupServer(String host,
                                                     int port) throws HttpException

  Get the appropriate server object for handling request to given target.
  Parameters:
    key - The server's identifier encoded as a `host:port` String.
  Returns:
    An object complying to the HttpServer interface.
  Throws: HttpException
    If the given host name couldn't be resolved.

notifyUse

      public void notifyUse(HttpConnection conn)

  The given connection is about to be used. Update our list of available servers.
  Parameters:
    conn - The idle connection.

notifyIdle

      public void notifyIdle(HttpConnection conn)

  The given connection can be reused, but is now idle.
  Parameters:
    conn - The connection that is now idle.

notifyConnection

      protected synchronized void notifyConnection(HttpConnection conn)

  The given connection has just been created.
  Parameters:
    conn - The newly created connection.

deleteConnection

      protected void deleteConnection(HttpConnection conn)

  The given connection has been deleted.
  Parameters:
    conn - The deleted connection.

tooManyConnections

      protected synchronized boolean tooManyConnections()

getConnection

      protected HttpConnection getConnection(HttpServer server)

  Try reusing one of the idle connection of that server, if any.
  Parameters:
    server - The target server.
  Returns:
    An currently idle connection to the given server.

waitForConnection

      protected synchronized void waitForConnection(HttpServer server) throws InterruptedException

closeAnyConnection

      protected boolean closeAnyConnection()

  Close one connection, but pickling the least recently used one.
  Returns:
    A boolean, true if a connection was closed false otherwise.

negotiateConnection

      protected boolean negotiateConnection(HttpServer server)

  One of our server handler wants to open a connection.
  Parameters:
    block - A boolean indicating whether we should block the calling thread until a token is available (otherwise, the method will just peek at the connection count, and return the appropriate result).
  Returns:
    A boolean, true if the connection can be opened straight, false otherwise.

incrConnCount

      protected final synchronized void incrConnCount(HttpServer server)

  A new client connection has been established. This method will try to maintain a maximum number of established connections, by closing idle connections when possible.
  Parameters:
    server - The server that has established a new connection.

decrConnCount

      protected final synchronized void decrConnCount(HttpServer server)

  Decrement the number of established connections.
  Parameters:
    server - The server that has closed one connection to its target.

runRequest

      public Reply runRequest(Request request) throws HttpException

  Run the given request, in synchronous mode. This method will launch the given request, and block the calling thread until the response headers are available.
  Parameters:
    request - The request to run.
  Returns:
    An instance of Reply, containing all the reply informations.
  Throws: HTTPException
    If something failed during request processing.

getReplyFactory

      public MimeParserFactory getReplyFactory()

setFilter

      public void setFilter(URL incs[],
                            URL exs[],
                            RequestFilter filter)

  Add a new request filter. Request filters are called before a request is launched, and after the reply headers are available. They allow applications to setup specific request headers (such as PICS, or PEP stuff) on the way in, and check the reply on the way out.

  Request filters are application wide: if their scope matches the current request, then they will always be aplied.

  Filter scopes are defined inclusively and exclusively

  Parameters:
    incs - The URL domains for which the filter should be triggered.
    exs - The URL domains for which the filter should not be triggered.
    filter - The request filter to add.

setFilter

      public void setFilter(RequestFilter filter)

  Add a global filter. The given filter will always be invoked.
  Parameters:
    filter - The filter to install.

getGlobalFilter

      public RequestFilter getGlobalFilter(Class cls)

  Find back an instance of a global filter. This methods allow external classes to get a pointer to installed filters of a given class.
  Parameters:
    cls - The class of the filter to look for.
  Returns:
    A RequestFilter instance, or null if not found.

createRequest

      public Request createRequest()

  Create a new default outgoing request. This method should always be used to create outgoing requests. It will initialize the request with appropriate default values for the various headers, and make sure that the request is enhanced by the registered request filters.
  Returns:
    An instance of Request, suitable to be launched.

setMaxConnections

      public synchronized void setMaxConnections(int max_conn)

  Global settings - Set the max number of allowed connections. Set the maximum number of simultaneous connections that can remain opened. The manager will take care of queuing requests if this number is reached.

  This value defaults to the value of the `w3c.www.http.maxConnections` property.

  Parameters:
    max_conn - The allowed maximum simultaneous open connections.

setProxy

      public void setProxy(URL proxy)

  Global settings - Set an optional proxy to use. Set the proxy to which all requests should be targeted. If the `w3c.www.http.proxy` property is defined, it will be used as the default value.
  Parameters:
    proxy - The URL for the proxy to use.

setRequestTimeout

      public void setRequestTimeout(int ms)

  Global settings - Set the request timeout. Once a request has been emited, the HttpManager will sit for this given number of milliseconds before the request is declared to have timed-out.

  This timeout value defaults to the value of the `w3c.www.http.requestTimeout` property value.

  Parameters:
    ms - The timeout value in milliseconds.

setGlobalHeader

      public void setGlobalHeader(String name,
                                  String value)

  Global settings - Define a global request header. Set a default value for some request header. Once defined, the header will automatically be defined on all outgoing requests created through the `createRequest` request.
  Parameters:
    name - The name of the header, case insensitive.
    value - It's default value.

getGlobalHeader

      public String getGlobalHeader(String name)

main

      public static void main(String args[])

  DEBUGGING !

    All Packages  Class Hierarchy  This Package  Previous  Next  Index