Class DefaultMessageManager
- java.lang.Object
-
- org.certificateservices.messages.pkimessages.manager.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classDefaultMessageManager.RequestEntryA request entry is used the the request map after a send message call i waiting for a response, contains a response PKI Message data.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_MESSAGE_TIMEOUT_MILLISprotected java.lang.Stringdestinationprotected MessageHandlermessageHandlerprotected PKIMessageParserparserprotected static java.lang.StringREVOKE_REASON_REASONINFORMATION_CESSATIONOFOPERATIONstatic java.lang.StringSETTING_MESSAGE_TIMEOUT_MILLISSetting indicating the time-out of a message in milli-seconds before IOException is thrown.static java.lang.StringSETTING_MESSAGEHANDLER_CLASSPATHSetting indicating the message handler to use to send and receive the messages.protected static longSLEEP_INTERVAL_MILLISprotected longtimeout
-
Constructor Summary
Constructors Constructor Description DefaultMessageManager()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcancelWaitForResponse(java.lang.String requestId)Method signaling that the waiting thread have stopped listening for a response to this request.protected PKIMessagecheckIfResponseIsReady(java.lang.String requestId)Method to check if a response have been sent to a request with the given id.voidclose()Closes the underlying connection.voidconnect()Method called by service if the underlying MessageHandler should connect to the MessageQueue server and start processing incoming calls.protected java.lang.StringfindRequestId(PKIMessage responseMessage)Method that extracts the requestId from the responseMessage.protected PKIResponsefindResponsePayload(PKIMessage responseMessage)java.lang.ObjectgetConnectionFactory()Method returning the JMS connection factory used in underlying classes.MessageHandlergetMessageHandler()Method to return a reference to the underlying message handler used.protected MessageHandlergetMessageHandler(java.util.Properties config, PKIMessageParser parser)Returns the message handler to use, if not configured is the default message handler created and returned.static longgetTimeOutInMillis(java.util.Properties config)voidinit(java.util.Properties config, PKIMessageParser parser, java.lang.String destination)Method that initializes the message managerbooleanisConnected()Method returning if the underlying message handler is currently connected.protected booleanpopulateResponseMapIfStillExist(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.protected voidregisterWaitForRequestId(java.lang.String requestId)Signals that the current manager is listening for this message.voidresponseReceived(PKIMessage responseMessage)Method called by the MessageHandler when receiving a message intended for this message manager.PKIMessagesendMessage(java.lang.String requestId, byte[] request)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.
-
-
-
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
-
parser
protected PKIMessageParser parser
-
destination
protected java.lang.String destination
-
messageHandler
protected MessageHandler messageHandler
-
timeout
protected long timeout
-
-
Method Detail
-
init
public void init(java.util.Properties config, PKIMessageParser parser, java.lang.String destination) throws java.lang.IllegalArgumentException, java.io.IOException, MessageExceptionMethod that initializes the message manager- Specified by:
initin interfaceMessageManager- Parameters:
config- configuration properties specific for a mq certificate manager. Available property keys is depending on underlying implementation.parser- message parser to usedestination- 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:
sendMessagein interfaceMessageManagerrequest- 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:
responseReceivedin interfaceMessageResponseCallback- 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
-
findResponsePayload
protected PKIResponse findResponsePayload(PKIMessage responseMessage)
-
close
public void close() throws java.io.IOExceptionCloses the underlying connection.- Specified by:
closein interfaceMessageManager- 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:
MessageExceptionjava.lang.IllegalArgumentExceptionjava.io.IOException
-
getTimeOutInMillis
public static long getTimeOutInMillis(java.util.Properties config) throws MessageException- Throws:
MessageException
-
getConnectionFactory
public java.lang.Object getConnectionFactory() throws MessageException, java.io.IOExceptionDescription copied from interface:MessageManagerMethod 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:
getConnectionFactoryin interfaceMessageManager- 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.IOExceptionDescription copied from interface:MessageManagerMethod called by service if the underlying MessageHandler should connect to the MessageQueue server and start processing incoming calls.- Specified by:
connectin interfaceMessageManager- 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.
-
getMessageHandler
public MessageHandler getMessageHandler()
Description copied from interface:MessageManagerMethod to return a reference to the underlying message handler used.- Specified by:
getMessageHandlerin interfaceMessageManager- Returns:
- underlying message handler used.
-
isConnected
public boolean isConnected()
Description copied from interface:MessageManagerMethod returning if the underlying message handler is currently connected.- Specified by:
isConnectedin interfaceMessageManager- Returns:
- true if connected.
-
-