Search in sources :

Example 66 with IntegrationMessageHeaderAccessor

use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.

the class JmsOutboundGateway method sendAndReceiveWithoutContainer.

private javax.jms.Message sendAndReceiveWithoutContainer(Message<?> requestMessage) throws JMSException {
    // NOSONAR - closed in ConnectionFactoryUtils.
    Connection connection = this.createConnection();
    Session session = null;
    Destination replyTo = null;
    try {
        session = this.createSession(connection);
        // convert to JMS Message
        Object objectToSend = requestMessage;
        if (this.extractRequestPayload) {
            objectToSend = requestMessage.getPayload();
        }
        javax.jms.Message jmsRequest = this.messageConverter.toMessage(objectToSend, session);
        // map headers
        this.headerMapper.fromHeaders(requestMessage.getHeaders(), jmsRequest);
        replyTo = this.determineReplyDestination(requestMessage, session);
        jmsRequest.setJMSReplyTo(replyTo);
        connection.start();
        if (logger.isDebugEnabled()) {
            logger.debug("ReplyTo: " + replyTo);
        }
        Integer priority = new IntegrationMessageHeaderAccessor(requestMessage).getPriority();
        if (priority == null) {
            priority = this.priority;
        }
        javax.jms.Message replyMessage = null;
        Destination requestDestination = this.determineRequestDestination(requestMessage, session);
        if (this.correlationKey != null) {
            replyMessage = doSendAndReceiveWithGeneratedCorrelationId(requestDestination, jmsRequest, replyTo, session, priority);
        } else if (replyTo instanceof TemporaryQueue || replyTo instanceof TemporaryTopic) {
            replyMessage = doSendAndReceiveWithTemporaryReplyToDestination(requestDestination, jmsRequest, replyTo, session, priority);
        } else {
            replyMessage = doSendAndReceiveWithMessageIdCorrelation(requestDestination, jmsRequest, replyTo, session, priority);
        }
        return replyMessage;
    } finally {
        JmsUtils.closeSession(session);
        this.deleteDestinationIfTemporary(replyTo);
        ConnectionFactoryUtils.releaseConnection(connection, this.connectionFactory, true);
    }
}
Also used : Destination(javax.jms.Destination) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) Connection(javax.jms.Connection) TemporaryQueue(javax.jms.TemporaryQueue) Session(javax.jms.Session) TemporaryTopic(javax.jms.TemporaryTopic)

Example 67 with IntegrationMessageHeaderAccessor

use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.

the class XPathMessageSplitterTests method splitDocumentWithCreateDocumentsTrue.

@Test
public void splitDocumentWithCreateDocumentsTrue() throws Exception {
    this.splitter.setCreateDocuments(true);
    Document doc = XmlTestUtil.getDocumentForString("<orders><order>one</order><order>two</order><order>three</order></orders>");
    this.splitter.handleMessage(new GenericMessage<>(doc));
    List<Message<?>> docMessages = this.replyChannel.clear();
    assertEquals("Wrong number of messages", 3, docMessages.size());
    for (Message<?> message : docMessages) {
        assertThat(message.getPayload(), instanceOf(Document.class));
        Document docPayload = (Document) message.getPayload();
        assertEquals("Wrong root element name", "order", docPayload.getDocumentElement().getLocalName());
        assertThat(new IntegrationMessageHeaderAccessor(message).getSequenceSize(), greaterThan(0));
    }
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 68 with IntegrationMessageHeaderAccessor

use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.

the class XPathMessageSplitterTests method splitDocument.

@Test
public void splitDocument() throws Exception {
    Document doc = XmlTestUtil.getDocumentForString("<orders><order>one</order><order>two</order><order>three</order></orders>");
    this.splitter.handleMessage(new GenericMessage<>(doc));
    List<Message<?>> docMessages = this.replyChannel.clear();
    assertEquals("Wrong number of messages", 3, docMessages.size());
    for (Message<?> message : docMessages) {
        assertThat(message.getPayload(), instanceOf(Node.class));
        assertThat(message.getPayload(), not(instanceOf(Document.class)));
        assertThat(new IntegrationMessageHeaderAccessor(message).getSequenceSize(), greaterThan(0));
    }
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) Node(org.w3c.dom.Node) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)68 Test (org.junit.Test)56 QueueChannel (org.springframework.integration.channel.QueueChannel)32 Message (org.springframework.messaging.Message)21 GenericMessage (org.springframework.messaging.support.GenericMessage)19 MessageChannel (org.springframework.messaging.MessageChannel)15 ArrayList (java.util.ArrayList)10 MessagingTemplate (org.springframework.integration.core.MessagingTemplate)9 DirectChannel (org.springframework.integration.channel.DirectChannel)8 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)6 List (java.util.List)5 BeanFactory (org.springframework.beans.factory.BeanFactory)5 MessageSequenceComparator (org.springframework.integration.aggregator.MessageSequenceComparator)4 Aggregator (org.springframework.integration.annotation.Aggregator)4 InputStream (java.io.InputStream)3 LinkedList (java.util.LinkedList)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)3 MessageGroup (org.springframework.integration.store.MessageGroup)3 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)3