use of javax.jms.Message in project spring-framework by spring-projects.
the class JmsInvokerServiceExporter method writeRemoteInvocationResult.
/**
* Send the given RemoteInvocationResult as a JMS message to the originator.
* @param requestMessage current request message
* @param session the JMS Session to use
* @param result the RemoteInvocationResult object
* @throws javax.jms.JMSException if thrown by trying to send the message
*/
protected void writeRemoteInvocationResult(Message requestMessage, Session session, RemoteInvocationResult result) throws JMSException {
Message response = createResponseMessage(requestMessage, session, result);
MessageProducer producer = session.createProducer(requestMessage.getJMSReplyTo());
try {
producer.send(response);
} finally {
JmsUtils.closeMessageProducer(producer);
}
}
use of javax.jms.Message in project spring-framework by spring-projects.
the class MappingJackson2MessageConverter method toMessage.
@Override
public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {
Message message;
try {
switch(this.targetType) {
case TEXT:
message = mapToTextMessage(object, session, this.objectMapper.writer());
break;
case BYTES:
message = mapToBytesMessage(object, session, this.objectMapper.writer());
break;
default:
message = mapToMessage(object, session, this.objectMapper.writer(), this.targetType);
}
} catch (IOException ex) {
throw new MessageConversionException("Could not map JSON object [" + object + "]", ex);
}
setTypeIdOnMessage(object, message);
return message;
}
use of javax.jms.Message in project spring-framework by spring-projects.
the class AbstractAdaptableMessageListener method handleResult.
/**
* Handle the given result object returned from the listener method,
* sending a response message back.
* @param result the result object to handle (never {@code null})
* @param request the original request message
* @param session the JMS Session to operate on (may be {@code null})
* @throws ReplyFailureException if the response message could not be sent
* @see #buildMessage
* @see #postProcessResponse
* @see #getResponseDestination
* @see #sendResponse
*/
protected void handleResult(Object result, Message request, Session session) {
if (session != null) {
if (logger.isDebugEnabled()) {
logger.debug("Listener method returned result [" + result + "] - generating response message for it");
}
try {
Message response = buildMessage(session, result);
postProcessResponse(request, response);
Destination destination = getResponseDestination(request, response, session, result);
sendResponse(session, destination, response);
} catch (Exception ex) {
throw new ReplyFailureException("Failed to send reply with payload [" + result + "]", ex);
}
} else {
// No JMS Session available
if (logger.isWarnEnabled()) {
logger.warn("Listener method returned result [" + result + "]: not generating response message for it because of no JMS Session given");
}
}
}
use of javax.jms.Message in project spring-framework by spring-projects.
the class MappingJackson2MessageConverter method toMessage.
protected Message toMessage(Object object, Session session, ObjectWriter objectWriter) throws JMSException, MessageConversionException {
Message message;
try {
switch(this.targetType) {
case TEXT:
message = mapToTextMessage(object, session, objectWriter);
break;
case BYTES:
message = mapToBytesMessage(object, session, objectWriter);
break;
default:
message = mapToMessage(object, session, objectWriter, this.targetType);
}
} catch (IOException ex) {
throw new MessageConversionException("Could not map JSON object [" + object + "]", ex);
}
setTypeIdOnMessage(object, message);
return message;
}
use of javax.jms.Message in project spring-framework by spring-projects.
the class JmsTemplate method doSend.
/**
* Send the given JMS message.
* @param session the JMS Session to operate on
* @param destination the JMS Destination to send to
* @param messageCreator callback to create a JMS Message
* @throws JMSException if thrown by JMS API methods
*/
protected void doSend(Session session, Destination destination, MessageCreator messageCreator) throws JMSException {
Assert.notNull(messageCreator, "MessageCreator must not be null");
MessageProducer producer = createProducer(session, destination);
try {
Message message = messageCreator.createMessage(session);
if (logger.isDebugEnabled()) {
logger.debug("Sending created message: " + message);
}
doSend(producer, message);
// Check commit - avoid commit call within a JTA transaction.
if (session.getTransacted() && isSessionLocallyTransacted(session)) {
// Transacted session created by this template -> commit.
JmsUtils.commitIfNecessary(session);
}
} finally {
JmsUtils.closeMessageProducer(producer);
}
}
Aggregations