Class DefaultMessageManager

  • All Implemented Interfaces:
    MessageManager, MessageResponseCallback

    public class DefaultMessageManager
    extends java.lang.Object
    implements MessageManager, MessageResponseCallback
    Message manager in charge of sending a request and waiting for the response for a given time before a time out IOException is thrown.

    If a IssueTokenRequest message is processed, but not returned in time is a revoke message sent back to the client.

    • Field Detail

      • SETTING_MESSAGE_TIMEOUT_MILLIS

        public static final java.lang.String SETTING_MESSAGE_TIMEOUT_MILLIS
        Setting indicating the time-out of a message in milli-seconds before IOException is thrown.
        See Also:
        Constant Field Values
      • DEFAULT_MESSAGE_TIMEOUT_MILLIS

        public static final java.lang.String DEFAULT_MESSAGE_TIMEOUT_MILLIS
        See Also:
        Constant Field Values
      • SETTING_MESSAGEHANDLER_CLASSPATH

        public static final java.lang.String SETTING_MESSAGEHANDLER_CLASSPATH
        Setting indicating the message handler to use to send and receive the messages.
        See Also:
        Constant Field Values
      • REVOKE_REASON_REASONINFORMATION_CESSATIONOFOPERATION

        protected static java.lang.String REVOKE_REASON_REASONINFORMATION_CESSATIONOFOPERATION
      • SLEEP_INTERVAL_MILLIS

        protected static long SLEEP_INTERVAL_MILLIS
      • destination

        protected java.lang.String destination
      • timeout

        protected long timeout
    • Constructor Detail

      • DefaultMessageManager

        public DefaultMessageManager()
    • Method Detail

      • init

        public void init​(java.util.Properties config,
                         PKIMessageParser parser,
                         java.lang.String destination)
                  throws java.lang.IllegalArgumentException,
                         java.io.IOException,
                         MessageException
        Method that initializes the message manager
        Specified by:
        init in interface MessageManager
        Parameters:
        config - configuration properties specific for a mq certificate manager. Available property keys is depending on underlying implementation.
        parser - message parser to use
        destination - the destination of sent messages
        Throws:
        java.lang.IllegalArgumentException - if arguments sent to the method were illegal or the given property file contained bad configuration.
        java.io.IOException - if communication problems occurred with underlying systems, such as time-out.
        MessageException - if there were an critical internal error at the server side, that wasn't related to communication problems.
        See Also:
        MessageManager.init(Properties, PKIMessageParser, String)
      • sendMessage

        public PKIMessage sendMessage​(java.lang.String requestId,
                                      byte[] request)
                               throws java.lang.IllegalArgumentException,
                                      java.io.IOException,
                                      MessageException
        Main method signaling sending a request with given id and waits for a response for a given time before a time-out IO exception is thrown.
        Specified by:
        sendMessage in interface MessageManager
        request - the request message to send
        Throws:
        java.lang.IllegalArgumentException - if request contained invalid data.
        java.io.IOException - if communication problems occurred with underlying systems, such as time-out.
        MessageException - if there were an critical internal error at the server side, that wasn't related to communication problems.
      • responseReceived

        public void responseReceived​(PKIMessage responseMessage)
        Method called by the MessageHandler when receiving a message intended for this message manager.
        Specified by:
        responseReceived in interface MessageResponseCallback
        Parameters:
        responseMessage - the response message that was received.
      • registerWaitForRequestId

        protected void registerWaitForRequestId​(java.lang.String requestId)
        Signals that the current manager is listening for this message.
        Parameters:
        requestId - the id of the message to register
      • checkIfResponseIsReady

        protected PKIMessage checkIfResponseIsReady​(java.lang.String requestId)
        Method to check if a response have been sent to a request with the given id.
        Parameters:
        requestId - the id to check for
        Returns:
        the PKIMessage response or null if no response have been recieved yet.
      • cancelWaitForResponse

        protected void cancelWaitForResponse​(java.lang.String requestId)
        Method signaling that the waiting thread have stopped listening for a response to this request.
      • populateResponseMapIfStillExist

        protected boolean populateResponseMapIfStillExist​(java.lang.String requestId,
                                                          PKIMessage responseMessage)
        Method that is called by the responseRecieved method that it received a message to this listener and should populate the response map.
      • findRequestId

        protected java.lang.String findRequestId​(PKIMessage responseMessage)
        Method that extracts the requestId from the responseMessage. Where IssueTokenCredentialsResponse and GetCredentialResponse and FailureResponse is supported.
        Parameters:
        responseMessage - the message to parse request id from
        Returns:
        the request id or null if no valid request id was found in the response
      • close

        public void close()
                   throws java.io.IOException
        Closes the underlying connection.
        Specified by:
        close in interface MessageManager
        Throws:
        java.io.IOException - if problems occurred closing the connections.
        See Also:
        MessageManager.close()
      • getMessageHandler

        protected MessageHandler getMessageHandler​(java.util.Properties config,
                                                   PKIMessageParser parser)
                                            throws MessageException,
                                                   java.lang.IllegalArgumentException,
                                                   java.io.IOException
        Returns the message handler to use, if not configured is the default message handler created and returned.
        Throws:
        MessageException
        java.lang.IllegalArgumentException
        java.io.IOException
      • getConnectionFactory

        public java.lang.Object getConnectionFactory()
                                              throws MessageException,
                                                     java.io.IOException
        Description copied from interface: MessageManager
        Method returning the JMS connection factory used in underlying classes.

        Used only for special purposes. and requires a JMS infrastructure underneath otherwise is a PKIMessageException thrown.

        Specified by:
        getConnectionFactory in interface MessageManager
        Returns:
        a connection factory to use to set up the message processing environment, never null.
        Throws:
        MessageException - if internal error or configuration problems occurred.
        java.io.IOException - if communication problems occurred with the message service.
      • connect

        public void connect()
                     throws MessageException,
                            java.io.IOException
        Description copied from interface: MessageManager
        Method called by service if the underlying MessageHandler should connect to the MessageQueue server and start processing incoming calls.
        Specified by:
        connect in interface MessageManager
        Throws:
        MessageException - if configuration problems or other internal problems occurred connecting to the MQ server.
        java.io.IOException - if communication problems occurred connecting from the message server.
      • isConnected

        public boolean isConnected()
        Description copied from interface: MessageManager
        Method returning if the underlying message handler is currently connected.
        Specified by:
        isConnected in interface MessageManager
        Returns:
        true if connected.