Search in sources :

Example 16 with AbstractEndpoint

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

the class WebServiceOutboundGatewayParserTests method marshallingGatewayWithSeparateMarshallerAndUnmarshaller.

@Test
public void marshallingGatewayWithSeparateMarshallerAndUnmarshaller() {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("marshallingWebServiceOutboundGatewayParserTests.xml", this.getClass());
    AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithSeparateMarshallerAndUnmarshaller");
    assertEquals(EventDrivenConsumer.class, endpoint.getClass());
    Object gateway = TestUtils.getPropertyValue(endpoint, "handler");
    Marshaller marshaller = context.getBean("marshaller", Marshaller.class);
    Unmarshaller unmarshaller = context.getBean("unmarshaller", Unmarshaller.class);
    assertSame(marshaller, TestUtils.getPropertyValue(gateway, "webServiceTemplate.marshaller", Marshaller.class));
    assertSame(unmarshaller, TestUtils.getPropertyValue(gateway, "webServiceTemplate.unmarshaller", Unmarshaller.class));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) Marshaller(org.springframework.oxm.Marshaller) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Unmarshaller(org.springframework.oxm.Unmarshaller) Test(org.junit.Test)

Example 17 with AbstractEndpoint

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

the class WebServiceOutboundGatewayParserTests method marshallingGatewayWithCustomRequestCallback.

@Test
public void marshallingGatewayWithCustomRequestCallback() {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("marshallingWebServiceOutboundGatewayParserTests.xml", this.getClass());
    AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithCustomRequestCallback");
    assertEquals(EventDrivenConsumer.class, endpoint.getClass());
    Object gateway = TestUtils.getPropertyValue(endpoint, "handler");
    assertEquals(MarshallingWebServiceOutboundGateway.class, gateway.getClass());
    DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
    WebServiceMessageCallback callback = (WebServiceMessageCallback) context.getBean("requestCallback");
    assertEquals(callback, accessor.getPropertyValue("requestCallback"));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) WebServiceMessageCallback(org.springframework.ws.client.core.WebServiceMessageCallback) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 18 with AbstractEndpoint

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

the class WebServiceOutboundGatewayParserTests method simpleGatewayWithCustomInterceptor.

@Test
public void simpleGatewayWithCustomInterceptor() {
    AbstractEndpoint endpoint = this.context.getBean("gatewayWithCustomInterceptor", AbstractEndpoint.class);
    assertEquals(EventDrivenConsumer.class, endpoint.getClass());
    Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler");
    assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass());
    DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
    accessor = new DirectFieldAccessor(accessor.getPropertyValue("webServiceTemplate"));
    ClientInterceptor interceptor = context.getBean("interceptor", ClientInterceptor.class);
    assertEquals(interceptor, ((ClientInterceptor[]) accessor.getPropertyValue("interceptors"))[0]);
}
Also used : AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) ClientInterceptor(org.springframework.ws.client.support.interceptor.ClientInterceptor) Test(org.junit.Test)

Example 19 with AbstractEndpoint

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

the class SplitterAnnotationPostProcessorTests method testSplitterAnnotation.

@Test
public void testSplitterAnnotation() throws InterruptedException {
    MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor();
    postProcessor.setBeanFactory(context.getBeanFactory());
    postProcessor.afterPropertiesSet();
    TestSplitter splitter = new TestSplitter();
    postProcessor.postProcessAfterInitialization(splitter, "testSplitter");
    context.refresh();
    inputChannel.send(new GenericMessage<String>("this.is.a.test"));
    Message<?> message1 = outputChannel.receive(500);
    assertNotNull(message1);
    assertEquals("this", message1.getPayload());
    Message<?> message2 = outputChannel.receive(500);
    assertNotNull(message2);
    assertEquals("is", message2.getPayload());
    Message<?> message3 = outputChannel.receive(500);
    assertNotNull(message3);
    assertEquals("a", message3.getPayload());
    Message<?> message4 = outputChannel.receive(500);
    assertNotNull(message4);
    assertEquals("test", message4.getPayload());
    assertNull(outputChannel.receive(0));
    AbstractEndpoint endpoint = context.getBean(AbstractEndpoint.class);
    assertTrue(splitter.isRunning());
    endpoint.stop();
    assertFalse(splitter.isRunning());
    endpoint.start();
    assertTrue(splitter.isRunning());
    context.stop();
}
Also used : AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) Test(org.junit.Test)

