Search in sources :

Example 16 with ServiceActivatingHandler

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

the class ExpressionControlBusFactoryBean method createHandler.

@Override
protected MessageHandler createHandler() {
    ExpressionCommandMessageProcessor processor = new ExpressionCommandMessageProcessor(methodFilter, this.getBeanFactory());
    ServiceActivatingHandler handler = new ServiceActivatingHandler(processor);
    if (this.sendTimeout != null) {
        handler.setSendTimeout(this.sendTimeout);
    }
    return handler;
}
Also used : ExpressionCommandMessageProcessor(org.springframework.integration.handler.ExpressionCommandMessageProcessor) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler)

Example 17 with ServiceActivatingHandler

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

the class ChainParserTests method testInt2755SubComponentsIdSupport.

@Test
public void testInt2755SubComponentsIdSupport() {
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1.handler"));
    assertTrue(this.beanFactory.containsBean("filterChain$child.filterWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("filterChain$child.serviceActivatorWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain$child.aggregatorWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain$child.nestedChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain$child.nestedChain$child.filterWithinNestedChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain$child.nestedChain$child.doubleNestedChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain$child.nestedChain$child.doubleNestedChain$child.filterWithinDoubleNestedChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain2.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain2$child.aggregatorWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain2$child.nestedChain.handler"));
    assertTrue(this.beanFactory.containsBean("aggregatorChain2$child.nestedChain$child.filterWithinNestedChain.handler"));
    assertTrue(this.beanFactory.containsBean("payloadTypeRouterChain$child.payloadTypeRouterWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("headerValueRouterChain$child.headerValueRouterWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("chainWithClaimChecks$child.claimCheckInWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("chainWithClaimChecks$child.claimCheckOutWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("outboundChain$child.outboundChannelAdapterWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("logChain$child.transformerWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("logChain$child.loggingChannelAdapterWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.splitterWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.resequencerWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.enricherWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.headerFilterWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.payloadSerializingTransformerWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.payloadDeserializingTransformerWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.gatewayWithinChain.handler"));
    // INT-3117
    GatewayProxyFactoryBean gatewayProxyFactoryBean = this.beanFactory.getBean("&subComponentsIdSupport1$child.gatewayWithinChain.handler", GatewayProxyFactoryBean.class);
    assertEquals("strings", TestUtils.getPropertyValue(gatewayProxyFactoryBean, "defaultRequestChannelName"));
    assertEquals("numbers", TestUtils.getPropertyValue(gatewayProxyFactoryBean, "defaultReplyChannelName"));
    assertEquals(1000L, TestUtils.getPropertyValue(gatewayProxyFactoryBean, "defaultRequestTimeout", Expression.class).getValue());
    assertEquals(100L, TestUtils.getPropertyValue(gatewayProxyFactoryBean, "defaultReplyTimeout", Expression.class).getValue());
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.objectToStringTransformerWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.objectToMapTransformerWithinChain.handler"));
    Object transformerHandler = this.beanFactory.getBean("subComponentsIdSupport1$child.objectToMapTransformerWithinChain.handler");
    Object transformer = TestUtils.getPropertyValue(transformerHandler, "transformer");
    assertThat(transformer, instanceOf(ObjectToMapTransformer.class));
    assertFalse(TestUtils.getPropertyValue(transformer, "shouldFlattenKeys", Boolean.class));
    assertSame(this.beanFactory.getBean(JsonObjectMapper.class), TestUtils.getPropertyValue(transformer, "jsonObjectMapper"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.mapToObjectTransformerWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.controlBusWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("subComponentsIdSupport1$child.routerWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("exceptionTypeRouterChain$child.exceptionTypeRouterWithinChain.handler"));
    assertTrue(this.beanFactory.containsBean("recipientListRouterChain$child.recipientListRouterWithinChain.handler"));
    MessageHandlerChain chain = this.beanFactory.getBean("headerEnricherChain.handler", MessageHandlerChain.class);
    List<?> handlers = TestUtils.getPropertyValue(chain, "handlers", List.class);
    assertTrue(handlers.get(0) instanceof MessageTransformingHandler);
    assertEquals("headerEnricherChain$child.headerEnricherWithinChain", TestUtils.getPropertyValue(handlers.get(0), "componentName"));
    assertEquals("headerEnricherChain$child.headerEnricherWithinChain.handler", TestUtils.getPropertyValue(handlers.get(0), "beanName"));
    assertTrue(this.beanFactory.containsBean("headerEnricherChain$child.headerEnricherWithinChain.handler"));
    assertTrue(handlers.get(1) instanceof ServiceActivatingHandler);
    assertEquals("headerEnricherChain$child#1", TestUtils.getPropertyValue(handlers.get(1), "componentName"));
    assertEquals("headerEnricherChain$child#1.handler", TestUtils.getPropertyValue(handlers.get(1), "beanName"));
    assertFalse(this.beanFactory.containsBean("headerEnricherChain$child#1.handler"));
}
Also used : GatewayProxyFactoryBean(org.springframework.integration.gateway.GatewayProxyFactoryBean) MessageTransformingHandler(org.springframework.integration.transformer.MessageTransformingHandler) MessageHandlerChain(org.springframework.integration.handler.MessageHandlerChain) ObjectToMapTransformer(org.springframework.integration.transformer.ObjectToMapTransformer) JsonObjectMapper(org.springframework.integration.support.json.JsonObjectMapper) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 18 with ServiceActivatingHandler

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

the class BeanFactoryTypeConverterTests method testMapOfMapOfCollectionIsConverted.

@SuppressWarnings("unchecked")
@Test
public void testMapOfMapOfCollectionIsConverted() {
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    DefaultConversionService conversionService = new DefaultConversionService();
    conversionService.addConverter(new Converter<Foo, Bar>() {

        @Override
        public Bar convert(Foo source) {
            return new Bar();
        }
    });
    BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter(conversionService);
    beanFactory.setConversionService(conversionService);
    typeConverter.setBeanFactory(beanFactory);
    Map<String, Map<String, Set<Foo>>> foos;
    Map<String, Map<String, Set<Bar>>> bars;
    TypeDescriptor sourceType = TypeDescriptor.map(Map.class, null, null);
    TypeDescriptor targetType = TypeDescriptor.map(Map.class, TypeDescriptor.valueOf(String.class), TypeDescriptor.map(Map.class, TypeDescriptor.valueOf(String.class), TypeDescriptor.collection(Set.class, TypeDescriptor.valueOf(Bar.class))));
    Set<Foo> fooSet = new HashSet<Foo>();
    fooSet.add(new Foo());
    Map<String, Set<Foo>> fooMap = new HashMap<String, Set<Foo>>();
    fooMap.put("foo", fooSet);
    foos = new HashMap<String, Map<String, Set<Foo>>>();
    foos.put("foo", fooMap);
    bars = (Map<String, Map<String, Set<Bar>>>) typeConverter.convertValue(foos, sourceType, targetType);
    assertThat(bars.get("foo").get("foo").iterator().next(), instanceOf(Bar.class));
    Service service = new Service();
    MethodInvokingMessageProcessor<Service> processor = new MethodInvokingMessageProcessor<>(service, "handle");
    processor.setConversionService(conversionService);
    processor.setUseSpelInvoker(true);
    ServiceActivatingHandler handler = new ServiceActivatingHandler(processor);
    QueueChannel replyChannel = new QueueChannel();
    handler.setOutputChannel(replyChannel);
    handler.handleMessage(new GenericMessage<Map<String, Map<String, Set<Foo>>>>(foos));
    Message<?> message = replyChannel.receive(0);
    assertNotNull(message);
    assertEquals("bar", message.getPayload());
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) QueueChannel(org.springframework.integration.channel.QueueChannel) HashMap(java.util.HashMap) HashSet(java.util.HashSet) MethodInvokingMessageProcessor(org.springframework.integration.handler.MethodInvokingMessageProcessor) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ConversionService(org.springframework.core.convert.ConversionService) ExecutorService(java.util.concurrent.ExecutorService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) HashMap(java.util.HashMap) Map(java.util.Map) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 19 with ServiceActivatingHandler

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

the class BeanFactoryTypeConverterTests method testCollectionIsConverted.

@Test
public void testCollectionIsConverted() {
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    DefaultConversionService conversionService = new DefaultConversionService();
    conversionService.addConverter(new Converter<Foo, Bar>() {

        @Override
        public Bar convert(Foo source) {
            return new Bar();
        }
    });
    BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter(conversionService);
    beanFactory.setConversionService(conversionService);
    typeConverter.setBeanFactory(beanFactory);
    Service service = new Service();
    MethodInvokingMessageProcessor<Service> processor = new MethodInvokingMessageProcessor<>(service, "handle");
    processor.setConversionService(conversionService);
    processor.setUseSpelInvoker(true);
    ServiceActivatingHandler handler = new ServiceActivatingHandler(processor);
    QueueChannel replyChannel = new QueueChannel();
    handler.setOutputChannel(replyChannel);
    handler.handleMessage(new GenericMessage<Collection<Foo>>(Collections.singletonList(new Foo())));
    Message<?> message = replyChannel.receive(10000);
    assertNotNull(message);
    assertEquals("baz", message.getPayload());
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) MethodInvokingMessageProcessor(org.springframework.integration.handler.MethodInvokingMessageProcessor) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ConversionService(org.springframework.core.convert.ConversionService) ExecutorService(java.util.concurrent.ExecutorService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) DefaultConversionService(org.springframework.core.convert.support.DefaultConversionService) Collection(java.util.Collection) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 20 with ServiceActivatingHandler

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

the class TcpInboundGatewayTests method testNioSingle.

@Test
public void testNioSingle() throws Exception {
    AbstractServerConnectionFactory scf = new TcpNioServerConnectionFactory(0);
    scf.setSingleUse(true);
    TcpInboundGateway gateway = new TcpInboundGateway();
    gateway.setConnectionFactory(scf);
    scf.start();
    TestingUtilities.waitListening(scf, 20000L);
    int port = scf.getPort();
    final QueueChannel channel = new QueueChannel();
    gateway.setRequestChannel(channel);
    gateway.setBeanFactory(mock(BeanFactory.class));
    ServiceActivatingHandler handler = new ServiceActivatingHandler(new Service());
    handler.setChannelResolver(channelName -> channel);
    Socket socket1 = SocketFactory.getDefault().createSocket("localhost", port);
    socket1.getOutputStream().write("Test1\r\n".getBytes());
    Socket socket2 = SocketFactory.getDefault().createSocket("localhost", port);
    socket2.getOutputStream().write("Test2\r\n".getBytes());
    handler.handleMessage(channel.receive(10000));
    handler.handleMessage(channel.receive(10000));
    byte[] bytes = new byte[12];
    readFully(socket1.getInputStream(), bytes);
    assertEquals("Echo:Test1\r\n", new String(bytes));
    readFully(socket2.getInputStream(), bytes);
    assertEquals("Echo:Test2\r\n", new String(bytes));
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) TcpNioServerConnectionFactory(org.springframework.integration.ip.tcp.connection.TcpNioServerConnectionFactory) AbstractServerConnectionFactory(org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Aggregations

ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)45 Test (org.junit.Test)38 QueueChannel (org.springframework.integration.channel.QueueChannel)29 BeanFactory (org.springframework.beans.factory.BeanFactory)10 DirectChannel (org.springframework.integration.channel.DirectChannel)10 GenericMessage (org.springframework.messaging.support.GenericMessage)10 Message (org.springframework.messaging.Message)8 ServerSocket (java.net.ServerSocket)7 Socket (java.net.Socket)7 IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)6 AbstractServerConnectionFactory (org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory)6 RequestReplyExchanger (org.springframework.integration.gateway.RequestReplyExchanger)5 Date (java.util.Date)4 TcpNetServerConnectionFactory (org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory)4 PollableChannel (org.springframework.messaging.PollableChannel)4 IOException (java.io.IOException)3 PublishSubscribeChannel (org.springframework.integration.channel.PublishSubscribeChannel)3 TestUtils (org.springframework.integration.test.util.TestUtils)3 SubscribableChannel (org.springframework.messaging.SubscribableChannel)3 HashMap (java.util.HashMap)2