Class 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 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
      • 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
    • Constructor Detail

      • HttpClientTransport

        public HttpClientTransport()
        Creates the http client transport. Generally only one will be created.
    • 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 the HTTP_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 the HTTP_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 interface ClientTransport<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

        This 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 interface ClientTransport<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
      • 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 interface ClientTransport<java.net.URI>
      • 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 transport
        uri - the URL to transport o 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 Attivio XMLSerializer.
        Parameters:
        o - the object to transport
        uri - 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 interface ClientTransport<java.net.URI>
      • 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: