Search in sources :

Example 1 with WebServiceMessage

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

the class SimpleWebServiceOutboundGatewayTests method testDomPoxMessageFactory.

@Test
public void testDomPoxMessageFactory() 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.setMessageFactory(new DomPoxMessageFactory());
    gateway.afterPropertiesSet();
    String request = "<test>foo</test>";
    try {
        gateway.handleMessage(new GenericMessage<>(request));
        fail("Expected MessageHandlingException");
    } catch (MessageHandlingException e) {
    // expected
    }
    WebServiceMessage requestMessage = requestFuture.get(10, TimeUnit.SECONDS);
    assertNotNull(requestMessage);
    assertThat(requestMessage, instanceOf(PoxMessage.class));
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    Transformer transformer = transformerFactory.newTransformer();
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
    StringResult stringResult = new StringResult();
    transformer.transform(requestMessage.getPayloadSource(), stringResult);
    assertEquals(request, stringResult.toString());
}
Also used : SettableListenableFuture(org.springframework.util.concurrent.SettableListenableFuture) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) DomPoxMessageFactory(org.springframework.ws.pox.dom.DomPoxMessageFactory) ClientInterceptorAdapter(org.springframework.ws.client.support.interceptor.ClientInterceptorAdapter) MessageHandlingException(org.springframework.messaging.MessageHandlingException) WebServiceMessage(org.springframework.ws.WebServiceMessage) BeanFactory(org.springframework.beans.factory.BeanFactory) MessageContext(org.springframework.ws.context.MessageContext) StringResult(org.springframework.xml.transform.StringResult) PoxMessage(org.springframework.ws.pox.PoxMessage) Test(org.junit.Test)

Example 2 with WebServiceMessage

use of org.springframework.ws.WebServiceMessage 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 3 with WebServiceMessage

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

the class StubMessageFactory method createWebServiceMessage.

public WebServiceMessage createWebServiceMessage() {
    WebServiceMessage message = mock(WebServiceMessage.class);
    Source source = mock(Source.class);
    when(message.getPayloadSource()).thenReturn(source);
    return message;
}
Also used : WebServiceMessage(org.springframework.ws.WebServiceMessage) InputSource(org.xml.sax.InputSource) Source(javax.xml.transform.Source)

Example 4 with WebServiceMessage

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

the class MarshallingWebServiceInboundGateway method doInvoke.

@Override
protected void doInvoke(MessageContext messageContext) throws Exception {
    WebServiceMessage request = messageContext.getRequest();
    Assert.notNull(request, "Invalid message context: request was null.");
    Object requestObject = MarshallingUtils.unmarshal(this.unmarshaller, request);
    AbstractIntegrationMessageBuilder<?> builder = this.getMessageBuilderFactory().withPayload(requestObject);
    this.fromSoapHeaders(messageContext, builder);
    Message<?> replyMessage = this.sendAndReceiveMessage(builder.build());
    if (replyMessage != null) {
        WebServiceMessage response = messageContext.getResponse();
        this.toSoapHeaders(response, replyMessage);
        MarshallingUtils.marshal(this.marshaller, replyMessage.getPayload(), response);
    }
}
Also used : WebServiceMessage(org.springframework.ws.WebServiceMessage)

Example 5 with WebServiceMessage

use of org.springframework.ws.WebServiceMessage in project camel by apache.

the class SpringWebserviceConsumer method invoke.

/**
     * Invoked by Spring-WS when a {@link WebServiceMessage} is received
     */
public void invoke(MessageContext messageContext) throws Exception {
    Exchange exchange = getEndpoint().createExchange(ExchangePattern.InOptionalOut);
    populateExchangeFromMessageContext(messageContext, exchange);
    // populate camel exchange with breadcrumb from transport header        
    populateExchangeWithBreadcrumbFromMessageContext(messageContext, exchange);
    // start message processing
    getProcessor().process(exchange);
    if (exchange.getException() != null) {
        throw exchange.getException();
    } else if (exchange.getPattern().isOutCapable()) {
        Message responseMessage = exchange.hasOut() ? exchange.getOut(Message.class) : exchange.getIn(Message.class);
        if (responseMessage != null) {
            Source responseBody = responseMessage.getBody(Source.class);
            WebServiceMessage response = messageContext.getResponse();
            configuration.getMessageFilter().filterConsumer(exchange, response);
            XmlConverter xmlConverter = configuration.getXmlConverter();
            xmlConverter.toResult(responseBody, response.getPayloadResult());
        }
    }
}
Also used : Exchange(org.apache.camel.Exchange) WebServiceMessage(org.springframework.ws.WebServiceMessage) SoapMessage(org.springframework.ws.soap.SoapMessage) Message(org.apache.camel.Message) MimeMessage(org.springframework.ws.mime.MimeMessage) WebServiceMessage(org.springframework.ws.WebServiceMessage) SOAPMessage(javax.xml.soap.SOAPMessage) SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) Source(javax.xml.transform.Source) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter)

Aggregations

WebServiceMessage (org.springframework.ws.WebServiceMessage)10 Source (javax.xml.transform.Source)4 SoapMessage (org.springframework.ws.soap.SoapMessage)4 URI (java.net.URI)2 Transformer (javax.xml.transform.Transformer)2 TransformerFactory (javax.xml.transform.TransformerFactory)2 Test (org.junit.Test)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 MessageHandlingException (org.springframework.messaging.MessageHandlingException)2 SettableListenableFuture (org.springframework.util.concurrent.SettableListenableFuture)2 WebServiceMessageFactory (org.springframework.ws.WebServiceMessageFactory)2 ClientInterceptorAdapter (org.springframework.ws.client.support.interceptor.ClientInterceptorAdapter)2 MessageContext (org.springframework.ws.context.MessageContext)2 MimeMessage (org.springframework.ws.mime.MimeMessage)2 DomPoxMessageFactory (org.springframework.ws.pox.dom.DomPoxMessageFactory)2 StringResult (org.springframework.xml.transform.StringResult)2 StringSource (org.springframework.xml.transform.StringSource)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 SOAPMessage (javax.xml.soap.SOAPMessage)1