Search in sources :

Example 1 with WebServiceMessageFactory

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

the class WebServiceOutboundGatewayParserTests method simpleGatewayWithCustomMessageFactory.

@Test
public void simpleGatewayWithCustomMessageFactory() {
    AbstractEndpoint endpoint = this.context.getBean("gatewayWithCustomMessageFactory", 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"));
    WebServiceMessageFactory factory = (WebServiceMessageFactory) context.getBean("messageFactory");
    assertEquals(factory, accessor.getPropertyValue("messageFactory"));
}
Also used : AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) WebServiceMessageFactory(org.springframework.ws.WebServiceMessageFactory) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 2 with WebServiceMessageFactory

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

the class WebServiceOutboundGatewayParserTests method marshallingGatewayWithAllInOneMarshallerAndMessageFactory.

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

Example 3 with WebServiceMessageFactory

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

the class SimpleWebServiceOutboundGatewayTests method testAttachments.

@Test
public void testAttachments() throws Exception {
    String uri = "http://www.example.org";
    SimpleWebServiceOutboundGateway gateway = new SimpleWebServiceOutboundGateway(uri);
    gateway.setBeanFactory(mock(BeanFactory.class));
    final SettableListenableFuture<WebServiceMessage> requestFuture = new SettableListenableFuture<>();
    ClientInterceptorAdapter interceptorAdapter = new ClientInterceptorAdapter() {

        @Override
        public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
            requestFuture.set(messageContext.getRequest());
            return super.handleRequest(messageContext);
        }
    };
    gateway.setInterceptors(interceptorAdapter);
    gateway.afterPropertiesSet();
    WebServiceMessageFactory messageFactory = new SaajSoapMessageFactory(MessageFactory.newInstance());
    MimeMessage webServiceMessage = (MimeMessage) messageFactory.createWebServiceMessage();
    String request = "<test>foo</test>";
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.transform(new StringSource(request), webServiceMessage.getPayloadResult());
    webServiceMessage.addAttachment("myAttachment", new ByteArrayResource("my_data".getBytes()), "text/plain");
    try {
        gateway.handleMessage(new GenericMessage<>(webServiceMessage));
        fail("Expected MessageHandlingException");
    } catch (MessageHandlingException e) {
    // expected
    }
    WebServiceMessage requestMessage = requestFuture.get(10, TimeUnit.SECONDS);
    assertNotNull(requestMessage);
    assertThat(requestMessage, instanceOf(MimeMessage.class));
    transformer = transformerFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    StringResult stringResult = new StringResult();
    transformer.transform(requestMessage.getPayloadSource(), stringResult);
    assertEquals(request, stringResult.toString());
    Attachment myAttachment = ((MimeMessage) requestMessage).getAttachment("myAttachment");
    assertNotNull(myAttachment);
    assertEquals("text/plain", myAttachment.getContentType());
    assertEquals("my_data", StreamUtils.copyToString(myAttachment.getInputStream(), Charset.forName("UTF-8")));
}
Also used : WebServiceMessageFactory(org.springframework.ws.WebServiceMessageFactory) SettableListenableFuture(org.springframework.util.concurrent.SettableListenableFuture) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) Attachment(org.springframework.ws.mime.Attachment) SaajSoapMessageFactory(org.springframework.ws.soap.saaj.SaajSoapMessageFactory) ByteArrayResource(org.springframework.core.io.ByteArrayResource) ClientInterceptorAdapter(org.springframework.ws.client.support.interceptor.ClientInterceptorAdapter) MessageHandlingException(org.springframework.messaging.MessageHandlingException) WebServiceMessage(org.springframework.ws.WebServiceMessage) MimeMessage(org.springframework.ws.mime.MimeMessage) BeanFactory(org.springframework.beans.factory.BeanFactory) MessageContext(org.springframework.ws.context.MessageContext) StringSource(org.springframework.xml.transform.StringSource) StringResult(org.springframework.xml.transform.StringResult) Test(org.junit.Test)

Example 4 with WebServiceMessageFactory

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

the class WebServiceOutboundGatewayParserTests method marshallingGatewayWithSeparateMarshallerAndUnmarshallerAndMessageFactory.

@Test
public void marshallingGatewayWithSeparateMarshallerAndUnmarshallerAndMessageFactory() {
    ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("marshallingWebServiceOutboundGatewayParserTests.xml", this.getClass());
    AbstractEndpoint endpoint = (AbstractEndpoint) context.getBean("gatewayWithSeparateMarshallerAndUnmarshallerAndMessageFactory");
    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));
    WebServiceMessageFactory messageFactory = context.getBean("messageFactory", WebServiceMessageFactory.class);
    assertEquals(messageFactory, TestUtils.getPropertyValue(gateway, "webServiceTemplate.messageFactory"));
    context.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) Marshaller(org.springframework.oxm.Marshaller) WebServiceMessageFactory(org.springframework.ws.WebServiceMessageFactory) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Unmarshaller(org.springframework.oxm.Unmarshaller) Test(org.junit.Test)

Example 5 with WebServiceMessageFactory

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

the class WebServiceOutboundGatewayParserTests method simpleGatewayWithCustomSourceExtractorAndMessageFactory.

@Test
public void simpleGatewayWithCustomSourceExtractorAndMessageFactory() {
    AbstractEndpoint endpoint = context.getBean("gatewayWithCustomSourceExtractorAndMessageFactory", AbstractEndpoint.class);
    SourceExtractor<?> sourceExtractor = (SourceExtractor<?>) context.getBean("sourceExtractor");
    assertEquals(EventDrivenConsumer.class, endpoint.getClass());
    Object gateway = new DirectFieldAccessor(endpoint).getPropertyValue("handler");
    assertEquals(SimpleWebServiceOutboundGateway.class, gateway.getClass());
    DirectFieldAccessor accessor = new DirectFieldAccessor(gateway);
    assertEquals(sourceExtractor, accessor.getPropertyValue("sourceExtractor"));
    accessor = new DirectFieldAccessor(accessor.getPropertyValue("webServiceTemplate"));
    WebServiceMessageFactory factory = (WebServiceMessageFactory) context.getBean("messageFactory");
    assertEquals(factory, accessor.getPropertyValue("messageFactory"));
}
Also used : AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) WebServiceMessageFactory(org.springframework.ws.WebServiceMessageFactory) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) SourceExtractor(org.springframework.ws.client.core.SourceExtractor) Test(org.junit.Test)

Aggregations

WebServiceMessageFactory (org.springframework.ws.WebServiceMessageFactory)7 Test (org.junit.Test)5 AbstractEndpoint (org.springframework.integration.endpoint.AbstractEndpoint)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URI (java.net.URI)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)2 Marshaller (org.springframework.oxm.Marshaller)2 Unmarshaller (org.springframework.oxm.Unmarshaller)2 WebServiceMessage (org.springframework.ws.WebServiceMessage)2 WebServiceConnection (org.springframework.ws.transport.WebServiceConnection)2 WebServiceMessageSender (org.springframework.ws.transport.WebServiceMessageSender)2 Transformer (javax.xml.transform.Transformer)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1 QueueChannel (org.springframework.integration.channel.QueueChannel)1 AbstractWebServiceOutboundGateway (org.springframework.integration.ws.AbstractWebServiceOutboundGateway)1 MessageChannel (org.springframework.messaging.MessageChannel)1