Search in sources :

Example 1 with GatewayProxyFactoryBean

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

the class IntegrationGraphServer method gateways.

private void gateways(Collection<IntegrationNode> nodes, Collection<LinkNode> links, Map<String, MessageChannelNode> channelNodes) {
    Map<String, MessagingGatewaySupport> gateways = this.applicationContext.getBeansOfType(MessagingGatewaySupport.class);
    for (Entry<String, MessagingGatewaySupport> entry : gateways.entrySet()) {
        MessagingGatewaySupport gateway = entry.getValue();
        MessageGatewayNode gatewayNode = this.nodeFactory.gatewayNode(entry.getKey(), gateway);
        nodes.add(gatewayNode);
        producerLink(links, channelNodes, gatewayNode);
    }
    Map<String, GatewayProxyFactoryBean> gpfbs = this.applicationContext.getBeansOfType(GatewayProxyFactoryBean.class);
    for (Entry<String, GatewayProxyFactoryBean> entry : gpfbs.entrySet()) {
        Map<Method, MessagingGatewaySupport> methodMap = entry.getValue().getGateways();
        for (Entry<Method, MessagingGatewaySupport> gwEntry : methodMap.entrySet()) {
            MessagingGatewaySupport gateway = gwEntry.getValue();
            Method method = gwEntry.getKey();
            Class<?>[] parameterTypes = method.getParameterTypes();
            String[] parameterTypeNames = new String[parameterTypes.length];
            int i = 0;
            for (Class<?> type : parameterTypes) {
                parameterTypeNames[i++] = type.getName();
            }
            String signature = method.getName() + "(" + StringUtils.arrayToCommaDelimitedString(parameterTypeNames) + ")";
            MessageGatewayNode gatewayNode = this.nodeFactory.gatewayNode(entry.getKey().substring(1) + "." + signature, gateway);
            nodes.add(gatewayNode);
            producerLink(links, channelNodes, gatewayNode);
        }
    }
}
Also used : GatewayProxyFactoryBean(org.springframework.integration.gateway.GatewayProxyFactoryBean) MessagingGatewaySupport(org.springframework.integration.gateway.MessagingGatewaySupport) Method(java.lang.reflect.Method)

Example 2 with GatewayProxyFactoryBean

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

the class IntegrationFlows method from.

/**
 * Populate the {@link MessageChannel} to the new {@link IntegrationFlowBuilder}
 * chain, which becomes as a {@code requestChannel} for the Messaging Gateway(s) built
 * on the provided service interface.
 * <p>A gateway proxy bean for provided service interface is registered under a name of
 * the provided {@code beanName} if not null, or from the
 * {@link org.springframework.integration.annotation.MessagingGateway#name()} if present
 * or as a fallback to the {@link IntegrationFlow} bean name plus {@code .gateway} suffix.
 * @param serviceInterface the service interface class with an optional
 * {@link org.springframework.integration.annotation.MessagingGateway} annotation.
 * @param beanName the bean name to be used for registering bean for the gateway proxy
 * @return new {@link IntegrationFlowBuilder}.
 */
public static IntegrationFlowBuilder from(Class<?> serviceInterface, String beanName) {
    final DirectChannel gatewayRequestChannel = new DirectChannel();
    GatewayProxyFactoryBean gatewayProxyFactoryBean = new AnnotationGatewayProxyFactoryBean(serviceInterface);
    gatewayProxyFactoryBean.setDefaultRequestChannel(gatewayRequestChannel);
    gatewayProxyFactoryBean.setBeanName(beanName);
    return from(gatewayRequestChannel).addComponent(gatewayProxyFactoryBean);
}
Also used : GatewayProxyFactoryBean(org.springframework.integration.gateway.GatewayProxyFactoryBean) AnnotationGatewayProxyFactoryBean(org.springframework.integration.gateway.AnnotationGatewayProxyFactoryBean) DirectChannel(org.springframework.integration.channel.DirectChannel) AnnotationGatewayProxyFactoryBean(org.springframework.integration.gateway.AnnotationGatewayProxyFactoryBean)

Example 3 with GatewayProxyFactoryBean

use of org.springframework.integration.gateway.GatewayProxyFactoryBean 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 4 with GatewayProxyFactoryBean

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

the class GatewayParserTests method testOneWayOverride.

