Search in sources :

Example 6 with WebServiceMessage

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

the class SpringWebserviceConsumer method populateExchangeFromMessageContext.

private void populateExchangeFromMessageContext(MessageContext messageContext, Exchange exchange) {
    populateExchangeWithPropertiesFromMessageContext(messageContext, exchange);
    // create inbound message
    WebServiceMessage request = messageContext.getRequest();
    SpringWebserviceMessage inMessage = new SpringWebserviceMessage(request);
    extractSourceFromSoapHeader(inMessage.getHeaders(), request);
    extractAttachmentsFromRequest(request, inMessage);
    exchange.setIn(inMessage);
}
Also used : WebServiceMessage(org.springframework.ws.WebServiceMessage)

Example 7 with WebServiceMessage

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

the class SpringWebserviceProducer method process.

public void process(Exchange exchange) throws Exception {
    // Let Camel TypeConverter hierarchy handle the conversion of XML messages to Source objects
    Source sourcePayload = exchange.getIn().getMandatoryBody(Source.class);
    // Extract optional headers
    String endpointUriHeader = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_ENDPOINT_URI, String.class);
    String soapActionHeader = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_SOAP_ACTION, String.class);
    URI wsAddressingActionHeader = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_ADDRESSING_ACTION, URI.class);
    URI wsReplyToHeader = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_ADDRESSING_PRODUCER_REPLY_TO, URI.class);
    URI wsFaultToHeader = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_ADDRESSING_PRODUCER_FAULT_TO, URI.class);
    Source soapHeaderSource = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_SOAP_HEADER, Source.class);
    WebServiceMessageCallback callback = new DefaultWebserviceMessageCallback(soapActionHeader, wsAddressingActionHeader, wsReplyToHeader, wsFaultToHeader, soapHeaderSource, getEndpoint().getConfiguration(), exchange);
    if (endpointUriHeader == null) {
        endpointUriHeader = getEndpoint().getConfiguration().getWebServiceTemplate().getDefaultUri();
    }
    getEndpoint().getConfiguration().getWebServiceTemplate().sendAndReceive(endpointUriHeader, new WebServiceMessageCallback() {

        @Override
        public void doWithMessage(WebServiceMessage requestMessage) throws IOException, TransformerException {
            XML_CONVERTER.toResult(sourcePayload, requestMessage.getPayloadResult());
            callback.doWithMessage(requestMessage);
        }
    }, new WebServiceMessageCallback() {

        @Override
        public void doWithMessage(WebServiceMessage responseMessage) throws IOException, TransformerException {
            SoapMessage soapMessage = (SoapMessage) responseMessage;
            if (ExchangeHelper.isOutCapable(exchange)) {
                exchange.getOut().copyFromWithNewBody(exchange.getIn(), soapMessage.getPayloadSource());
                populateHeaderAndAttachmentsFromResponse(exchange.getOut(), soapMessage);
            } else {
                exchange.getIn().setBody(soapMessage.getPayloadSource());
                populateHeaderAndAttachmentsFromResponse(exchange.getIn(), soapMessage);
            }
        }
    });
}
Also used : WebServiceMessage(org.springframework.ws.WebServiceMessage) WebServiceMessageCallback(org.springframework.ws.client.core.WebServiceMessageCallback) IOException(java.io.IOException) URI(java.net.URI) Source(javax.xml.transform.Source) TransformerException(javax.xml.transform.TransformerException) SoapMessage(org.springframework.ws.soap.SoapMessage)

Example 8 with WebServiceMessage

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

the class SimpleWebServiceInboundGateway method doInvoke.

@Override
protected void doInvoke(MessageContext messageContext) throws Exception {
    WebServiceMessage request = messageContext.getRequest();
    Assert.notNull(request, "Invalid message context: request was null.");
    AbstractIntegrationMessageBuilder<?> builder = this.getMessageBuilderFactory().withPayload((this.extractPayload) ? request.getPayloadSource() : request);
    this.fromSoapHeaders(messageContext, builder);
    Message<?> replyMessage = this.sendAndReceiveMessage(builder.build());
    if (replyMessage != null) {
        Object replyPayload = replyMessage.getPayload();
        Source responseSource = null;
        if (replyPayload instanceof WebServiceMessage) {
            messageContext.setResponse((WebServiceMessage) replyPayload);
        } else {
            if (replyPayload instanceof Source) {
                responseSource = (Source) replyPayload;
            } else if (replyPayload instanceof Document) {
                responseSource = new DOMSource((Document) replyPayload);
            } else if (replyPayload instanceof String) {
                responseSource = new StringSource((String) replyPayload);
            } else {
                throw new IllegalArgumentException("The reply Message payload must be a [" + Source.class.getName() + "], [" + Document.class.getName() + "], [java.lang.String] or [" + WebServiceMessage.class.getName() + "]. " + "The actual type was [" + replyPayload.getClass().getName() + "]");
            }
            WebServiceMessage response = messageContext.getResponse();
            this.transformerSupportDelegate.transformSourceToResult(responseSource, response.getPayloadResult());
            toSoapHeaders(response, replyMessage);
        }
    }
}
Also used : WebServiceMessage(org.springframework.ws.WebServiceMessage) DOMSource(javax.xml.transform.dom.DOMSource) StringSource(org.springframework.xml.transform.StringSource) Document(org.w3c.dom.Document) DOMSource(javax.xml.transform.dom.DOMSource) StringSource(org.springframework.xml.transform.StringSource) Source(javax.xml.transform.Source)

