/** * Extract the payload of the specified {@link javax.jms.Message}. */ protected Object extractPayload(javax.jms.Message message) throws JMSException { return this.payloadConverter.fromMessage(message); }
/** * Create the invoker request message. * <p>The default implementation creates a JMS {@link javax.jms.ObjectMessage} * for the given RemoteInvocation object. * @param session the current JMS Session * @param invocation the remote invocation to send * @return the JMS Message to send * @throws JMSException if the message could not be created */ protected Message createRequestMessage(Session session, RemoteInvocation invocation) throws JMSException { return this.messageConverter.toMessage(invocation, session); }
try { if (this.extractRequestPayload) { result = this.messageConverter.fromMessage(jmsMessage); if (this.logger.isDebugEnabled()) { this.logger.debug("converted JMS Message [" + jmsMessage + "] to integration Message payload [" javax.jms.Message jmsReply = this.messageConverter.toMessage(replyResult, session);
/** * Read a RemoteInvocation from the given JMS message. * @param requestMessage current request message * @return the RemoteInvocation object (or {@code null} * in case of an invalid message that will simply be ignored) * @throws javax.jms.JMSException in case of message access failure */ @Nullable protected RemoteInvocation readRemoteInvocation(Message requestMessage) throws JMSException { Object content = this.messageConverter.fromMessage(requestMessage); if (content instanceof RemoteInvocation) { return (RemoteInvocation) content; } return onInvalidRequest(requestMessage); }
/** * Create a JMS message for the specified payload and conversionHint. * The conversion hint is an extra object passed to the {@link MessageConverter}, * e.g. the associated {@code MethodParameter} (may be {@code null}}. * @since 4.3 * @see MessageConverter#toMessage(Object, Session) */ protected javax.jms.Message createMessageForPayload( Object payload, Session session, @Nullable Object conversionHint) throws JMSException { return this.payloadConverter.toMessage(payload, session); }
/** * Extract the invocation result from the response message. * <p>The default implementation expects a JMS {@link javax.jms.ObjectMessage} * carrying a {@link RemoteInvocationResult} object. If an invalid response * message is encountered, the {@code onInvalidResponse} callback gets invoked. * @param responseMessage the response message * @return the invocation result * @throws JMSException is thrown if a JMS exception occurs * @see #onInvalidResponse */ protected RemoteInvocationResult extractInvocationResult(Message responseMessage) throws JMSException { Object content = this.messageConverter.fromMessage(responseMessage); if (content instanceof RemoteInvocationResult) { return (RemoteInvocationResult) content; } return onInvalidResponse(responseMessage); }
@Override public javax.jms.Message createMessage(Session session) throws JMSException { try { return this.messageConverter.toMessage(this.message, session); } catch (Exception ex) { throw new MessageConversionException("Could not convert '" + this.message + "'", ex); } } }
@Nullable protected Message<?> convertJmsMessage(@Nullable javax.jms.Message message) { if (message == null) { return null; } try { return (Message<?>) getJmsMessageConverter().fromMessage(message); } catch (Exception ex) { throw new MessageConversionException("Could not convert '" + message + "'", ex); } }
@Override protected Message createMessageForPayload(Object payload, Session session, @Nullable Object conversionHint) throws JMSException { MessageConverter converter = getMessageConverter(); if (converter == null) { throw new IllegalStateException("No message converter, cannot handle '" + payload + "'"); } if (converter instanceof SmartMessageConverter) { return ((SmartMessageConverter) converter).toMessage(payload, session, conversionHint); } return converter.toMessage(payload, session); }
/** * Extract the content from the given JMS message. * @param message the JMS Message to convert (can be {@code null}) * @return the content of the message, or {@code null} if none */ @Nullable protected Object doConvertFromMessage(@Nullable Message message) { if (message != null) { try { return getRequiredMessageConverter().fromMessage(message); } catch (JMSException ex) { throw convertJmsAccessException(ex); } } return null; }
@Override public void convertAndSend(Destination destination, final Object message) throws JmsException { send(destination, session -> getRequiredMessageConverter().toMessage(message, session)); }
/** * Extract the message body from the given JMS message. * @param message the JMS {@code Message} * @return the content of the message, to be passed into the listener method * as an argument * @throws MessageConversionException if the message could not be extracted */ protected Object extractMessage(Message message) { try { MessageConverter converter = getMessageConverter(); if (converter != null) { return converter.fromMessage(message); } return message; } catch (JMSException ex) { throw new MessageConversionException("Could not convert JMS message", ex); } }
@Override public void convertAndSend(String destinationName, final Object message) throws JmsException { send(destinationName, session -> getRequiredMessageConverter().toMessage(message, session)); }
@Test public void payloadConversionLazilyInvoked() throws JMSException { javax.jms.Message jmsMessage = mock(javax.jms.Message.class); MessageConverter messageConverter = mock(MessageConverter.class); given(messageConverter.fromMessage(jmsMessage)).willReturn("FooBar"); MessagingMessageListenerAdapter listener = getSimpleInstance("simple", Message.class); listener.setMessageConverter(messageConverter); Message<?> message = listener.toMessagingMessage(jmsMessage); verify(messageConverter, never()).fromMessage(jmsMessage); assertEquals("FooBar", message.getPayload()); verify(messageConverter, times(1)).fromMessage(jmsMessage); }
@Override public void convertAndSend( Destination destination, final Object message, final MessagePostProcessor postProcessor) throws JmsException { send(destination, session -> { Message msg = getRequiredMessageConverter().toMessage(message, session); return postProcessor.postProcessMessage(msg); }); }
@Test public void incomingMessageUsesMessageConverter() throws JMSException { javax.jms.Message jmsMessage = mock(javax.jms.Message.class); Session session = mock(Session.class); MessageConverter messageConverter = mock(MessageConverter.class); given(messageConverter.fromMessage(jmsMessage)).willReturn("FooBar"); MessagingMessageListenerAdapter listener = getSimpleInstance("simple", Message.class); listener.setMessageConverter(messageConverter); listener.onMessage(jmsMessage, session); verify(messageConverter, times(1)).fromMessage(jmsMessage); assertEquals(1, sample.simples.size()); assertEquals("FooBar", sample.simples.get(0).getPayload()); }
@Override public void convertAndSend( String destinationName, final Object message, final MessagePostProcessor postProcessor) throws JmsException { send(destinationName, session -> { Message msg = getRequiredMessageConverter().toMessage(message, session); return postProcessor.postProcessMessage(msg); }); }
@Test public void convertMessageConversionExceptionOnReceive() throws JMSException { javax.jms.Message message = createJmsTextMessage(); MessageConverter messageConverter = mock(MessageConverter.class); willThrow(org.springframework.jms.support.converter.MessageConversionException.class) .given(messageConverter).fromMessage(message); this.messagingTemplate.setJmsMessageConverter(messageConverter); given(this.jmsTemplate.receive("myQueue")).willReturn(message); this.thrown.expect(org.springframework.messaging.converter.MessageConversionException.class); this.messagingTemplate.receive("myQueue"); }
/** * 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; }
Log debugLogger = LogFactory.getLog("si.jmsgateway.debug"); if (debugLogger.isDebugEnabled()) { Object siMessage = this.messageConverter.fromMessage(message); debugLogger.debug("No pending reply for " + siMessage + " with correlationId: " + correlationId + " pending replies: " + this.replies.keySet());