@Test
public void testOneWayOverride() {
    TestService service = (TestService) context.getBean("methodOverride");
    service.oneWay("foo");
    PollableChannel channel = (PollableChannel) context.getBean("otherRequestChannel");
    Message<?> result = channel.receive(10000);
    assertNotNull(result);
    assertEquals("fiz", result.getPayload());
    assertEquals("bar", result.getHeaders().get("foo"));
    assertEquals("qux", result.getHeaders().get("baz"));
    GatewayProxyFactoryBean fb = context.getBean("&methodOverride", GatewayProxyFactoryBean.class);
    assertEquals(1000L, TestUtils.getPropertyValue(fb, "defaultRequestTimeout", Expression.class).getValue());
    assertEquals(2000L, TestUtils.getPropertyValue(fb, "defaultReplyTimeout", Expression.class).getValue());
    Map<?, ?> methods = TestUtils.getPropertyValue(fb, "methodMetadataMap", Map.class);
    GatewayMethodMetadata meta = (GatewayMethodMetadata) methods.get("oneWay");
    assertNotNull(meta);
    assertEquals("456", meta.getRequestTimeout());
    assertEquals("123", meta.getReplyTimeout());
    assertEquals("foo", meta.getReplyChannelName());
    meta = (GatewayMethodMetadata) methods.get("oneWayWithTimeouts");
    assertNotNull(meta);
    assertEquals("#args[1]", meta.getRequestTimeout());
    assertEquals("#args[2]", meta.getReplyTimeout());
    service.oneWayWithTimeouts("foo", 100L, 200L);
    result = channel.receive(10000);
    assertNotNull(result);
}
Also used : GatewayProxyFactoryBean(org.springframework.integration.gateway.GatewayProxyFactoryBean) TestService(org.springframework.integration.gateway.TestService) PollableChannel(org.springframework.messaging.PollableChannel) GatewayMethodMetadata(org.springframework.integration.gateway.GatewayMethodMetadata) Test(org.junit.Test)

Example 5 with GatewayProxyFactoryBean

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

the class MethodInvokingMessageProcessorTests method gatewayTest.

@Test
public void gatewayTest() throws Exception {
    GatewayProxyFactoryBean gwFactoryBean = new GatewayProxyFactoryBean();
    gwFactoryBean.setBeanFactory(mock(BeanFactory.class));
    gwFactoryBean.afterPropertiesSet();
    Object target = gwFactoryBean.getObject();
    // just instantiate a helper with a simple target; we're going to invoke getTargetClass with reflection
    MessagingMethodInvokerHelper helper = new MessagingMethodInvokerHelper(new TestErrorService(), "error", true);
    Method method = MessagingMethodInvokerHelper.class.getDeclaredMethod("getTargetClass", Object.class);
    method.setAccessible(true);
    Object result = method.invoke(helper, target);
    assertSame(RequestReplyExchanger.class, result);
}
Also used : MessagingMethodInvokerHelper(org.springframework.integration.handler.support.MessagingMethodInvokerHelper) GatewayProxyFactoryBean(org.springframework.integration.gateway.GatewayProxyFactoryBean) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) BeanFactory(org.springframework.beans.factory.BeanFactory) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

GatewayProxyFactoryBean (org.springframework.integration.gateway.GatewayProxyFactoryBean)7 Test (org.junit.Test)5 BeanFactory (org.springframework.beans.factory.BeanFactory)3 DirectChannel (org.springframework.integration.channel.DirectChannel)3 Method (java.lang.reflect.Method)2 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1 AnnotationGatewayProxyFactoryBean (org.springframework.integration.gateway.AnnotationGatewayProxyFactoryBean)1 GatewayMethodMetadata (org.springframework.integration.gateway.GatewayMethodMetadata)1 MessagingGatewaySupport (org.springframework.integration.gateway.MessagingGatewaySupport)1 TestService (org.springframework.integration.gateway.TestService)1 MessageHandlerChain (org.springframework.integration.handler.MessageHandlerChain)1 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)1 MessagingMethodInvokerHelper (org.springframework.integration.handler.support.MessagingMethodInvokerHelper)1 JsonObjectMapper (org.springframework.integration.support.json.JsonObjectMapper)1 MessageTransformingHandler (org.springframework.integration.transformer.MessageTransformingHandler)1 ObjectToMapTransformer (org.springframework.integration.transformer.ObjectToMapTransformer)1 MessagingException (org.springframework.messaging.MessagingException)1