下面列出了javax.jms.Message#getJMSCorrelationID ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onMessage(Message message) {
StandardLogger logger = LoggerUtil.getStandardLogger();
String logtag = "EngineDriver.T" + Thread.currentThread().getId() + " - ";
try {
String txt = ((TextMessage) message).getText();
if (logger.isDebugEnabled()) {
logger.debug("JMS Spring InternalEvent Listener receives request: " + txt);
}
logger.info(logtag + "starts processing");
String messageId = message.getJMSCorrelationID();
ProcessEngineDriver driver = new ProcessEngineDriver();
driver.processEvents(messageId, txt);
} catch (Throwable e) { // only possible when failed to get ProcessManager ejb
logger.error(logtag + "process exception " + e.getMessage(), e);
}
}
void copyMessageProperties(Message message, Message newMessage, String testId, Queue destination, String testIdHeaderName) throws JMSException {
String jmsCorrelationId = message.getJMSCorrelationID();
newMessage.setJMSCorrelationID(StringUtils.isNotEmpty(jmsCorrelationId) ? jmsCorrelationId : message.getJMSMessageID());
newMessage.setStringProperty(testIdHeaderName, testId);
newMessage.setJMSDestination(destination);
}
private ClientMessage buildClientMessage(final Message message) throws JMSException
{
String jmsMessageID = message.getJMSMessageID();
String jmsCorrelationID = message.getJMSCorrelationID();
byte[] jmsCorrelationIDAsBytes;
try
{
jmsCorrelationIDAsBytes = message.getJMSCorrelationIDAsBytes();
}
catch (JMSException e)
{
jmsCorrelationIDAsBytes = null;
}
long jmsTimestamp = message.getJMSTimestamp();
int jmsDeliveryMode = message.getJMSDeliveryMode();
boolean jmsRedelivered = message.getJMSRedelivered();
String jmsType = message.getJMSType();
long jmsExpiration = message.getJMSExpiration();
int jmsPriority = message.getJMSPriority();
return new JMSMessageAdaptor(jmsMessageID,
jmsTimestamp,
jmsCorrelationID,
jmsCorrelationIDAsBytes,
jmsDeliveryMode,
jmsRedelivered,
jmsType,
jmsExpiration,
jmsPriority);
}
/**
* Gets the correlation ID from a response message.
*
* @param message The message.
* @return The ID or {@code null} if the message does not contain the corresponding property.
*/
public static String getCorrelationID(final Message message) {
try {
return message.getJMSCorrelationID();
} catch (final JMSException e) {
return null;
}
}
private void handle() throws Exception {
Message message = consumer.receive();
OperationType operationType = OperationType.fromInt(message.getIntProperty("operationType"));
String operationData = message.getStringProperty("payload");
SimulatorOperation op = OperationCodec.fromJson(operationData, operationType.getClassType());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Received operation:" + op);
}
PromiseImpl promise = new PromiseImpl();
promise.replyTo = message.getJMSReplyTo();
promise.correlationId = message.getJMSCorrelationID();
promise.op = op;
SimulatorAddress source = SimulatorAddress.fromString(message.getStringProperty("source"));
try {
processor.process(op, source, promise);
} catch (Exception e) {
if (stop) {
throw e;
} else {
LOGGER.warn(e.getMessage(), e);
promise.answer(e);
}
}
}
private boolean processResponses(RemoteBroker remoteBroker) {
try {
Message replyMessage = remoteBroker.replyQueueConsumer.receiveNoWait();
if (replyMessage == null) {
return false;
}
String correlationId = replyMessage.getJMSCorrelationID();
FutureImpl future = futures.remove(correlationId);
if (future == null) {
LOGGER.debug("No future for " + correlationId + "\n" + replyMessage);
} else {
boolean error = replyMessage.getBooleanProperty("error");
if (error) {
String message = replyMessage.getStringProperty("message");
future.complete(new Exception(message));
} else {
future.complete(replyMessage.getStringProperty("payload"));
}
}
return true;
} catch (Exception e) {
if (!stop) {
//todo: feed into failure collector
LOGGER.fatal(e);
}
return false;
}
}
public static Map<String, String> createAttributeMap(final Message message) throws JMSException {
final Map<String, String> attributes = new HashMap<>();
final Enumeration<?> enumeration = message.getPropertyNames();
while (enumeration.hasMoreElements()) {
final String propName = (String) enumeration.nextElement();
final Object value = message.getObjectProperty(propName);
if (value == null) {
attributes.put(ATTRIBUTE_PREFIX + propName, "");
attributes.put(ATTRIBUTE_PREFIX + propName + ATTRIBUTE_TYPE_SUFFIX, "Unknown");
continue;
}
final String valueString = value.toString();
attributes.put(ATTRIBUTE_PREFIX + propName, valueString);
final String propType;
if (value instanceof String) {
propType = PROP_TYPE_STRING;
} else if (value instanceof Double) {
propType = PROP_TYPE_DOUBLE;
} else if (value instanceof Float) {
propType = PROP_TYPE_FLOAT;
} else if (value instanceof Long) {
propType = PROP_TYPE_LONG;
} else if (value instanceof Integer) {
propType = PROP_TYPE_INTEGER;
} else if (value instanceof Short) {
propType = PROP_TYPE_SHORT;
} else if (value instanceof Byte) {
propType = PROP_TYPE_BYTE;
} else if (value instanceof Boolean) {
propType = PROP_TYPE_BOOLEAN;
} else {
propType = PROP_TYPE_OBJECT;
}
attributes.put(ATTRIBUTE_PREFIX + propName + ATTRIBUTE_TYPE_SUFFIX, propType);
}
if (message.getJMSCorrelationID() != null) {
attributes.put(ATTRIBUTE_PREFIX + JMS_CORRELATION_ID, message.getJMSCorrelationID());
}
if (message.getJMSDestination() != null) {
String destinationName;
if (message.getJMSDestination() instanceof Queue) {
destinationName = ((Queue) message.getJMSDestination()).getQueueName();
} else {
destinationName = ((Topic) message.getJMSDestination()).getTopicName();
}
attributes.put(ATTRIBUTE_PREFIX + JMS_DESTINATION, destinationName);
}
if (message.getJMSMessageID() != null) {
attributes.put(ATTRIBUTE_PREFIX + JMS_MESSAGE_ID, message.getJMSMessageID());
}
if (message.getJMSReplyTo() != null) {
attributes.put(ATTRIBUTE_PREFIX + JMS_REPLY_TO, message.getJMSReplyTo().toString());
}
if (message.getJMSType() != null) {
attributes.put(ATTRIBUTE_PREFIX + JMS_TYPE, message.getJMSType());
}
attributes.put(ATTRIBUTE_PREFIX + JMS_DELIVERY_MODE, String.valueOf(message.getJMSDeliveryMode()));
attributes.put(ATTRIBUTE_PREFIX + JMS_EXPIRATION, String.valueOf(message.getJMSExpiration()));
attributes.put(ATTRIBUTE_PREFIX + JMS_PRIORITY, String.valueOf(message.getJMSPriority()));
attributes.put(ATTRIBUTE_PREFIX + JMS_REDELIVERED, String.valueOf(message.getJMSRedelivered()));
attributes.put(ATTRIBUTE_PREFIX + JMS_TIMESTAMP, String.valueOf(message.getJMSTimestamp()));
return attributes;
}
/**
* Gets the key to use for the Kafka Connect SourceRecord.
*
* @param context the JMS context to use for building messages
* @param topic the Kafka topic
* @param message the message
*
* @return the Kafka Connect SourceRecord's key
*
* @throws JMSException Message could not be converted
*/
public SchemaAndValue getKey(JMSContext context, String topic, Message message) throws JMSException {
Schema keySchema = null;
Object key = null;
String keystr;
switch (keyheader) {
case MESSAGE_ID:
keySchema = Schema.OPTIONAL_STRING_SCHEMA;
keystr = message.getJMSMessageID();
if (keystr.startsWith("ID:", 0)) {
key = keystr.substring(3);
}
else {
key = keystr;
}
break;
case CORRELATION_ID:
keySchema = Schema.OPTIONAL_STRING_SCHEMA;
keystr = message.getJMSCorrelationID();
if (keystr.startsWith("ID:", 0)) {
key = keystr.substring(3);
}
else {
key = keystr;
}
break;
case CORRELATION_ID_AS_BYTES:
keySchema = Schema.OPTIONAL_BYTES_SCHEMA;
key = message.getJMSCorrelationIDAsBytes();
break;
case DESTINATION:
keySchema = Schema.OPTIONAL_STRING_SCHEMA;
key = message.getJMSDestination().toString();
break;
default:
break;
}
return new SchemaAndValue(keySchema, key);
}
private static void verifyMessageHeaders(final MessageDescription messageDescription,
final Message message) throws VerificationException
{
try
{
for (Map.Entry<MessageDescription.MessageHeader, Serializable> entry : messageDescription.getHeaders()
.entrySet())
{
Object actualValue;
switch (entry.getKey())
{
case DESTINATION:
actualValue = message.getJMSDestination();
break;
case DELIVERY_MODE:
actualValue = message.getJMSDeliveryMode();
break;
case MESSAGE_ID:
actualValue = message.getJMSMessageID();
break;
case TIMESTAMP:
actualValue = message.getJMSTimestamp();
break;
case CORRELATION_ID:
if (entry.getValue() instanceof byte[])
{
actualValue = message.getJMSCorrelationIDAsBytes();
}
else
{
actualValue = message.getJMSCorrelationID();
}
break;
case REPLY_TO:
actualValue = message.getJMSReplyTo();
break;
case REDELIVERED:
actualValue = message.getJMSRedelivered();
break;
case TYPE:
actualValue = message.getJMSType();
break;
case EXPIRATION:
actualValue = message.getJMSExpiration();
break;
case PRIORITY:
actualValue = message.getJMSPriority();
break;
default:
throw new RuntimeException(String.format("unexpected message header '%s'", entry.getKey()));
}
verifyEquals(String.format("Unexpected message header '%s'", entry.getKey()),
entry.getValue(),
actualValue);
}
}
catch (JMSException e)
{
throw new RuntimeException("Unexpected exception during message header verification", e);
}
}
public void run(String... args) throws Exception {
String[] split = args[1].split("@");
String host = args[0];
String vpnName = split[1];
String username = split[0];
String password = args[2];
System.out.printf("BasicRequestor is connecting to Solace messaging at %s...%n", host);
// Programmatically create the connection factory using default settings
SolConnectionFactory connectionFactory = SolJmsUtility.createConnectionFactory();
connectionFactory.setHost(host);
connectionFactory.setVPN(vpnName);
connectionFactory.setUsername(username);
connectionFactory.setPassword(password);
// Create connection to the Solace router
Connection connection = connectionFactory.createConnection();
// Create a non-transacted, auto ACK session.
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
System.out.printf("Connected to the Solace Message VPN '%s' with client username '%s'.%n", vpnName,
username);
// Create the request topic programmatically
Topic requestTopic = session.createTopic(REQUEST_TOPIC_NAME);
// Create the message producer for the created queue
MessageProducer requestProducer = session.createProducer(requestTopic);
// The response will be received on this temporary queue.
TemporaryQueue replyToQueue = session.createTemporaryQueue();
// Create consumer for receiving the request's reply
MessageConsumer replyConsumer = session.createConsumer(replyToQueue);
// Start receiving replies
connection.start();
// Create a request.
TextMessage request = session.createTextMessage("Sample Request");
// The application must put the destination of the reply in the replyTo field of the request
request.setJMSReplyTo(replyToQueue);
// The application must put a correlation ID in the request
String correlationId = UUID.randomUUID().toString();
request.setJMSCorrelationID(correlationId);
System.out.printf("Sending request '%s' to topic '%s'...%n", request.getText(), requestTopic.toString());
// Send the request
requestProducer.send(requestTopic, request, DeliveryMode.NON_PERSISTENT,
Message.DEFAULT_PRIORITY,
Message.DEFAULT_TIME_TO_LIVE);
System.out.println("Sent successfully. Waiting for reply...");
// the main thread blocks at the next statement until a message received or the timeout occurs
Message reply = replyConsumer.receive(REPLY_TIMEOUT_MS);
if (reply == null) {
throw new Exception("Failed to receive a reply in " + REPLY_TIMEOUT_MS + " msecs");
}
// Process the reply
if (reply.getJMSCorrelationID() == null) {
throw new Exception(
"Received a reply message with no correlationID. This field is needed for a direct request.");
}
// Apache Qpid JMS prefixes correlation ID with string "ID:" so remove such prefix for interoperability
if (!reply.getJMSCorrelationID().replaceAll("ID:", "").equals(correlationId)) {
throw new Exception("Received invalid correlationID in reply message.");
}
if (reply instanceof TextMessage) {
System.out.printf("TextMessage response received: '%s'%n", ((TextMessage) reply).getText());
if (!reply.getBooleanProperty(SupportedProperty.SOLACE_JMS_PROP_IS_REPLY_MESSAGE)) {
System.out.println("Warning: Received a reply message without the isReplyMsg flag set.");
}
} else {
System.out.println("Message response received.");
}
System.out.printf("Message Content:%n%s%n", SolJmsUtility.dumpMessage(reply));
connection.stop();
// Close everything in the order reversed from the opening order
// NOTE: as the interfaces below extend AutoCloseable,
// with them it's possible to use the "try-with-resources" Java statement
// see details at https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
replyConsumer.close();
requestProducer.close();
session.close();
connection.close();
}
@Override
public void onMessage(final Message message) {
if (log.isDebugEnabled()) {
log.debug("onMessage, message=" + message);
}
try {
final long sentTimestamp = message.getJMSTimestamp();
final long currentTimestamp = System.currentTimeMillis();
// check if received message is not too old because in case of overload we could have old search-messages
if ((currentTimestamp - sentTimestamp) < receiveTimeout) {
final String correlationID = message.getJMSCorrelationID();
final Destination replyTo = message.getJMSReplyTo();
if (message instanceof ObjectMessage) {
final ObjectMessage objectMessage = (ObjectMessage) message;
final SearchRequest searchRequest = (SearchRequest) objectMessage.getObject();
taskExecutorService.runTask(new Runnable() {
@Override
public void run() {
onSearchMessage(searchRequest, correlationID, replyTo);
}
});
} else if (message instanceof TextMessage) {
final TextMessage testMessage = (TextMessage) message;
final String spellText = testMessage.getText();
taskExecutorService.runTask(new Runnable() {
@Override
public void run() {
onSpellMessage(spellText, correlationID, replyTo);
}
});
}
} else {
// JMS message is too old, discard it (do nothing)
log.warn("JMS message was too old, discard message, timeout=" + receiveTimeout + "ms , received time=" + (currentTimestamp - sentTimestamp) + "ms");
}
} catch (final JMSException e) {
log.error("error when receiving jms messages", e);
return; // signal search not available
} catch (final Error err) {
log.warn("Error in onMessage, ", err);
// OLAT-3973: don't throw exceptions here
} catch (final RuntimeException runEx) {
log.warn("RuntimeException in onMessage, ", runEx);
// OLAT-3973: don't throw exceptions here
}
}
@Override
public void onMessage(final Message message) {
if (log.isDebugEnabled()) {
log.debug("onMessage, message=" + message);
}
try {
final long sentTimestamp = message.getJMSTimestamp();
final long currentTimestamp = System.currentTimeMillis();
// check if received message is not too old because in case of overload we could have old search-messages
if ((currentTimestamp - sentTimestamp) < receiveTimeout) {
final String correlationID = message.getJMSCorrelationID();
final Destination replyTo = message.getJMSReplyTo();
if (message instanceof ObjectMessage) {
final ObjectMessage objectMessage = (ObjectMessage) message;
final SearchRequest searchRequest = (SearchRequest) objectMessage.getObject();
taskExecutorService.runTask(new Runnable() {
@Override
public void run() {
onSearchMessage(searchRequest, correlationID, replyTo);
}
});
} else if (message instanceof TextMessage) {
final TextMessage testMessage = (TextMessage) message;
final String spellText = testMessage.getText();
taskExecutorService.runTask(new Runnable() {
@Override
public void run() {
onSpellMessage(spellText, correlationID, replyTo);
}
});
}
} else {
// JMS message is too old, discard it (do nothing)
log.warn("JMS message was too old, discard message, timeout=" + receiveTimeout + "ms , received time=" + (currentTimestamp - sentTimestamp) + "ms");
}
} catch (final JMSException e) {
log.error("error when receiving jms messages", e);
return; // signal search not available
} catch (final Error err) {
log.warn("Error in onMessage, ", err);
// OLAT-3973: don't throw exceptions here
} catch (final RuntimeException runEx) {
log.warn("RuntimeException in onMessage, ", runEx);
// OLAT-3973: don't throw exceptions here
}
}
public MessageDump toDumpMessage(Message msg) throws JMSException{
MessageDump dump = new MessageDump();
dump.JMSCorrelationID = msg.getJMSCorrelationID();
dump.JMSMessageID = msg.getJMSMessageID();
dump.JMSType = msg.getJMSType();
dump.JMSDeliveryMode = msg.getJMSDeliveryMode();
dump.JMSExpiration = msg.getJMSExpiration();
dump.JMSRedelivered = msg.getJMSRedelivered();
dump.JMSTimestamp = msg.getJMSTimestamp();
dump.JMSPriority = msg.getJMSPriority();
@SuppressWarnings("rawtypes")
Enumeration propertyNames = msg.getPropertyNames();
while(propertyNames.hasMoreElements()){
String property = (String) propertyNames.nextElement();
Object propertyValue = msg.getObjectProperty(property);
if( propertyValue instanceof String){
dump.stringProperties.put(property, (String)propertyValue);
} else if ( propertyValue instanceof Integer ){
dump.intProperties.put(property, (Integer)propertyValue);
} else if ( propertyValue instanceof Long) {
dump.longProperties.put(property, (Long)propertyValue);
} else if( propertyValue instanceof Double) {
dump.doubleProperties.put(property, (Double) propertyValue);
} else if (propertyValue instanceof Short) {
dump.shortProperties.put(property, (Short)propertyValue);
} else if (propertyValue instanceof Float) {
dump.floatProperties.put(property, (Float) propertyValue);
} else if (propertyValue instanceof Byte) {
dump.byteProperties.put(property, (Byte)propertyValue);
} else if (propertyValue instanceof Boolean) {
dump.boolProperties.put(property, (Boolean)propertyValue);
} else if (propertyValue instanceof Serializable){
// Object property.. if it's on Classpath and Serializable
byte[] propBytes = SerializationUtils.serialize((Serializable) propertyValue);
dump.objectProperties.put(property, Base64.encodeBase64String(propBytes));
} else {
// Corner case.
throw new IllegalArgumentException("Property of key '"+ property +"' is not serializable. Type is: " + propertyValue.getClass().getCanonicalName());
}
}
dump.body = "";
dump.type = "";
if (msg instanceof TextMessage) {
dump.body = ((TextMessage)msg).getText();
dump.type = "TextMessage";
} else if (msg instanceof BytesMessage) {
BytesMessage bm = (BytesMessage)msg;
byte[] bytes = new byte[(int) bm.getBodyLength()];
bm.readBytes(bytes);
dump.body = Base64.encodeBase64String(bytes);
dump.type = "BytesMessage";
} else if (msg instanceof ObjectMessage) {
ObjectMessage om = (ObjectMessage)msg;
byte[] objectBytes = SerializationUtils.serialize(om.getObject());
dump.body = Base64.encodeBase64String(objectBytes);
dump.type = "ObjectMessage";
}
return dump;
}
public static Map<String, String> createAttributeMap(final Message message) throws JMSException {
final Map<String, String> attributes = new HashMap<>();
final Enumeration<?> enumeration = message.getPropertyNames();
while (enumeration.hasMoreElements()) {
final String propName = (String) enumeration.nextElement();
final Object value = message.getObjectProperty(propName);
if (value == null) {
attributes.put(ATTRIBUTE_PREFIX + propName, "");
attributes.put(ATTRIBUTE_PREFIX + propName + ATTRIBUTE_TYPE_SUFFIX, "Unknown");
continue;
}
final String valueString = value.toString();
attributes.put(ATTRIBUTE_PREFIX + propName, valueString);
final String propType;
if (value instanceof String) {
propType = PROP_TYPE_STRING;
} else if (value instanceof Double) {
propType = PROP_TYPE_DOUBLE;
} else if (value instanceof Float) {
propType = PROP_TYPE_FLOAT;
} else if (value instanceof Long) {
propType = PROP_TYPE_LONG;
} else if (value instanceof Integer) {
propType = PROP_TYPE_INTEGER;
} else if (value instanceof Short) {
propType = PROP_TYPE_SHORT;
} else if (value instanceof Byte) {
propType = PROP_TYPE_BYTE;
} else if (value instanceof Boolean) {
propType = PROP_TYPE_BOOLEAN;
} else {
propType = PROP_TYPE_OBJECT;
}
attributes.put(ATTRIBUTE_PREFIX + propName + ATTRIBUTE_TYPE_SUFFIX, propType);
}
if (message.getJMSCorrelationID() != null) {
attributes.put(ATTRIBUTE_PREFIX + JMS_CORRELATION_ID, message.getJMSCorrelationID());
}
if (message.getJMSDestination() != null) {
String destinationName;
if (message.getJMSDestination() instanceof Queue) {
destinationName = ((Queue) message.getJMSDestination()).getQueueName();
} else {
destinationName = ((Topic) message.getJMSDestination()).getTopicName();
}
attributes.put(ATTRIBUTE_PREFIX + JMS_DESTINATION, destinationName);
}
if (message.getJMSMessageID() != null) {
attributes.put(ATTRIBUTE_PREFIX + JMS_MESSAGE_ID, message.getJMSMessageID());
}
if (message.getJMSReplyTo() != null) {
attributes.put(ATTRIBUTE_PREFIX + JMS_REPLY_TO, message.getJMSReplyTo().toString());
}
if (message.getJMSType() != null) {
attributes.put(ATTRIBUTE_PREFIX + JMS_TYPE, message.getJMSType());
}
attributes.put(ATTRIBUTE_PREFIX + JMS_DELIVERY_MODE, String.valueOf(message.getJMSDeliveryMode()));
attributes.put(ATTRIBUTE_PREFIX + JMS_EXPIRATION, String.valueOf(message.getJMSExpiration()));
attributes.put(ATTRIBUTE_PREFIX + JMS_PRIORITY, String.valueOf(message.getJMSPriority()));
attributes.put(ATTRIBUTE_PREFIX + JMS_REDELIVERED, String.valueOf(message.getJMSRedelivered()));
attributes.put(ATTRIBUTE_PREFIX + JMS_TIMESTAMP, String.valueOf(message.getJMSTimestamp()));
return attributes;
}
/**
* Post-process the given response message before it will be sent.
* <p>The default implementation sets the response's correlation id
* to the request message's correlation id, if any; otherwise to the
* request message id.
* @param request the original incoming JMS message
* @param response the outgoing JMS message about to be sent
* @throws JMSException if thrown by JMS API methods
* @see javax.jms.Message#setJMSCorrelationID
*/
protected void postProcessResponse(Message request, Message response) throws JMSException {
String correlation = request.getJMSCorrelationID();
if (correlation == null) {
correlation = request.getJMSMessageID();
}
response.setJMSCorrelationID(correlation);
}
/**
* Create the invocation result response message.
* <p>The default implementation creates a JMS ObjectMessage for the given
* RemoteInvocationResult object. It sets the response's correlation id
* to the request message's correlation id, if any; otherwise to the
* request message id.
* @param request the original request message
* @param session the JMS session to use
* @param result the invocation result
* @return the message response to send
* @throws javax.jms.JMSException if creating the message failed
*/
protected Message createResponseMessage(Message request, Session session, RemoteInvocationResult result)
throws JMSException {
Message response = this.messageConverter.toMessage(result, session);
String correlation = request.getJMSCorrelationID();
if (correlation == null) {
correlation = request.getJMSMessageID();
}
response.setJMSCorrelationID(correlation);
return response;
}
/**
* Post-process the given response message before it will be sent.
* <p>The default implementation sets the response's correlation id
* to the request message's correlation id, if any; otherwise to the
* request message id.
* @param request the original incoming JMS message
* @param response the outgoing JMS message about to be sent
* @throws JMSException if thrown by JMS API methods
* @see javax.jms.Message#setJMSCorrelationID
*/
protected void postProcessResponse(Message request, Message response) throws JMSException {
String correlation = request.getJMSCorrelationID();
if (correlation == null) {
correlation = request.getJMSMessageID();
}
response.setJMSCorrelationID(correlation);
}
/**
* Create the invocation result response message.
* <p>The default implementation creates a JMS ObjectMessage for the given
* RemoteInvocationResult object. It sets the response's correlation id
* to the request message's correlation id, if any; otherwise to the
* request message id.
* @param request the original request message
* @param session the JMS session to use
* @param result the invocation result
* @return the message response to send
* @throws javax.jms.JMSException if creating the message failed
*/
protected Message createResponseMessage(Message request, Session session, RemoteInvocationResult result)
throws JMSException {
Message response = this.messageConverter.toMessage(result, session);
String correlation = request.getJMSCorrelationID();
if (correlation == null) {
correlation = request.getJMSMessageID();
}
response.setJMSCorrelationID(correlation);
return response;
}
/**
* Post-process the given response message before it will be sent.
* <p>The default implementation sets the response's correlation id
* to the request message's correlation id, if any; otherwise to the
* request message id.
* @param request the original incoming JMS message
* @param response the outgoing JMS message about to be sent
* @throws JMSException if thrown by JMS API methods
* @see javax.jms.Message#setJMSCorrelationID
*/
protected void postProcessResponse(Message request, Message response) throws JMSException {
String correlation = request.getJMSCorrelationID();
if (correlation == null) {
correlation = request.getJMSMessageID();
}
response.setJMSCorrelationID(correlation);
}
/**
* Create the invocation result response message.
* <p>The default implementation creates a JMS ObjectMessage for the given
* RemoteInvocationResult object. It sets the response's correlation id
* to the request message's correlation id, if any; otherwise to the
* request message id.
* @param request the original request message
* @param session the JMS session to use
* @param result the invocation result
* @return the message response to send
* @throws javax.jms.JMSException if creating the messsage failed
*/
protected Message createResponseMessage(Message request, Session session, RemoteInvocationResult result)
throws JMSException {
Message response = this.messageConverter.toMessage(result, session);
String correlation = request.getJMSCorrelationID();
if (correlation == null) {
correlation = request.getJMSMessageID();
}
response.setJMSCorrelationID(correlation);
return response;
}