Search in sources :

Example 1 with WebServiceMessageCallback

use of org.springframework.ws.client.core.WebServiceMessageCallback 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 2 with WebServiceMessageCallback

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

use of org.springframework.ws.client.core.WebServiceMessageCallback in project spring-integration by spring-projects.

the class WebServiceOutboundGatewayParserTests method simpleGatewayWithCustomRequestCallback.

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

Aggregations

WebServiceMessageCallback (org.springframework.ws.client.core.WebServiceMessageCallback)3 Test (org.junit.Test)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 AbstractEndpoint (org.springframework.integration.endpoint.AbstractEndpoint)2 IOException (java.io.IOException)1 URI (java.net.URI)1 Source (javax.xml.transform.Source)1 TransformerException (javax.xml.transform.TransformerException)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 WebServiceMessage (org.springframework.ws.WebServiceMessage)1 SoapMessage (org.springframework.ws.soap.SoapMessage)1