Class HttpClient
- java.lang.Object
-
- org.sblim.cimclient.internal.http.HttpClient
-
- All Implemented Interfaces:
java.util.EventListener
,javax.net.ssl.HandshakeCompletedListener
public class HttpClient extends java.lang.Object implements javax.net.ssl.HandshakeCompletedListener
Class HttpClient implements a HTTP client
-
-
Constructor Summary
Constructors Constructor Description HttpClient(java.net.URI url, HttpClientPool clientPool, AuthorizationHandler auth_handler)
Ctor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
connect()
Connects to the http serverstatic java.lang.String
convertToHexString(byte[] digest)
Converts a byte array to a String of hex digitsprotected static java.lang.String
dequote(java.lang.String str)
void
disconnect()
Disconnects the sessionprotected void
finalize()
protected AuthorizationInfo
getAuthentication(boolean proxy, AuthorizationInfo prevAuthInfo, java.lang.String authenticate)
static HttpClient
getClient(java.net.URI url, HttpClientPool clientPool, AuthorizationHandler auth_handler)
Returns a client from a http client pooljava.lang.String
getHeaderField(java.lang.String name)
Returns the http header field for a given namejava.lang.String
getHeaderFieldName(int index)
Return the http header field name for a given indexjava.lang.String
getHeaderFieldValue(int index)
Returns the http header field value for a given indexjava.io.InputStream
getInputStream()
Returns the input stream of this http connectionjava.io.OutputStream
getOutputStream()
Returns the output stream of this http connectionjava.lang.String
getRequestMethod()
Returns the request methodjava.lang.String
getRequestProperty(java.lang.String key)
Returns the request property for a given keyint
getResponseCode()
Returns the response codejava.lang.String
getResponseMessage()
Returns the response messageprotected static void
handleRsp(java.lang.String authInfo, AuthorizationInfo prevAuthInfo)
void
handshakeCompleted(javax.net.ssl.HandshakeCompletedEvent event)
boolean
isConnected()
Returns connectedprotected static byte[]
parseHex(java.lang.String hex)
void
reset()
Resets statevoid
setRequestMethod(java.lang.String method)
Sets the request methodvoid
setRequestProperty(java.lang.String key, java.lang.String value)
Sets the request propertyvoid
streamFinished()
Releases the client and returns it to the poolvoid
streamFinished(boolean keep)
Releases the client and returns it to the pooljava.lang.String
toString()
void
useHttp11(boolean bool)
Enables/Disables use of http 1.1boolean
usingProxy()
Returns if a proxy is used
-
-
-
Constructor Detail
-
HttpClient
public HttpClient(java.net.URI url, HttpClientPool clientPool, AuthorizationHandler auth_handler)
Ctor.- Parameters:
url
- The url to connect toclientPool
- The associated client poolauth_handler
- The authentication handler
-
-
Method Detail
-
convertToHexString
public static java.lang.String convertToHexString(byte[] digest)
Converts a byte array to a String of hex digits- Parameters:
digest
- The byte array- Returns:
- The hex string
-
getClient
public static HttpClient getClient(java.net.URI url, HttpClientPool clientPool, AuthorizationHandler auth_handler)
Returns a client from a http client pool- Parameters:
url
- The url to connect toclientPool
- The client poolauth_handler
- The authentication handler to use- Returns:
- A http client from the pool
-
dequote
protected static java.lang.String dequote(java.lang.String str)
-
handleRsp
protected static void handleRsp(java.lang.String authInfo, AuthorizationInfo prevAuthInfo) throws java.io.IOException
- Throws:
java.io.IOException
-
parseHex
protected static byte[] parseHex(java.lang.String hex)
-
connect
public void connect() throws java.io.IOException
Connects to the http server- Throws:
java.io.IOException
-
disconnect
public void disconnect()
Disconnects the session
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
getHeaderFieldValue
public java.lang.String getHeaderFieldValue(int index)
Returns the http header field value for a given index- Parameters:
index
- The index- Returns:
- The header field value
-
getHeaderField
public java.lang.String getHeaderField(java.lang.String name)
Returns the http header field for a given name- Parameters:
name
- The name- Returns:
- The header field
-
getHeaderFieldName
public java.lang.String getHeaderFieldName(int index)
Return the http header field name for a given index- Parameters:
index
- The index- Returns:
- The name
-
getInputStream
public java.io.InputStream getInputStream() throws java.io.IOException
Returns the input stream of this http connection- Returns:
- The input stream
- Throws:
java.io.IOException
-
getOutputStream
public java.io.OutputStream getOutputStream()
Returns the output stream of this http connection- Returns:
- The output stream
-
getRequestMethod
public java.lang.String getRequestMethod()
Returns the request method- Returns:
- The request method
-
getRequestProperty
public java.lang.String getRequestProperty(java.lang.String key)
Returns the request property for a given key- Parameters:
key
- The key- Returns:
- The property
-
getResponseCode
public int getResponseCode() throws java.io.IOException
Returns the response code- Returns:
- The response code
- Throws:
java.io.IOException
-
getResponseMessage
public java.lang.String getResponseMessage()
Returns the response message- Returns:
- The response message
-
handshakeCompleted
public void handshakeCompleted(javax.net.ssl.HandshakeCompletedEvent event)
- Specified by:
handshakeCompleted
in interfacejavax.net.ssl.HandshakeCompletedListener
-
reset
public void reset()
Resets state
-
setRequestMethod
public void setRequestMethod(java.lang.String method)
Sets the request method- Parameters:
method
- The request method
-
setRequestProperty
public void setRequestProperty(java.lang.String key, java.lang.String value)
Sets the request property- Parameters:
key
- The property namevalue
- The value
-
streamFinished
public void streamFinished()
Releases the client and returns it to the pool
-
streamFinished
public void streamFinished(boolean keep)
Releases the client and returns it to the pool- Parameters:
keep
- iftrue
return to the pool, iffalse
drop.
-
useHttp11
public void useHttp11(boolean bool)
Enables/Disables use of http 1.1- Parameters:
bool
- iftrue
http 1.1 is enabled.
-
usingProxy
public boolean usingProxy()
Returns if a proxy is used- Returns:
true
if a proxy is used
-
getAuthentication
protected AuthorizationInfo getAuthentication(boolean proxy, AuthorizationInfo prevAuthInfo, java.lang.String authenticate) throws HttpParseException, java.security.NoSuchAlgorithmException
- Throws:
HttpParseException
java.security.NoSuchAlgorithmException
-
isConnected
public boolean isConnected()
Returns connected- Returns:
- The value of connected.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-