Search in sources :

Example 1 with JmsOutboundGateway

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

the class JmsOutboundGatewayParserTests method testAdvised.

@Test
public void testAdvised() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsOutboundGatewayWithDeliveryPersistent.xml", this.getClass());
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("advised");
    JmsOutboundGateway gateway = TestUtils.getPropertyValue(endpoint, "handler", JmsOutboundGateway.class);
    assertFalse(TestUtils.getPropertyValue(gateway, "async", Boolean.class));
    gateway.handleMessage(new GenericMessage<String>("foo"));
    assertEquals(1, adviceCalled);
    assertEquals(3, TestUtils.getPropertyValue(gateway, "replyContainer.sessionAcknowledgeMode"));
    context.close();
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) JmsOutboundGateway(org.springframework.integration.jms.JmsOutboundGateway) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 2 with JmsOutboundGateway

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

the class JmsOutboundGatewayParserTests method gatewayWithDestExpression.

@Test
public void gatewayWithDestExpression() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsOutboundGatewayReplyDestOptions.xml", this.getClass());
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("jmsGatewayDestExpression");
    DirectFieldAccessor accessor = new DirectFieldAccessor(endpoint);
    JmsOutboundGateway gateway = (JmsOutboundGateway) accessor.getPropertyValue("handler");
    ExpressionEvaluatingMessageProcessor<?> processor = TestUtils.getPropertyValue(gateway, "replyDestinationExpressionProcessor", ExpressionEvaluatingMessageProcessor.class);
    Expression expression = TestUtils.getPropertyValue(gateway, "replyDestinationExpressionProcessor.expression", Expression.class);
    assertEquals("payload", expression.getExpressionString());
    Message<?> message = MessageBuilder.withPayload("foo").build();
    assertEquals("foo", processor.processMessage(message));
    Method method = JmsOutboundGateway.class.getDeclaredMethod("determineReplyDestination", Message.class, Session.class);
    method.setAccessible(true);
    Session session = mock(Session.class);
    Queue queue = mock(Queue.class);
    when(session.createQueue("foo")).thenReturn(queue);
    Destination replyQ = (Destination) method.invoke(gateway, message, session);
    assertSame(queue, replyQ);
    context.close();
}
Also used : Destination(javax.jms.Destination) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Expression(org.springframework.expression.Expression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) JmsOutboundGateway(org.springframework.integration.jms.JmsOutboundGateway) Method(java.lang.reflect.Method) Queue(javax.jms.Queue) Session(javax.jms.Session) Test(org.junit.Test)

Example 3 with JmsOutboundGateway

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

the class RequestReplyScenariosWithCorrelationKeyProvidedTests method messageCorrelationBasedCustomCorrelationKeyDelayedReplies.

@Test
public void messageCorrelationBasedCustomCorrelationKeyDelayedReplies() throws Exception {
    ActiveMqTestUtils.prepare();
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("explicit-correlation-key.xml", this.getClass());
    RequestReplyExchanger gateway = context.getBean("explicitCorrelationKeyGatewayC", RequestReplyExchanger.class);
    for (int i = 0; i < 3; i++) {
        try {
            gateway.exchange(MessageBuilder.withPayload("hello").build());
        } catch (Exception e) {
        // ignore
        }
    }
    JmsOutboundGateway outGateway = TestUtils.getPropertyValue(context.getBean("outGateway"), "handler", JmsOutboundGateway.class);
    outGateway.setReceiveTimeout(5000);
    assertEquals("foo", gateway.exchange(MessageBuilder.withPayload("foo").build()).getPayload());
    context.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) RequestReplyExchanger(org.springframework.integration.gateway.RequestReplyExchanger) JmsOutboundGateway(org.springframework.integration.jms.JmsOutboundGateway) LongRunningIntegrationTest(org.springframework.integration.test.support.LongRunningIntegrationTest) Test(org.junit.Test)

Example 4 with JmsOutboundGateway

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

the class JmsOutboundGatewayParserTests method gatewayMaintainsReplyChannelAndInboundHistory.

