|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.w3c.www.protocol.http.HttpManager
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.createRequest() ; 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() ; ...
Field Summary | |
static java.lang.String |
ACCEPT_ENCODING_P
Header properties - Set the accept encodings. |
static java.lang.String |
ACCEPT_LANGUAGE_P
Header properties - Set the accept language. |
static java.lang.String |
ACCEPT_P
Header properties - Set the accept header. |
protected int |
conn_count
|
protected int |
conn_max
|
static java.lang.String |
CONN_MAX_P
The maximum number of simultaneous connectionlrus. |
protected LRUList |
connectionsLru
The LRU list of connections. |
static java.lang.String |
DEFAULT_ACCEPT
The default value for the Accept header. |
static java.lang.String |
DEFAULT_USER_AGENT
The default value for the User-Agent header. |
static java.lang.String |
FILTERS_PROP_P
The name of the property containing the ProprequestFilter to launch. |
static java.lang.String |
MAX_STALE_P
Header properties - The allowed drift for getting cached resources. |
static java.lang.String |
MIN_FRESH_P
Header properties - The minium freshness required on cached resources. |
static java.lang.String |
ONLY_IF_CACHED_P
Header properties - Set the only if cached flag on requests. |
static java.lang.String |
PROXY_HOST_P
Header properties - What is the proxy host name. |
static java.lang.String |
PROXY_PORT_P
Header properties - What is the proxy port number. |
static java.lang.String |
PROXY_SET_P
Header properties - Should we use a proxy ? |
static java.lang.String |
SERVER_CLASS_P
The name of the property indicating the class of HttpServer to use. |
protected java.lang.Class |
serverclass
The class to instantiate to create new HttpServer instances. |
protected java.util.Hashtable |
servers
The server this manager knows about, indexed by FQDN of target servers. |
protected Request |
template
The template request (the request we will clone to create new requests) |
protected int |
timeout
|
static java.lang.String |
TIMEOUT_P
The SO_TIMEOUT of the client socket. |
static java.lang.String |
USER_AGENT_P
Header properties - Set the user agent. |
Constructor Summary | |
protected |
HttpManager()
Create a new HttpManager. |
Method Summary | |
protected boolean |
closeAnyConnection()
Close some connections, but pickling the least recently used ones. |
Request |
createRequest()
Create a new default outgoing request. |
protected void |
decrConnCount(HttpServer server)
Decrement the number of established connections. |
protected void |
deleteConnection(org.w3c.www.protocol.http.HttpConnection conn)
The given connection has been deleted. |
protected org.w3c.www.protocol.http.HttpConnection |
getConnection(HttpServer server)
Try reusing one of the idle connection of that server, if any. |
RequestFilter |
getGlobalFilter(java.lang.Class cls)
Find back an instance of a global filter. |
java.lang.String |
getGlobalHeader(java.lang.String name)
Global settings - Get a global request header default value. |
static HttpManager |
getManager()
|
static HttpManager |
getManager(java.util.Properties p)
Get an instance of the HTTP manager. |
ObservableProperties |
getProperties()
Get this manager properties. |
MimeParserFactory |
getReplyFactory()
|
java.lang.String |
getServerKey(Request request)
Get the String key for the server instance handling that request. |
protected void |
incrConnCount(HttpServer server)
A new client connection has been established. |
protected HttpServer |
lookupServer(java.lang.String host,
int port)
Get the appropriate server object for handling request to given target. |
static void |
main(java.lang.String[] args)
DEBUGGING ! |
protected boolean |
negotiateConnection(HttpServer server)
One of our server handler wants to open a connection. |
protected void |
notifyConnection(org.w3c.www.protocol.http.HttpConnection conn)
The given connection has just been created. |
void |
notifyIdle(org.w3c.www.protocol.http.HttpConnection conn)
The given connection can be reused, but is now idle. |
void |
notifyUse(org.w3c.www.protocol.http.HttpConnection conn)
The given connection is about to be used. |
boolean |
propertyChanged(java.lang.String name)
PropertyMonitoring implementation - Update properties on the fly ! |
Reply |
runRequest(Request request)
Run the given request, in synchronous mode. |
void |
setAllowUserInteraction(boolean onoff)
Allow the manager to interact with the user if needed. |
void |
setFilter(RequestFilter filter)
Add a global filter. |
void |
setFilter(java.net.URL[] incs,
java.net.URL[] exs,
RequestFilter filter)
Add a new request filter. |
void |
setGlobalHeader(java.lang.String name,
java.lang.String value)
Global settings - Define a global request header. |
void |
setMaxConnections(int max_conn)
Global settings - Set the max number of allowed connections. |
void |
setProxy(java.net.URL proxy)
Global settings - Set an optional proxy to use. |
void |
setRequestTimeout(int ms)
Global settings - Set the request timeout. |
void |
setTimeout(int timeout)
Global settings - Set the timeout on the socket |
void |
sync()
Dump all in-memory cached state to persistent storage. |
protected boolean |
tooManyConnections()
|
protected boolean |
updateProxy()
Update the proxy configuration to match current properties setting. |
boolean |
usingProxy()
Does this manager uses a proxy to fulfill requests ? |
protected void |
waitForConnection(HttpServer server)
Wait for a connection to come up. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final java.lang.String SERVER_CLASS_P
public static final java.lang.String FILTERS_PROP_P
public static final java.lang.String CONN_MAX_P
public static final java.lang.String TIMEOUT_P
public static final java.lang.String MAX_STALE_P
public static final java.lang.String MIN_FRESH_P
public static final java.lang.String ONLY_IF_CACHED_P
public static final java.lang.String USER_AGENT_P
public static final java.lang.String ACCEPT_P
public static final java.lang.String ACCEPT_LANGUAGE_P
public static final java.lang.String ACCEPT_ENCODING_P
public static final java.lang.String PROXY_SET_P
public static final java.lang.String PROXY_HOST_P
public static final java.lang.String PROXY_PORT_P
public static final java.lang.String DEFAULT_ACCEPT
Accept
header.public static final java.lang.String DEFAULT_USER_AGENT
User-Agent
header.protected java.lang.Class serverclass
protected java.util.Hashtable servers
protected Request template
protected LRUList connectionsLru
protected int timeout
protected int conn_count
protected int conn_max
Constructor Detail |
protected HttpManager()
props
- The properties from which the manager should initialize
itself, or null if none are available.Method Detail |
protected boolean updateProxy()
public final ObservableProperties getProperties()
public boolean propertyChanged(java.lang.String name)
name
- The name of the property that has changed.public void setAllowUserInteraction(boolean onoff)
onoff
- Turn interaction on or off.public static HttpManager getManager(java.util.Properties p)
public static HttpManager getManager()
public final java.lang.String getServerKey(Request request)
protected HttpServer lookupServer(java.lang.String host, int port) throws HttpException
key
- The server's key, as returned by getServerKey
.public void notifyUse(org.w3c.www.protocol.http.HttpConnection conn)
conn
- The idle connection.public void notifyIdle(org.w3c.www.protocol.http.HttpConnection conn)
conn
- The connection that is now idle.protected void notifyConnection(org.w3c.www.protocol.http.HttpConnection conn)
conn
- The newly created connection.protected void deleteConnection(org.w3c.www.protocol.http.HttpConnection conn)
conn
- The deleted connection.protected boolean tooManyConnections()
protected org.w3c.www.protocol.http.HttpConnection getConnection(HttpServer server)
server
- The target server.protected void waitForConnection(HttpServer server) throws java.lang.InterruptedException
server,
- the target server.protected boolean closeAnyConnection()
protected boolean negotiateConnection(HttpServer server)
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).protected final void incrConnCount(HttpServer server)
server
- The server that has established a new connection.protected final void decrConnCount(HttpServer server)
server
- The server that has closed one connection to its target.public Reply runRequest(Request request) throws HttpException
request
- The request to run.public MimeParserFactory getReplyFactory()
public void setFilter(java.net.URL[] incs, java.net.URL[] exs, RequestFilter filter)
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
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.public void setFilter(RequestFilter filter)
filter
- The filter to install.public RequestFilter getGlobalFilter(java.lang.Class cls)
cls
- The class of the filter to look for.public Request createRequest()
public void setMaxConnections(int max_conn)
This value defaults to the value of the
org.w3c.www.http.maxConnections
property.
max_conn
- The allowed maximum simultaneous open connections.public void setTimeout(int timeout)
This value defaults to the value of the
org.w3c.www.http.Timeout
property.
timeout
- The allowed maximum microsecond before a timeout.public void setProxy(java.net.URL proxy)
org.w3c.www.http.proxy
property is defined, it will be
used as the default value.proxy
- The URL for the proxy to use.public boolean usingProxy()
public void setRequestTimeout(int ms)
This timeout value defaults to the value of the
org.w3c.www.http.requestTimeout
property value.
ms
- The timeout value in milliseconds.public void setGlobalHeader(java.lang.String name, java.lang.String value)
createRequest
request.name
- The name of the header, case insensitive.value
- It's default value.public java.lang.String getGlobalHeader(java.lang.String name)
name
- The name of the header to get.public void sync()
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |