Search in sources :

Example 11 with WebServiceTemplate

use of org.springframework.ws.client.core.WebServiceTemplate in project spring-boot by spring-projects.

the class WebServiceTemplateBuilderTests method additionalMessageSendersShouldAddToExisting.

@Test
void additionalMessageSendersShouldAddToExisting() {
    ClientHttpRequestMessageSender httpMessageSender = new ClientHttpRequestMessageSender();
    WebServiceTemplate template = this.builder.messageSenders(httpMessageSender).additionalMessageSenders(this.messageSender).build();
    assertThat(template.getMessageSenders()).containsOnly(httpMessageSender, this.messageSender);
}
Also used : WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) ClientHttpRequestMessageSender(org.springframework.ws.transport.http.ClientHttpRequestMessageSender) Test(org.junit.jupiter.api.Test)

Example 12 with WebServiceTemplate

use of org.springframework.ws.client.core.WebServiceTemplate in project spring-boot by spring-projects.

the class WebServiceTemplateBuilderTests method setUnmarshaller.

@Test
void setUnmarshaller() {
    Unmarshaller unmarshaller = mock(Unmarshaller.class);
    WebServiceTemplate webServiceTemplate = this.builder.setUnmarshaller(unmarshaller).build();
    assertThat(webServiceTemplate.getUnmarshaller()).isEqualTo(unmarshaller);
}
Also used : Unmarshaller(org.springframework.oxm.Unmarshaller) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) Test(org.junit.jupiter.api.Test)

Example 13 with WebServiceTemplate

use of org.springframework.ws.client.core.WebServiceTemplate in project camel by apache.

the class SpringWebserviceProducer method prepareMessageSenders.

private void prepareMessageSenders(SpringWebserviceConfiguration configuration) {
    // Skip this whole thing if none of the relevant config options are set.
    if (!(configuration.getTimeout() > -1) && configuration.getSslContextParameters() == null) {
        return;
    }
    WebServiceTemplate webServiceTemplate = configuration.getWebServiceTemplate();
    WebServiceMessageSender[] messageSenders = webServiceTemplate.getMessageSenders();
    for (int i = 0; i < messageSenders.length; i++) {
        WebServiceMessageSender messageSender = messageSenders[i];
        if (messageSender instanceof HttpComponentsMessageSender) {
            if (configuration.getSslContextParameters() != null) {
                LOG.warn("Not applying SSLContextParameters based configuration to HttpComponentsMessageSender.  " + "If you are using this MessageSender, which you are not by default, you will need " + "to configure SSL using the Commons HTTP 3.x Protocol registry.");
            }
            if (configuration.getTimeout() > -1) {
                if (messageSender.getClass().equals(HttpComponentsMessageSender.class)) {
                    ((HttpComponentsMessageSender) messageSender).setReadTimeout(configuration.getTimeout());
                } else {
                    LOG.warn("Not applying timeout configuration to HttpComponentsMessageSender based implementation.  " + "You are using what appears to be a custom MessageSender, which you are not doing by default. " + "You will need configure timeout on your own.");
                }
            }
        } else if (messageSender.getClass().equals(HttpUrlConnectionMessageSender.class)) {
            // Only if exact match denoting likely use of default configuration.  We don't want to get
            // sub-classes that might have been otherwise injected.
            messageSenders[i] = new AbstractHttpWebServiceMessageSenderDecorator((HttpUrlConnectionMessageSender) messageSender, configuration, getEndpoint().getCamelContext());
        } else {
            // For example this will be the case during unit-testing with the net.javacrumbs.spring-ws-test API
            LOG.warn("Ignoring the timeout and SSLContextParameters options for {}.  You will need to configure " + "these options directly on your custom configured WebServiceMessageSender", messageSender);
        }
    }
}
Also used : AbstractHttpWebServiceMessageSender(org.springframework.ws.transport.http.AbstractHttpWebServiceMessageSender) WebServiceMessageSender(org.springframework.ws.transport.WebServiceMessageSender) HttpComponentsMessageSender(org.springframework.ws.transport.http.HttpComponentsMessageSender) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) HttpUrlConnectionMessageSender(org.springframework.ws.transport.http.HttpUrlConnectionMessageSender) Endpoint(org.apache.camel.Endpoint)

Example 14 with WebServiceTemplate

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

use of org.springframework.ws.client.core.WebServiceTemplate in project spring-boot by spring-projects.

the class WebServiceTemplateBuilderTests method additionalInterceptorsShouldAddToExistingWebServiceTemplate.

@Test
void additionalInterceptorsShouldAddToExistingWebServiceTemplate() {
    ClientInterceptor f1 = mock(ClientInterceptor.class);
    ClientInterceptor f2 = mock(ClientInterceptor.class);
    WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
    webServiceTemplate.setInterceptors(new ClientInterceptor[] { f1 });
    this.builder.additionalInterceptors(f2).configure(webServiceTemplate);
    assertThat(webServiceTemplate.getInterceptors()).containsExactlyInAnyOrder(f2, f1);
}
Also used : ClientInterceptor(org.springframework.ws.client.support.interceptor.ClientInterceptor) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

WebServiceTemplate (org.springframework.ws.client.core.WebServiceTemplate)30 Test (org.junit.jupiter.api.Test)24 URI (java.net.URI)4 ClientInterceptor (org.springframework.ws.client.support.interceptor.ClientInterceptor)4 WebServiceMessageSender (org.springframework.ws.transport.WebServiceMessageSender)4 WebServiceMessageFactory (org.springframework.ws.WebServiceMessageFactory)3 ClientHttpRequestMessageSender (org.springframework.ws.transport.http.ClientHttpRequestMessageSender)3 SAXTransformerFactory (javax.xml.transform.sax.SAXTransformerFactory)2 Test (org.junit.Test)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 Marshaller (org.springframework.oxm.Marshaller)2 Unmarshaller (org.springframework.oxm.Unmarshaller)2 FaultMessageResolver (org.springframework.ws.client.core.FaultMessageResolver)2 WebServiceMessageCallback (org.springframework.ws.client.core.WebServiceMessageCallback)2 DestinationProvider (org.springframework.ws.client.support.destination.DestinationProvider)2 HttpUrlConnectionMessageSender (org.springframework.ws.transport.http.HttpUrlConnectionMessageSender)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Collection (java.util.Collection)1