Example 20 with AbstractEndpoint

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

the class MessagingAnnotationPostProcessor method processAnnotationTypeOnMethod.

protected void processAnnotationTypeOnMethod(Object bean, String beanName, Method method, Class<? extends Annotation> annotationType, List<Annotation> annotations) {
    MethodAnnotationPostProcessor<?> postProcessor = MessagingAnnotationPostProcessor.this.postProcessors.get(annotationType);
    if (postProcessor != null && postProcessor.shouldCreateEndpoint(method, annotations)) {
        Method targetMethod = method;
        if (AopUtils.isJdkDynamicProxy(bean)) {
            try {
                targetMethod = bean.getClass().getMethod(method.getName(), method.getParameterTypes());
            } catch (NoSuchMethodException e) {
                throw new IllegalArgumentException("Service methods must be extracted to the service " + "interface for JdkDynamicProxy. The affected bean is: '" + beanName + "' " + "and its method: '" + method + "'", e);
            }
        }
        Object result = postProcessor.postProcess(bean, beanName, targetMethod, annotations);
        if (result != null && result instanceof AbstractEndpoint) {
            AbstractEndpoint endpoint = (AbstractEndpoint) result;
            String autoStartup = MessagingAnnotationUtils.resolveAttribute(annotations, "autoStartup", String.class);
            if (StringUtils.hasText(autoStartup)) {
                autoStartup = getBeanFactory().resolveEmbeddedValue(autoStartup);
                if (StringUtils.hasText(autoStartup)) {
                    endpoint.setAutoStartup(Boolean.parseBoolean(autoStartup));
                }
            }
            String phase = MessagingAnnotationUtils.resolveAttribute(annotations, "phase", String.class);
            if (StringUtils.hasText(phase)) {
                phase = getBeanFactory().resolveEmbeddedValue(phase);
                if (StringUtils.hasText(phase)) {
                    endpoint.setPhase(Integer.parseInt(phase));
                }
            }
            Role role = AnnotationUtils.findAnnotation(method, Role.class);
            if (role != null) {
                endpoint.setRole(role.value());
            }
            String endpointBeanName = generateBeanName(beanName, method, annotationType);
            endpoint.setBeanName(endpointBeanName);
            getBeanFactory().registerSingleton(endpointBeanName, endpoint);
            getBeanFactory().initializeBean(endpoint, endpointBeanName);
        }
    }
}
Also used : Role(org.springframework.integration.annotation.Role) AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) Method(java.lang.reflect.Method)

Aggregations

AbstractEndpoint (org.springframework.integration.endpoint.AbstractEndpoint)34 Test (org.junit.Test)28 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)19 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)7 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)6 MessageHandler (org.springframework.messaging.MessageHandler)5 Marshaller (org.springframework.oxm.Marshaller)4 Unmarshaller (org.springframework.oxm.Unmarshaller)4 WebServiceMessageFactory (org.springframework.ws.WebServiceMessageFactory)4 PollingConsumer (org.springframework.integration.endpoint.PollingConsumer)3 WebServiceMessageCallback (org.springframework.ws.client.core.WebServiceMessageCallback)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)2 DirectChannel (org.springframework.integration.channel.DirectChannel)2 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)2 ReactiveStreamsConsumer (org.springframework.integration.endpoint.ReactiveStreamsConsumer)2 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)2 PollableChannel (org.springframework.messaging.PollableChannel)2 SubscribableChannel (org.springframework.messaging.SubscribableChannel)2 SourceExtractor (org.springframework.ws.client.core.SourceExtractor)2