|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.w3c.www.protocol.http.HttpManager
public class 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 typical 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 | |
---|---|
protected java.util.Hashtable |
_tmp_servers
|
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 int |
conn_timeout
|
static java.lang.String |
CONN_TIMEOUT_P
The connection timeout of the client socket. |
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. |
protected boolean |
keepbody
|
static java.lang.String |
KEEPBODY_P
Header properties - should we reuse a connection for POST? |
protected boolean |
lenient
|
static java.lang.String |
LENIENT_P
Header properties - are we parsing answers in a lenient way? |
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()
|
protected static HttpManager |
getManager(java.lang.Class managerclass,
java.util.Properties p)
|
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. |
boolean |
isLenient()
Is this manager parsing headers in a lenient way? |
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)
|
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 |
setConnTimeout(int conn_timeout)
Global settings - Set the connection timeout for the socket |
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 |
setLenient(boolean lenient)
Global settings - set the HTTP parsing lenient or not. |
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()
|
java.lang.String |
toString()
DEBUGGING ! |
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, 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 CONN_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 LENIENT_P
public static final java.lang.String KEEPBODY_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_timeout
protected int conn_count
protected int conn_max
protected boolean lenient
protected boolean keepbody
protected java.util.Hashtable _tmp_servers
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)
propertyChanged
in interface PropertyMonitoring
name
- The name of the property that has changed.
public void setAllowUserInteraction(boolean onoff)
onoff
- Turn interaction on or off.protected static HttpManager getManager(java.lang.Class managerclass, java.util.Properties p)
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
.
HttpException
- If the given host name couldn't be resolved.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.
java.lang.InterruptedException
- If interrupted..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.
HttpException
- If something failed during request processing.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.connections.max
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.connections.timeout
property.
timeout
- The allowed maximum microsecond before a timeout.public void setConnTimeout(int conn_timeout)
This value defaults to the value of the
org.w3c.www.protocol.http.connections.connTimeout
property
timeout
- The allowed maximum microsecond before a timeout.public void setLenient(boolean lenient)
lenient,
- true by default, false to detect wrong serverspublic boolean isLenient()
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 java.lang.String toString()
toString
in class java.lang.Object
public static void main(java.lang.String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |