@ThreadSafe
public class HTTPSession
extends java.lang.Object
implements java.io.Closeable
A Session encapsulate a number of other objects:
Currently, it is assumed that only one set of credentials is needed, whether directly for server X or for server Y. This may change in the future.
As a rule, if the client gives an HTTPSession object to the "create method"
procedures of HTTPFactory (e.g. HTTPFactory.Get or HTTPFactory.Post)
then that creation call must specify a url that is "compatible" with the
scope of the session. The method url is
If the HTTPFactory method creation call does not specify a session
object, then one is created (and destroyed) behind the scenes
along with the method.
Note that the term legalurl in the following code means that the url has
reserved characters within identifieers in escaped form. This is
particularly and issue for queries. Especially: ?x[0:5] is legal and the
square brackets need not be encoded.
As of the move to Apache Httpclient 4.4 and later, the underlying
HttpClient objects are generally immutable. This means that at least
this class (HTTPSession) and the HTTPMethod class must store the
relevant info and create the HttpClient and HttpMethod objects
dynamically. This also means that when a parameter is changed (Agent,
for example), any existing cached HttpClient must be thrown away and
reconstructed using the change. As a rule, the HttpClient object will be
created at the last minute so that multiple parameter changes can be
effected without have to re-create the HttpClient for each parameter
change. Also note that the immutable objects will be cached and reused
if no parameters are changed.
Authorization
We assume that the session supports two CredentialsProvider instances:
one global to all HTTPSession objects and one specific to each
HTTPSession object.
As an aside, authentication is a bit tricky because some
authorization schemes use redirection. That is, the initial request
is made to server X, but X says: goto to server Y" to get, say, and
authorization token. Then Y says: return to X with this token and
proceed.
SSL
TBD.
| Modifier and Type | Class and Description |
|---|---|
static class |
HTTPSession.Methods |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ACCEPT_ENCODING |
protected static ucar.httpservices.HTTPSession.AuthControls |
authcontrols |
protected org.apache.http.client.config.RequestConfig |
cachedconfig |
protected boolean |
cachevalid |
protected static org.apache.http.HttpResponseInterceptor |
CEKILL |
protected boolean |
closed |
protected static ucar.httpservices.HTTPConnections |
connmgr |
protected static java.util.Map<java.lang.String,org.apache.http.client.entity.InputStreamFactory> |
contentDecoderMap |
protected static java.util.List<org.apache.http.HttpRequestInterceptor> |
dbgreq |
protected static java.util.List<org.apache.http.HttpResponseInterceptor> |
dbgrsp |
protected static java.util.Map<org.apache.http.auth.AuthScope,HTTPProviderFactory> |
globalcredfactories |
static java.lang.String |
HEADER_USERAGENT |
protected java.lang.String |
identifier |
protected java.util.Map<org.apache.http.auth.AuthScope,org.apache.http.client.CredentialsProvider> |
localcreds |
protected java.util.Map<ucar.httpservices.HTTPSession.Prop,java.lang.Object> |
localsettings |
static org.slf4j.Logger |
log |
protected java.util.concurrent.ConcurrentSkipListSet<HTTPMethod> |
methods |
protected java.net.URI |
requestURI |
protected org.apache.http.auth.AuthScope |
scope |
protected java.net.URI |
scopeURI |
protected org.apache.http.impl.client.BasicAuthCache |
sessioncache |
protected org.apache.http.client.protocol.HttpClientContext |
sessioncontext |
protected java.lang.String |
sessionURI |
static boolean |
TESTING |
protected static boolean |
USEPOOL
Determine wether to use a Pooling connection manager
or to manage a bunch of individual connections.
|
| Modifier | Constructor and Description |
|---|---|
protected |
HTTPSession() |
| Modifier and Type | Method and Description |
|---|---|
protected static java.security.KeyStore |
buildkeystore(java.lang.String keypath,
java.lang.String keypassword) |
protected static java.lang.String |
checkCompressors(java.lang.String compressors) |
HTTPSession |
clearCookies() |
HTTPSession |
clearCredentialsCache() |
HTTPSession |
clearCredentialsCache(org.apache.http.auth.AuthScope template) |
static void |
clearGlobalCredentials()
Remove any global credentials that have been previosly set with the
setGlobalCredentials(Credentials)
or setCredentialsProviderFactory(ucar.httpservices.HTTPProviderFactory, org.apache.http.auth.AuthScope) methods. |
static void |
clearkeystore() |
void |
clearState()
Deprecated.
|
void |
close()
Close the session.
|
static HTTPUtil.InterceptRequest |
debugRequestInterceptor() |
static HTTPUtil.InterceptResponse |
debugResponseInterceptor() |
org.apache.http.auth.AuthScope |
getAuthScope() |
java.util.List<org.apache.http.cookie.Cookie> |
getCookies() |
org.apache.http.impl.client.BasicAuthCache |
getCredentialsCache() |
protected static int |
getDPropInt(java.lang.String key) |
static int |
getGlobalMaxConnection() |
static java.lang.Object |
getGlobalSetting(java.lang.String key) |
static java.lang.String |
getGlobalUserAgent() |
int |
getMethodcount() |
static int |
getRetryCount()
Deprecated.
|
java.lang.String |
getSessionID()
Extract the sessionid cookie value
|
java.lang.String |
getSessionURI() |
java.lang.String |
getSessionURL()
Deprecated.
|
java.lang.Object |
getSetting(java.lang.String key) |
protected void |
init(org.apache.http.auth.AuthScope scope,
java.lang.String actualurl) |
boolean |
isClosed() |
protected static void |
kill() |
java.util.Map<ucar.httpservices.HTTPSession.Prop,java.lang.Object> |
mergedSettings() |
static void |
rebuildkeystore(java.lang.String path,
java.lang.String pwd) |
static void |
removeGlobalCompression() |
static void |
resetInterceptors() |
protected void |
setAuthenticationAndProxy(org.apache.http.impl.client.HttpClientBuilder cb)
Handle authentication and Proxy'ing
|
HTTPSession |
setConnectionTimeout(int timeout) |
HTTPSession |
setCredentials(org.apache.http.auth.Credentials creds)
It is convenient to be able to directly set the Credentials
(not the provider) when those credentials are fixed.
|
HTTPSession |
setCredentials(org.apache.http.auth.Credentials creds,
org.apache.http.auth.AuthScope scope)
It is convenient to be able to directly set the Credentials
(not the provider) when those credentials are fixed.
|
HTTPSession |
setCredentials(java.lang.String url,
org.apache.http.auth.Credentials creds)
Deprecated.
|
HTTPSession |
setCredentialsProvider(org.apache.http.auth.AuthScope scope,
org.apache.http.client.CredentialsProvider provider)
Deprecated.
|
HTTPSession |
setCredentialsProvider(org.apache.http.client.CredentialsProvider provider) |
HTTPSession |
setCredentialsProvider(org.apache.http.client.CredentialsProvider provider,
org.apache.http.auth.AuthScope scope)
This is the most general case
|
HTTPSession |
setCredentialsProvider(java.lang.String url,
org.apache.http.client.CredentialsProvider provider)
Deprecated.
|
static void |
setCredentialsProviderFactory(HTTPProviderFactory factory,
org.apache.http.auth.AuthScope scope) |
protected static void |
setDefaults(java.util.Map<ucar.httpservices.HTTPSession.Prop,java.lang.Object> props) |
HTTPSession |
setFollowRedirects(boolean tf)
Enable/disable redirection following
Default is yes.
|
static void |
setGlobalCompression()
Deprecated.
|
static void |
setGlobalCompression(java.lang.String compressors) |
static void |
setGlobalConnectionTimeout(int timeout) |
static void |
setGlobalCredentials(org.apache.http.auth.Credentials creds)
It is convenient to be able to directly set the Credentials
(not the provider) when those credentials are fixed.
|
static void |
setGlobalCredentials(org.apache.http.auth.Credentials creds,
org.apache.http.auth.AuthScope scope)
It is convenient to be able to directly set the Credentials
(not the provider) when those credentials are fixed.
|
static void |
setGlobalCredentials(java.lang.String url,
org.apache.http.auth.Credentials creds)
Deprecated.
|
static void |
setGlobalCredentialsProvider(org.apache.http.auth.AuthScope scope,
org.apache.http.client.CredentialsProvider provider)
Deprecated.
|
static void |
setGlobalCredentialsProvider(org.apache.http.client.CredentialsProvider provider)
Deprecated.
|
static void |
setGlobalCredentialsProvider(org.apache.http.client.CredentialsProvider provider,
org.apache.http.auth.AuthScope scope)
Deprecated.
|
static void |
setGlobalCredentialsProvider(org.apache.http.client.CredentialsProvider provider,
java.lang.String scheme)
Deprecated.
|
static void |
setGlobalCredentialsProvider(java.lang.String url,
org.apache.http.client.CredentialsProvider provider)
Deprecated.
|
static void |
setGlobalFollowRedirects(boolean tf)
Enable/disable redirection following
Default is yes.
|
static void |
setGlobalMaxConnections(int n) |
static void |
setGlobalMaxRedirects(int n)
Set the max number of redirects to follow
|
static void |
setGlobalProxy(java.lang.String host,
int port)
Deprecated.
|
static void |
setGlobalRetryCount(int n) |
static void |
setGlobalSoTimeout(int timeout) |
static void |
setGlobalUserAgent(java.lang.String userAgent) |
static void |
setInterceptors(boolean print) |
protected static void |
setInterceptors(org.apache.http.impl.client.HttpClientBuilder cb) |
HTTPSession |
setMaxRedirects(int n)
Set the max number of redirects to follow
|
void |
setProxy(java.lang.String host,
int port)
Deprecated.
|
HTTPSession |
setSoTimeout(int timeout) |
HTTPSession |
setUserAgent(java.lang.String agent) |
HTTPSession |
setUseSessions(boolean tf)
Should we use sessionid's?
|
protected static void |
track(HTTPSession session) |
static void |
validatestate() |
public static boolean TESTING
protected static final boolean USEPOOL
public static final java.lang.String HEADER_USERAGENT
public static final java.lang.String ACCEPT_ENCODING
public static final org.slf4j.Logger log
protected static org.apache.http.HttpResponseInterceptor CEKILL
protected static java.util.List<org.apache.http.HttpRequestInterceptor> dbgreq
protected static java.util.List<org.apache.http.HttpResponseInterceptor> dbgrsp
protected static ucar.httpservices.HTTPConnections connmgr
protected static java.util.Map<java.lang.String,org.apache.http.client.entity.InputStreamFactory> contentDecoderMap
protected static java.util.Map<org.apache.http.auth.AuthScope,HTTPProviderFactory> globalcredfactories
protected static ucar.httpservices.HTTPSession.AuthControls authcontrols
protected java.lang.String sessionURI
protected java.net.URI scopeURI
protected org.apache.http.auth.AuthScope scope
protected boolean closed
protected java.util.Map<org.apache.http.auth.AuthScope,org.apache.http.client.CredentialsProvider> localcreds
protected java.util.concurrent.ConcurrentSkipListSet<HTTPMethod> methods
protected java.lang.String identifier
protected java.util.Map<ucar.httpservices.HTTPSession.Prop,java.lang.Object> localsettings
protected org.apache.http.client.protocol.HttpClientContext sessioncontext
protected org.apache.http.impl.client.BasicAuthCache sessioncache
protected java.net.URI requestURI
protected boolean cachevalid
protected org.apache.http.client.config.RequestConfig cachedconfig
protected HTTPSession()
throws HTTPException
HTTPExceptionprotected static int getDPropInt(java.lang.String key)
protected static void setDefaults(java.util.Map<ucar.httpservices.HTTPSession.Prop,java.lang.Object> props)
protected static final java.security.KeyStore buildkeystore(java.lang.String keypath,
java.lang.String keypassword)
public static void setGlobalUserAgent(java.lang.String userAgent)
public static java.lang.String getGlobalUserAgent()
public static void setGlobalMaxConnections(int n)
public static int getGlobalMaxConnection()
public static void setGlobalConnectionTimeout(int timeout)
public static void setGlobalSoTimeout(int timeout)
public static void setGlobalFollowRedirects(boolean tf)
public static void setGlobalMaxRedirects(int n)
n - public static java.lang.Object getGlobalSetting(java.lang.String key)
public static void setGlobalCompression(java.lang.String compressors)
public static void removeGlobalCompression()
protected static java.lang.String checkCompressors(java.lang.String compressors)
public static void setCredentialsProviderFactory(HTTPProviderFactory factory, org.apache.http.auth.AuthScope scope) throws HTTPException
factory - the credentials provider factoryscope - where to use it (i.e. on what host)HTTPExceptionpublic static void setGlobalCredentials(org.apache.http.auth.Credentials creds)
throws HTTPException
creds - HTTPExceptionpublic static void setGlobalCredentials(org.apache.http.auth.Credentials creds,
org.apache.http.auth.AuthScope scope)
throws HTTPException
creds - scope - where to use it (i.e. on what host)HTTPExceptionpublic static void clearGlobalCredentials()
setGlobalCredentials(Credentials)
or setCredentialsProviderFactory(ucar.httpservices.HTTPProviderFactory, org.apache.http.auth.AuthScope) methods.public static void setGlobalRetryCount(int n)
protected void init(org.apache.http.auth.AuthScope scope,
java.lang.String actualurl)
throws HTTPException
HTTPExceptionprotected static void setInterceptors(org.apache.http.impl.client.HttpClientBuilder cb)
public org.apache.http.auth.AuthScope getAuthScope()
public java.lang.String getSessionURI()
public java.lang.String getSessionID()
public HTTPSession setUserAgent(java.lang.String agent)
public HTTPSession setSoTimeout(int timeout)
public HTTPSession setConnectionTimeout(int timeout)
public HTTPSession setMaxRedirects(int n)
n - public HTTPSession setFollowRedirects(boolean tf)
public HTTPSession setUseSessions(boolean tf)
tf - public java.util.List<org.apache.http.cookie.Cookie> getCookies()
public HTTPSession clearCookies()
public HTTPSession clearCredentialsCache()
public HTTPSession clearCredentialsCache(org.apache.http.auth.AuthScope template)
public org.apache.http.impl.client.BasicAuthCache getCredentialsCache()
public java.lang.Object getSetting(java.lang.String key)
public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablepublic HTTPSession setCredentialsProvider(org.apache.http.client.CredentialsProvider provider) throws HTTPException
provider - HTTPExceptionpublic HTTPSession setCredentialsProvider(org.apache.http.client.CredentialsProvider provider, org.apache.http.auth.AuthScope scope) throws HTTPException
provider - the credentials providerscope - where to use it (i.e. on what host+port)HTTPExceptionpublic HTTPSession setCredentials(org.apache.http.auth.Credentials creds) throws HTTPException
creds - HTTPExceptionpublic HTTPSession setCredentials(org.apache.http.auth.Credentials creds, org.apache.http.auth.AuthScope scope) throws HTTPException
creds - scope - where to use it (i.e. on what host)HTTPExceptionprotected void setAuthenticationAndProxy(org.apache.http.impl.client.HttpClientBuilder cb)
throws HTTPException
cb - HTTPExceptionpublic java.util.Map<ucar.httpservices.HTTPSession.Prop,java.lang.Object> mergedSettings()
public boolean isClosed()
public int getMethodcount()
protected static void track(HTTPSession session)
public static void setInterceptors(boolean print)
public static void resetInterceptors()
public static HTTPUtil.InterceptRequest debugRequestInterceptor()
public static HTTPUtil.InterceptResponse debugResponseInterceptor()
public static void clearkeystore()
public static void rebuildkeystore(java.lang.String path,
java.lang.String pwd)
@Deprecated
public static void setGlobalCredentialsProvider(org.apache.http.auth.AuthScope scope,
org.apache.http.client.CredentialsProvider provider)
throws HTTPException
HTTPException@Deprecated
public static void setGlobalCredentialsProvider(java.lang.String url,
org.apache.http.client.CredentialsProvider provider)
throws HTTPException
HTTPException@Deprecated
public static void setGlobalCredentials(java.lang.String url,
org.apache.http.auth.Credentials creds)
throws HTTPException
HTTPException@Deprecated public HTTPSession setCredentials(java.lang.String url, org.apache.http.auth.Credentials creds) throws HTTPException
HTTPException@Deprecated public HTTPSession setCredentialsProvider(java.lang.String url, org.apache.http.client.CredentialsProvider provider) throws HTTPException
HTTPException@Deprecated public HTTPSession setCredentialsProvider(org.apache.http.auth.AuthScope scope, org.apache.http.client.CredentialsProvider provider) throws HTTPException
HTTPException@Deprecated public static int getRetryCount()
@Deprecated public static void setGlobalCompression()
@Deprecated
public static void setGlobalProxy(java.lang.String host,
int port)
@Deprecated
public void setProxy(java.lang.String host,
int port)
@Deprecated
public static void setGlobalCredentialsProvider(org.apache.http.client.CredentialsProvider provider,
java.lang.String scheme)
throws HTTPException
HTTPException@Deprecated public void clearState()
@Deprecated public java.lang.String getSessionURL()
protected static void kill()
public static void validatestate()
@Deprecated
public static void setGlobalCredentialsProvider(org.apache.http.client.CredentialsProvider provider)
throws HTTPException
provider - HTTPException@Deprecated
public static void setGlobalCredentialsProvider(org.apache.http.client.CredentialsProvider provider,
org.apache.http.auth.AuthScope scope)
throws HTTPException
provider - the credentials providerscope - where to use it (i.e. on what host)HTTPException