Example 9 with WebServiceMessage

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

the class WebServiceOutboundGatewayWithHeaderMapperTests method process.

private Message<?> process(Object payload, String gatewayName, String channelName, final boolean soap) throws Exception {
    AbstractWebServiceOutboundGateway gateway = TestUtils.getPropertyValue(this.context.getBean(gatewayName), "handler", AbstractWebServiceOutboundGateway.class);
    if (!soap) {
        WebServiceTemplate template = TestUtils.getPropertyValue(gateway, "webServiceTemplate", WebServiceTemplate.class);
        template.setMessageFactory(new DomPoxMessageFactory());
    }
    WebServiceMessageSender messageSender = Mockito.mock(WebServiceMessageSender.class);
    WebServiceConnection wsConnection = Mockito.mock(WebServiceConnection.class);
    Mockito.when(messageSender.createConnection(Mockito.any(URI.class))).thenReturn(wsConnection);
    Mockito.when(messageSender.supports(Mockito.any(URI.class))).thenReturn(true);
    Mockito.doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        WebServiceMessage wsMessage = (WebServiceMessage) args[0];
        // }
        if (soap) {
            SoapHeader soapHeader = ((SoapMessage) wsMessage).getSoapHeader();
            assertNotNull(soapHeader.getAttributeValue(QNameUtils.parseQNameString("foo")));
            assertNotNull(soapHeader.getAttributeValue(QNameUtils.parseQNameString("foobar")));
            assertNotNull(soapHeader.getAttributeValue(QNameUtils.parseQNameString("abaz")));
            assertNull(soapHeader.getAttributeValue(QNameUtils.parseQNameString("bar")));
        }
        return null;
    }).when(wsConnection).send(Mockito.any(WebServiceMessage.class));
    Mockito.doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        WebServiceMessageFactory factory = (WebServiceMessageFactory) args[0];
        String responseMessage = factory instanceof SoapMessageFactory ? responseSoapMessage : responseNonSoapMessage;
        WebServiceMessage wsMessage = factory.createWebServiceMessage(new ByteArrayInputStream(responseMessage.getBytes()));
        if (soap) {
            ((SoapMessage) wsMessage).getSoapHeader().addAttribute(QNameUtils.parseQNameString("bar"), "bar");
            ((SoapMessage) wsMessage).getSoapHeader().addAttribute(QNameUtils.parseQNameString("baz"), "baz");
        }
        // }
        return wsMessage;
    }).when(wsConnection).receive(Mockito.any(WebServiceMessageFactory.class));
    gateway.setMessageSender(messageSender);
    MessageChannel inputChannel = context.getBean(channelName, MessageChannel.class);
    Message<?> message = MessageBuilder.withPayload(payload).setHeader("foo", "foo").setHeader("foobar", "foobar").setHeader("abaz", "abaz").setHeader("bar", "bar").setHeader(WebServiceHeaders.SOAP_ACTION, "someAction").build();
    inputChannel.send(message);
    QueueChannel outputChannel = context.getBean("outputChannel", QueueChannel.class);
    return outputChannel.receive(0);
}
Also used : WebServiceMessageFactory(org.springframework.ws.WebServiceMessageFactory) QueueChannel(org.springframework.integration.channel.QueueChannel) DomPoxMessageFactory(org.springframework.ws.pox.dom.DomPoxMessageFactory) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) URI(java.net.URI) SoapMessage(org.springframework.ws.soap.SoapMessage) WebServiceMessage(org.springframework.ws.WebServiceMessage) SoapMessageFactory(org.springframework.ws.soap.SoapMessageFactory) WebServiceMessageSender(org.springframework.ws.transport.WebServiceMessageSender) MessageChannel(org.springframework.messaging.MessageChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) SoapHeader(org.springframework.ws.soap.SoapHeader) AbstractWebServiceOutboundGateway(org.springframework.integration.ws.AbstractWebServiceOutboundGateway) WebServiceConnection(org.springframework.ws.transport.WebServiceConnection)

Example 10 with WebServiceMessage

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

the class AbstractWebServiceInboundGateway method fromSoapHeaders.

protected void fromSoapHeaders(MessageContext messageContext, AbstractIntegrationMessageBuilder<?> builder) {
    WebServiceMessage request = messageContext.getRequest();
    String[] propertyNames = messageContext.getPropertyNames();
    if (propertyNames != null) {
        for (String propertyName : propertyNames) {
            builder.setHeader(propertyName, messageContext.getProperty(propertyName));
        }
    }
    if (request instanceof SoapMessage) {
        SoapMessage soapMessage = (SoapMessage) request;
        Map<String, ?> headers = this.headerMapper.toHeadersFromRequest(soapMessage);
        if (!CollectionUtils.isEmpty(headers)) {
            builder.copyHeaders(headers);
        }
    }
}
Also used : WebServiceMessage(org.springframework.ws.WebServiceMessage) SoapMessage(org.springframework.ws.soap.SoapMessage)

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