Package com.attivio.transport
Class HttpClientTransport
- java.lang.Object
-
- com.attivio.transport.HttpClientTransport
-
- All Implemented Interfaces:
ClientTransport<java.net.URI>
- Direct Known Subclasses:
HttpsClientTransport
public class HttpClientTransport extends java.lang.Object implements ClientTransport<java.net.URI>
Handles sending Messages to Attivio HTTP receivers.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ATTIVIO_AUTHENTICATION_REALM
Attivio authentication realmstatic java.lang.String
ATTIVIO_SERVER
The Attivio HTTP server type.static java.lang.String
CONTENT_TYPE_XML_UTF8
The constant for "text/xml; charset=utf-8".static long
DEFAULT_HTTP_IDLE_TIMEOUT
Default setting forHTTP_IDLE_TIMEOUT_PROPERTY
.static java.lang.String
HTTP_CONNECTION_TIMEOUT_PROPERTY
Property read to determine the connection timeout(default=0).static java.lang.String
HTTP_CONNECTIONS_PER_HOST_PROPERTY
Default number of http connections to allow to any single host by the commons http client.static java.lang.String
HTTP_IDLE_TIMEOUT_PROPERTY
Property read to determine idle connection timeout (default=30000 (30seconds))static java.lang.String
HTTP_INACTIVITY_VALIDATION_TIMEOUT_PROPERTY
Property read to determine how much inactivity requires re-validation on re-lease of connection (stale check) (default=30000 (30seconds))static java.lang.String
HTTP_MAX_CONNECTIONS_PROPERTY
Property read to determine the maximum number of http connections to a single host (default=1024).static java.lang.String
HTTP_RECEIVER_ADMIN_PASSWORD_PROPERTY
HTTP transport admin password propertystatic java.lang.String
HTTP_RECEIVER_ADMIN_USERNAME_PROPERTY
HTTP transport admin user name propertystatic java.lang.String
HTTP_SO_TIMEOUT_PROPERTY
Property read to determine the SO TIMEOUT (default=0).static java.lang.String
X_ATTIVIO_ASYNC
Custom Attivio HTTP request header, indicates asynchronous message dispatch desired.static java.lang.String
X_ATTIVIO_BASEPORT
Custom Attivio HTTP header, contains baseport property.static java.lang.String
X_ATTIVIO_EXCEPTION
Custom Attivio HTTP header, contains remote exception.static java.lang.String
X_ATTIVIO_HOME
Custom Attivio HTTP header, contains home directory.static java.lang.String
X_ATTIVIO_ORIG_RESPONSE_CODE
Custom Attivio HTTP header, contains original response code when response code is converted to SC_OK.static java.lang.String
X_ATTIVIO_PROJECT
Custom Attivio HTTP header, contains project directory.static java.lang.String
X_ATTIVIO_VERSION
Custom Attivio HTTP header, contains Attivio version.
-
Constructor Summary
Constructors Constructor Description HttpClientTransport()
Creates the http client transport.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.net.URI
createSender(java.net.URI uri, boolean synchronous)
no op.void
dispatchMessage(PlatformMessage msg, java.net.URI sender)
Asynchronously send a message via the provided sender with no expected return.static java.lang.String
getPassword()
Returns the password configured via theHTTP_RECEIVER_ADMIN_PASSWORD_PROPERTY
property.java.lang.String
getProtocol()
Get the String protocol that this transports implements.java.net.URI
getSender(java.net.URI uri)
URI's are always validstatic java.lang.String
getUsername()
Returns the username configured via theHTTP_RECEIVER_ADMIN_USERNAME_PROPERTY
property.static HttpClientTransport
instance()
static HttpClientTransport
instance(boolean useSSL)
Return a HttpsClientTransport if ssl is used, return HttpClientTransport if notvoid
resetClient()
Resets the static HttpClient using System properties for username and password.void
resetClient(java.lang.String username, java.lang.String password)
Resets the static HttpClientvoid
resetConnectionManager()
Stop and start the connection manager if there are any live connections in the pool.PlatformMessage
sendMessage(PlatformMessage msg, java.net.URI sender)
Synchronously send a message via the provided sender.void
shutdown()
Closes down any transport related resourcesvoid
startConnectionManager()
Setup the connection manager and all default parameters.void
stopSender(java.net.URI sender)
no op.<T> T
transport(java.lang.Class<? extends T> clazz, java.lang.Object o, java.lang.String uri)
Sends the object synchronously to the uri via HTTP POST.void
transportAsync(java.lang.Object o, java.lang.String uri)
Sends the object asynchronously to the uri via HTTP POST.
-
-
-
Field Detail
-
CONTENT_TYPE_XML_UTF8
public static final java.lang.String CONTENT_TYPE_XML_UTF8
The constant for "text/xml; charset=utf-8".- See Also:
- Constant Field Values
-
ATTIVIO_SERVER
public static final java.lang.String ATTIVIO_SERVER
The Attivio HTTP server type.- See Also:
- Constant Field Values
-
X_ATTIVIO_BASEPORT
public static final java.lang.String X_ATTIVIO_BASEPORT
Custom Attivio HTTP header, contains baseport property.- See Also:
- Constant Field Values
-
X_ATTIVIO_HOME
public static final java.lang.String X_ATTIVIO_HOME
Custom Attivio HTTP header, contains home directory.- See Also:
- Constant Field Values
-
X_ATTIVIO_PROJECT
public static final java.lang.String X_ATTIVIO_PROJECT
Custom Attivio HTTP header, contains project directory.- See Also:
- Constant Field Values
-
X_ATTIVIO_VERSION
public static final java.lang.String X_ATTIVIO_VERSION
Custom Attivio HTTP header, contains Attivio version.- See Also:
- Constant Field Values
-
X_ATTIVIO_EXCEPTION
public static final java.lang.String X_ATTIVIO_EXCEPTION
Custom Attivio HTTP header, contains remote exception.- See Also:
- Constant Field Values
-
X_ATTIVIO_ASYNC
public static final java.lang.String X_ATTIVIO_ASYNC
Custom Attivio HTTP request header, indicates asynchronous message dispatch desired.- See Also:
- Constant Field Values
-
X_ATTIVIO_ORIG_RESPONSE_CODE
public static final java.lang.String X_ATTIVIO_ORIG_RESPONSE_CODE
Custom Attivio HTTP header, contains original response code when response code is converted to SC_OK.- See Also:
- Constant Field Values
-
HTTP_MAX_CONNECTIONS_PROPERTY
public static final java.lang.String HTTP_MAX_CONNECTIONS_PROPERTY
Property read to determine the maximum number of http connections to a single host (default=1024).- See Also:
- Constant Field Values
-
HTTP_CONNECTIONS_PER_HOST_PROPERTY
public static final java.lang.String HTTP_CONNECTIONS_PER_HOST_PROPERTY
Default number of http connections to allow to any single host by the commons http client.- See Also:
- Constant Field Values
-
HTTP_CONNECTION_TIMEOUT_PROPERTY
public static final java.lang.String HTTP_CONNECTION_TIMEOUT_PROPERTY
Property read to determine the connection timeout(default=0).- See Also:
- Constant Field Values
-
HTTP_SO_TIMEOUT_PROPERTY
public static final java.lang.String HTTP_SO_TIMEOUT_PROPERTY
Property read to determine the SO TIMEOUT (default=0).- See Also:
- Constant Field Values
-
HTTP_IDLE_TIMEOUT_PROPERTY
public static final java.lang.String HTTP_IDLE_TIMEOUT_PROPERTY
Property read to determine idle connection timeout (default=30000 (30seconds))- See Also:
- Constant Field Values
-
DEFAULT_HTTP_IDLE_TIMEOUT
public static final long DEFAULT_HTTP_IDLE_TIMEOUT
Default setting forHTTP_IDLE_TIMEOUT_PROPERTY
.- See Also:
- Constant Field Values
-
HTTP_INACTIVITY_VALIDATION_TIMEOUT_PROPERTY
public static final java.lang.String HTTP_INACTIVITY_VALIDATION_TIMEOUT_PROPERTY
Property read to determine how much inactivity requires re-validation on re-lease of connection (stale check) (default=30000 (30seconds))- See Also:
- Constant Field Values
-
ATTIVIO_AUTHENTICATION_REALM
public static final java.lang.String ATTIVIO_AUTHENTICATION_REALM
Attivio authentication realm- See Also:
- Constant Field Values
-
HTTP_RECEIVER_ADMIN_USERNAME_PROPERTY
public static final java.lang.String HTTP_RECEIVER_ADMIN_USERNAME_PROPERTY
HTTP transport admin user name property- See Also:
- Constant Field Values
-
HTTP_RECEIVER_ADMIN_PASSWORD_PROPERTY
public static final java.lang.String HTTP_RECEIVER_ADMIN_PASSWORD_PROPERTY
HTTP transport admin password property- See Also:
- Constant Field Values
-
-
Method Detail
-
startConnectionManager
public void startConnectionManager()
Setup the connection manager and all default parameters.
-
resetConnectionManager
public void resetConnectionManager()
Stop and start the connection manager if there are any live connections in the pool.
-
getUsername
public static java.lang.String getUsername()
Returns the username configured via theHTTP_RECEIVER_ADMIN_USERNAME_PROPERTY
property.- Returns:
- the configured username or
null
if none defined.
-
getPassword
public static java.lang.String getPassword()
Returns the password configured via theHTTP_RECEIVER_ADMIN_PASSWORD_PROPERTY
property. The password may be encrypted.- Returns:
- the configured password or
null
if none defined.
-
resetClient
public void resetClient()
Resets the static HttpClient using System properties for username and password.
-
resetClient
public void resetClient(java.lang.String username, java.lang.String password)
Resets the static HttpClient
-
sendMessage
public PlatformMessage sendMessage(PlatformMessage msg, java.net.URI sender) throws TransportException
Synchronously send a message via the provided sender.- Specified by:
sendMessage
in interfaceClientTransport<java.net.URI>
- Parameters:
msg
- the message to send.sender
- the sender that was chosen based on the URI that the message must be sent toThis method can block as long as is required to send the message including allowing time for the receiver to free up resources.
- Throws:
TransportException
-
dispatchMessage
public void dispatchMessage(PlatformMessage msg, java.net.URI sender) throws TransportException
Asynchronously send a message via the provided sender with no expected return.- Specified by:
dispatchMessage
in interfaceClientTransport<java.net.URI>
- Parameters:
msg
- the message to send.sender
- the sender that was chosen based on the URI that the message must be sent to- Throws:
TransportException
-
stopSender
public void stopSender(java.net.URI sender) throws TransportException
no op.- Specified by:
stopSender
in interfaceClientTransport<java.net.URI>
- Throws:
TransportException
-
getProtocol
public java.lang.String getProtocol()
Description copied from interface:ClientTransport
Get the String protocol that this transports implements.This will register this protocol with Attivio for message delivery.
For example if this method returned "foo" then URI's of the form:
foo://someUriSyntax:8000/goes?here
would be processed using this transport. This must return a constant value and must return that value as soon as the object is constructed as the value is registered with the platform and can not be changed once registered.- Specified by:
getProtocol
in interfaceClientTransport<java.net.URI>
-
createSender
public java.net.URI createSender(java.net.URI uri, boolean synchronous) throws TransportException
no op.- Specified by:
createSender
in interfaceClientTransport<java.net.URI>
- Throws:
TransportException
-
transport
public <T> T transport(java.lang.Class<? extends T> clazz, java.lang.Object o, java.lang.String uri) throws AttivioException
Sends the object synchronously to the uri via HTTP POST.The object will be serialized using the Attivio
XMLSerializer
. If a response is returned it will be deserialized and returned.- Parameters:
o
- the object to transporturi
- the URL to transporto
to- Returns:
- the deserialized response
- Throws:
AttivioException
-
transportAsync
public void transportAsync(java.lang.Object o, java.lang.String uri) throws AttivioException
Sends the object asynchronously to the uri via HTTP POST. The object will be serialized using the AttivioXMLSerializer
.- Parameters:
o
- the object to transporturi
- the URI to transport the object to- Throws:
AttivioException
-
getSender
public java.net.URI getSender(java.net.URI uri)
URI's are always valid- Specified by:
getSender
in interfaceClientTransport<java.net.URI>
-
shutdown
public void shutdown() throws TransportException
Closes down any transport related resources- Specified by:
shutdown
in interfaceClientTransport<java.net.URI>
- Throws:
TransportException
-
instance
public static HttpClientTransport instance()
- Returns:
- an already created transport or creates one
-
instance
public static HttpClientTransport instance(boolean useSSL)
Return a HttpsClientTransport if ssl is used, return HttpClientTransport if not- Parameters:
useSSL
-- Returns:
-
-