@Test
public void gatewayMaintainsReplyChannelAndInboundHistory() {
    ActiveMqTestUtils.prepare();
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("gatewayMaintainsReplyChannel.xml", this.getClass());
    SampleGateway gateway = context.getBean("gateway", SampleGateway.class);
    SubscribableChannel jmsInput = context.getBean("jmsInput", SubscribableChannel.class);
    MessageHandler handler = message -> {
        MessageHistory history = MessageHistory.read(message);
        assertNotNull(history);
        Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "inboundGateway", 0);
        assertNotNull(componentHistoryRecord);
        assertEquals("jms:inbound-gateway", componentHistoryRecord.get("type"));
        MessagingTemplate messagingTemplate = new MessagingTemplate();
        messagingTemplate.setDefaultDestination((MessageChannel) message.getHeaders().getReplyChannel());
        messagingTemplate.send(message);
    };
    jmsInput.subscribe(handler);
    String result = gateway.echo("hello");
    assertEquals("hello", result);
    JmsOutboundGateway gw1 = context.getBean("chain1$child.gateway.handler", JmsOutboundGateway.class);
    MessageChannel out = TestUtils.getPropertyValue(gw1, "outputChannel", MessageChannel.class);
    assertThat(out.getClass().getSimpleName(), equalTo("ReplyForwardingMessageChannel"));
    JmsOutboundGateway gw2 = context.getBean("chain2$child.gateway.handler", JmsOutboundGateway.class);
    out = TestUtils.getPropertyValue(gw2, "outputChannel", MessageChannel.class);
    assertThat(out.getClass().getName(), containsString("MessageHandlerChain$"));
    context.close();
}
Also used : DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) AbstractRequestHandlerAdvice(org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice) SubscribableChannel(org.springframework.messaging.SubscribableChannel) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) TestUtils(org.springframework.integration.test.util.TestUtils) MessagingTemplate(org.springframework.integration.core.MessagingTemplate) Assert.assertSame(org.junit.Assert.assertSame) Assert.assertThat(org.junit.Assert.assertThat) MessageBuilder(org.springframework.integration.support.MessageBuilder) Session(javax.jms.Session) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageHistory(org.springframework.integration.history.MessageHistory) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Assert.fail(org.junit.Assert.fail) Message(org.springframework.messaging.Message) JmsOutboundGateway(org.springframework.integration.jms.JmsOutboundGateway) Method(java.lang.reflect.Method) DeliveryMode(javax.jms.DeliveryMode) Properties(java.util.Properties) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) MessageChannel(org.springframework.messaging.MessageChannel) ExpressionEvaluatingMessageProcessor(org.springframework.integration.handler.ExpressionEvaluatingMessageProcessor) Queue(javax.jms.Queue) BeanDefinitionParsingException(org.springframework.beans.factory.parsing.BeanDefinitionParsingException) Destination(javax.jms.Destination) MessageHandler(org.springframework.messaging.MessageHandler) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Expression(org.springframework.expression.Expression) MessageConverter(org.springframework.jms.support.converter.MessageConverter) GenericMessage(org.springframework.messaging.support.GenericMessage) Matchers.containsString(org.hamcrest.Matchers.containsString) NotReadablePropertyException(org.springframework.beans.NotReadablePropertyException) Assert.assertEquals(org.junit.Assert.assertEquals) StubMessageConverter(org.springframework.integration.jms.StubMessageConverter) Mockito.mock(org.mockito.Mockito.mock) MessageHistory(org.springframework.integration.history.MessageHistory) MessagingTemplate(org.springframework.integration.core.MessagingTemplate) MessageHandler(org.springframework.messaging.MessageHandler) MessageChannel(org.springframework.messaging.MessageChannel) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) JmsOutboundGateway(org.springframework.integration.jms.JmsOutboundGateway) Matchers.containsString(org.hamcrest.Matchers.containsString) Properties(java.util.Properties) SubscribableChannel(org.springframework.messaging.SubscribableChannel) Test(org.junit.Test)

Example 5 with JmsOutboundGateway

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

the class JmsOutboundGatewayParserTests method testDefault.

@Test
public void testDefault() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsOutboundGatewayWithConverter.xml", this.getClass());
    PollingConsumer endpoint = (PollingConsumer) context.getBean("jmsGateway");
    DirectFieldAccessor accessor = new DirectFieldAccessor(endpoint);
    JmsOutboundGateway gateway = (JmsOutboundGateway) accessor.getPropertyValue("handler");
    accessor = new DirectFieldAccessor(gateway);
    MessageConverter converter = (MessageConverter) accessor.getPropertyValue("messageConverter");
    assertTrue("Wrong message converter", converter instanceof StubMessageConverter);
    context.close();
}
Also used : PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) StubMessageConverter(org.springframework.integration.jms.StubMessageConverter) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) JmsOutboundGateway(org.springframework.integration.jms.JmsOutboundGateway) MessageConverter(org.springframework.jms.support.converter.MessageConverter) StubMessageConverter(org.springframework.integration.jms.StubMessageConverter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)9 JmsOutboundGateway (org.springframework.integration.jms.JmsOutboundGateway)9 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)7 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)7 Expression (org.springframework.expression.Expression)3 Method (java.lang.reflect.Method)2 Destination (javax.jms.Destination)2 Queue (javax.jms.Queue)2 Session (javax.jms.Session)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 NotReadablePropertyException (org.springframework.beans.NotReadablePropertyException)2 PollingConsumer (org.springframework.integration.endpoint.PollingConsumer)2 StubMessageConverter (org.springframework.integration.jms.StubMessageConverter)2 DefaultMessageListenerContainer (org.springframework.jms.listener.DefaultMessageListenerContainer)2 MessageConverter (org.springframework.jms.support.converter.MessageConverter)2 Properties (java.util.Properties)1 DeliveryMode (javax.jms.DeliveryMode)1 Matchers.equalTo (org.hamcrest.Matchers.equalTo)1 Assert.assertEquals (org.junit.Assert.assertEquals)1