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 | Field and Description |
---|---|
static java.lang.String |
ACCEPT_ENCODING |
protected org.apache.http.impl.client.CloseableHttpClient |
cachedclient |
protected org.apache.http.client.config.RequestConfig |
cachedconfig |
protected boolean |
cachevalid |
protected static org.apache.http.HttpResponseInterceptor |
CEKILL |
protected boolean |
closed |
protected static org.apache.http.impl.conn.PoolingHttpClientConnectionManager |
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 ucar.httpservices.HTTPSession.ExecState |
execution |
protected static java.util.Map<org.apache.http.auth.AuthScope,org.apache.http.client.CredentialsProvider> |
globalcreds |
protected static java.lang.Boolean |
globaldebugheaders |
protected static org.apache.http.conn.ssl.SSLConnectionSocketFactory |
globalsslfactory |
static java.lang.String |
HEADER_USERAGENT |
protected static org.apache.http.HttpHost |
httpproxy |
protected static org.apache.http.HttpHost |
httpsproxy |
protected java.lang.String |
identifier |
protected static java.lang.String |
keypassword |
protected static java.lang.String |
keypath |
protected static java.security.KeyStore |
keystore |
protected java.util.Map<org.apache.http.auth.AuthScope,org.apache.http.client.CredentialsProvider> |
localcreds |
protected ucar.httpservices.HTTPSession.Settings |
localsettings |
static org.slf4j.Logger |
log |
protected java.util.List<HTTPMethod> |
methodList |
protected static java.lang.String |
proxypwd |
protected static java.lang.String |
proxyuser |
protected java.net.URI |
requestURI |
protected org.apache.http.auth.AuthScope |
scope |
protected java.net.URI |
scopeURI |
protected org.apache.http.client.protocol.HttpClientContext |
sessioncontext |
protected java.lang.String |
sessionURI |
protected static org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> |
sslregistry |
static boolean |
TESTING |
protected static java.lang.String |
trustpassword |
protected static java.lang.String |
trustpath |
protected static java.security.KeyStore |
truststore |
Modifier | Constructor and Description |
---|---|
protected |
HTTPSession() |
Modifier and Type | Method and Description |
---|---|
protected static java.lang.String |
checkCompressors(java.lang.String compressors) |
HTTPSession |
clearCookies() |
HTTPSession |
clearCredentialsCache() |
void |
clearState()
Deprecated.
|
void |
close()
Close the session.
|
protected void |
configClient(org.apache.http.impl.client.HttpClientBuilder cb,
ucar.httpservices.HTTPSession.Settings settings) |
protected org.apache.http.client.config.RequestConfig |
configureRequest(org.apache.http.client.config.RequestConfig.Builder rcb,
ucar.httpservices.HTTPSession.Settings settings) |
static void |
debugHeaders(boolean print) |
static HTTPUtil.InterceptRequest |
debugRequestInterceptor() |
static void |
debugReset() |
static HTTPUtil.InterceptResponse |
debugResponseInterceptor() |
org.apache.http.auth.AuthScope |
getAuthScope() |
java.util.List<org.apache.http.cookie.Cookie> |
getCookies() |
org.apache.http.client.config.RequestConfig |
getDebugConfig() |
protected static int |
getDPropInt(java.lang.String key) |
static java.lang.Object |
getGlobalSetting(java.lang.String key) |
static int |
getGlobalThreadCount() |
static java.lang.String |
getGlobalUserAgent() |
int |
getMethodcount() |
org.apache.http.Header[] |
getRequestHeaders() |
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() |
static void |
removeGlobalCompression() |
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.
|
void |
setCredentials(java.lang.String url,
org.apache.http.auth.Credentials creds)
Deprecated.
|
void |
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
|
void |
setCredentialsProvider(java.lang.String url,
org.apache.http.client.CredentialsProvider provider)
Deprecated.
|
protected static void |
setDefaults(ucar.httpservices.HTTPSession.Settings 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) |
static void |
setGlobalCredentialsProvider(org.apache.http.client.CredentialsProvider provider,
org.apache.http.auth.AuthScope scope)
This is the most general case
|
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 nthreads) |
static void |
setGlobalMaxRedirects(int n)
Set the max number of redirects to follow
|
static void |
setGlobalProxy(java.lang.String proxyurl) |
static void |
setGlobalProxy(java.lang.String host,
int port)
Deprecated.
|
static void |
setGlobalSoTimeout(int timeout) |
static void |
setGlobalSSLAuth(java.lang.String keypath,
java.lang.String keypassword,
java.lang.String trustpath,
java.lang.String trustpassword) |
static void |
setGlobalThreadCount(int nthreads) |
static void |
setGlobalUserAgent(java.lang.String userAgent) |
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.
|
static void |
setRetryCount(int count)
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) |
public static final java.lang.String HEADER_USERAGENT
public static final java.lang.String ACCEPT_ENCODING
public static org.slf4j.Logger log
protected static org.apache.http.impl.conn.PoolingHttpClientConnectionManager connmgr
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 java.util.Map<java.lang.String,org.apache.http.client.entity.InputStreamFactory> contentDecoderMap
protected static java.util.Map<org.apache.http.auth.AuthScope,org.apache.http.client.CredentialsProvider> globalcreds
protected static java.security.KeyStore keystore
protected static java.security.KeyStore truststore
protected static java.lang.String keypath
protected static java.lang.String keypassword
protected static java.lang.String trustpath
protected static java.lang.String trustpassword
protected static org.apache.http.conn.ssl.SSLConnectionSocketFactory globalsslfactory
protected static org.apache.http.config.Registry<org.apache.http.conn.socket.ConnectionSocketFactory> sslregistry
protected static org.apache.http.HttpHost httpproxy
protected static org.apache.http.HttpHost httpsproxy
protected static java.lang.String proxyuser
protected static java.lang.String proxypwd
protected static java.lang.Boolean globaldebugheaders
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.List<HTTPMethod> methodList
protected java.lang.String identifier
protected ucar.httpservices.HTTPSession.Settings localsettings
protected org.apache.http.client.protocol.HttpClientContext sessioncontext
protected boolean cachevalid
protected org.apache.http.impl.client.CloseableHttpClient cachedclient
protected org.apache.http.client.config.RequestConfig cachedconfig
protected java.net.URI requestURI
protected ucar.httpservices.HTTPSession.ExecState execution
public static boolean TESTING
protected HTTPSession() throws HTTPException
HTTPException
protected static void setDefaults(ucar.httpservices.HTTPSession.Settings props)
protected static int getDPropInt(java.lang.String key)
public static void setGlobalUserAgent(java.lang.String userAgent)
public static java.lang.String getGlobalUserAgent()
public static void setGlobalThreadCount(int nthreads)
public static void setGlobalMaxConnections(int nthreads)
public static int getGlobalThreadCount()
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 setGlobalCredentialsProvider(org.apache.http.client.CredentialsProvider provider) throws HTTPException
provider
- HTTPException
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
public static void setGlobalCredentials(org.apache.http.auth.Credentials creds) throws HTTPException
creds
- HTTPException
public 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)HTTPException
public static void setGlobalSSLAuth(java.lang.String keypath, java.lang.String keypassword, java.lang.String trustpath, java.lang.String trustpassword)
public static void setGlobalProxy(java.lang.String proxyurl)
protected void init(org.apache.http.auth.AuthScope scope, java.lang.String actualurl) throws HTTPException
HTTPException
protected 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 java.lang.Object getSetting(java.lang.String key)
public void close()
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
public HTTPSession setCredentialsProvider(org.apache.http.client.CredentialsProvider provider) throws HTTPException
provider
- HTTPException
public 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)HTTPException
public HTTPSession setCredentials(org.apache.http.auth.Credentials creds) throws HTTPException
creds
- HTTPException
public 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)HTTPException
protected org.apache.http.client.config.RequestConfig configureRequest(org.apache.http.client.config.RequestConfig.Builder rcb, ucar.httpservices.HTTPSession.Settings settings) throws HTTPException
HTTPException
protected void configClient(org.apache.http.impl.client.HttpClientBuilder cb, ucar.httpservices.HTTPSession.Settings settings) throws HTTPException
HTTPException
protected void setAuthenticationAndProxy(org.apache.http.impl.client.HttpClientBuilder cb) throws HTTPException
cb
- HTTPException
public boolean isClosed()
public int getMethodcount()
public org.apache.http.client.config.RequestConfig getDebugConfig()
public org.apache.http.Header[] getRequestHeaders()
protected static void kill()
protected static void track(HTTPSession session)
public static void debugHeaders(boolean print)
public static void debugReset()
public static HTTPUtil.InterceptRequest debugRequestInterceptor()
public static HTTPUtil.InterceptResponse debugResponseInterceptor()
@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 void setCredentials(java.lang.String url, org.apache.http.auth.Credentials creds) throws HTTPException
HTTPException
@Deprecated public void setCredentialsProvider(java.lang.String url, org.apache.http.client.CredentialsProvider provider) throws HTTPException
HTTPException
@Deprecated public void 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 static void setRetryCount(int count)
@Deprecated public void clearState()
@Deprecated public java.lang.String getSessionURL()