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);
}
}
use of javax.jms.Message in project spring-framework by spring-projects.
the class JmsListenerContainerFactoryIntegrationTests method parameterAnnotationWithJdkProxy.
@Test
public void parameterAnnotationWithJdkProxy() throws JMSException {
ProxyFactory pf = new ProxyFactory(sample);
listener = (JmsEndpointSampleInterface) pf.getProxy();
containerFactory.setMessageConverter(new UpperCaseMessageConverter());
MethodJmsListenerEndpoint endpoint = createDefaultMethodJmsEndpoint(JmsEndpointSampleInterface.class, "handleIt", String.class, String.class);
Message message = new StubTextMessage("foo-bar");
message.setStringProperty("my-header", "my-value");
invokeListener(endpoint, message);
assertListenerMethodInvocation("handleIt");
}
use of javax.jms.Message in project spring-framework by spring-projects.
the class JmsListenerContainerFactoryIntegrationTests method parameterAnnotationWithCglibProxy.
@Test
public void parameterAnnotationWithCglibProxy() throws JMSException {
ProxyFactory pf = new ProxyFactory(sample);
pf.setProxyTargetClass(true);
listener = (JmsEndpointSampleBean) pf.getProxy();
containerFactory.setMessageConverter(new UpperCaseMessageConverter());
MethodJmsListenerEndpoint endpoint = createDefaultMethodJmsEndpoint(JmsEndpointSampleBean.class, "handleIt", String.class, String.class);
Message message = new StubTextMessage("foo-bar");
message.setStringProperty("my-header", "my-value");
invokeListener(endpoint, message);
assertListenerMethodInvocation("handleIt");
}
Aggregations