Search in sources :

Example 1 with WebServiceTemplate

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

the class SpringWebserviceComponent method configureProducerConfiguration.

private void configureProducerConfiguration(String remaining, SpringWebserviceConfiguration configuration) throws URISyntaxException {
    if (configuration.getEndpointMapping() == null && configuration.getEndpointDispatcher() == null) {
        LOG.debug("Building Spring Web Services producer");
        URI webServiceEndpointUri = new URI(UnsafeUriCharactersEncoder.encode(remaining));
        // Obtain a WebServiceTemplate from the registry when specified by
        // an option on the component, else create a new template with
        // Spring-WS defaults
        WebServiceTemplate webServiceTemplate = configuration.getWebServiceTemplate();
        if (webServiceTemplate == null) {
            webServiceTemplate = new WebServiceTemplate();
            configuration.setWebServiceTemplate(webServiceTemplate);
        }
        if (webServiceTemplate.getDefaultUri() == null) {
            String uri = webServiceEndpointUri.toString();
            webServiceTemplate.setDefaultUri(uri);
            configuration.setWebServiceEndpointUri(uri);
        }
        if (configuration.getMessageSender() != null) {
            webServiceTemplate.setMessageSender(configuration.getMessageSender());
        }
        if (configuration.getMessageFactory() != null) {
            webServiceTemplate.setMessageFactory(configuration.getMessageFactory());
        }
    }
}
Also used : WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) URI(java.net.URI)

Example 2 with WebServiceTemplate

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

the class AbstractWSATests method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    // initialize beans for catching results
    webServiceTemplate = applicationContext.getBean("webServiceTemplate", WebServiceTemplate.class);
    newReply = getMandatoryBean(OutputChannelReceiver.class, "replyReceiver");
    response = getMandatoryBean(OutputChannelReceiver.class, "responseReceiver");
    // sample data
    source = new StreamSource(new StringReader(xmlBody));
    result = new StreamResult(new StringWriter());
    // reset from previous test
    response.clear();
    newReply.clear();
    requestInputAction = null;
}
Also used : OutputChannelReceiver(org.apache.camel.component.spring.ws.utils.OutputChannelReceiver) StreamResult(javax.xml.transform.stream.StreamResult) StringWriter(java.io.StringWriter) StreamSource(javax.xml.transform.stream.StreamSource) StringReader(java.io.StringReader) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) Before(org.junit.Before)

Example 3 with WebServiceTemplate

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

the class WebServiceOutboundGatewayParserTests method jmsUri.

@Test
@SuppressWarnings("unchecked")
public void jmsUri() {
    AbstractEndpoint endpoint = this.context.getBean("gatewayWithJmsUri", AbstractEndpoint.class);
    assertEquals(EventDrivenConsumer.class, endpoint.getClass());
    MessageHandler handler = TestUtils.getPropertyValue(endpoint, "handler", MessageHandler.class);
    assertNull(TestUtils.getPropertyValue(handler, "destinationProvider"));
    assertFalse(TestUtils.getPropertyValue(handler, "encodeUri", Boolean.class));
    WebServiceTemplate webServiceTemplate = TestUtils.getPropertyValue(handler, "webServiceTemplate", WebServiceTemplate.class);
    webServiceTemplate = spy(webServiceTemplate);
    doReturn(null).when(webServiceTemplate).sendAndReceive(anyString(), any(WebServiceMessageCallback.class), ArgumentMatchers.<WebServiceMessageExtractor<Object>>any());
    new DirectFieldAccessor(handler).setPropertyValue("webServiceTemplate", webServiceTemplate);
    handler.handleMessage(new GenericMessage<String>("foo"));
    verify(webServiceTemplate).sendAndReceive(eq("jms:wsQueue"), any(WebServiceMessageCallback.class), ArgumentMatchers.<WebServiceMessageExtractor<Object>>any());
}
Also used : AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) WebServiceMessageCallback(org.springframework.ws.client.core.WebServiceMessageCallback) MessageHandler(org.springframework.messaging.MessageHandler) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) Test(org.junit.Test)

Example 4 with WebServiceTemplate

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

the class UriVariableTests method testHttpUriVariables.

@Test
@SuppressWarnings("unchecked")
public void testHttpUriVariables() {
    WebServiceTemplate webServiceTemplate = TestUtils.getPropertyValue(this.httpOutboundGateway, "webServiceTemplate", WebServiceTemplate.class);
    webServiceTemplate = Mockito.spy(webServiceTemplate);
    final AtomicReference<String> uri = new AtomicReference<>();
    doAnswer(invocation -> {
        uri.set(invocation.getArgument(0));
        throw new WebServiceIOException("intentional");
    }).when(webServiceTemplate).sendAndReceive(Mockito.anyString(), Mockito.any(WebServiceMessageCallback.class), (WebServiceMessageExtractor<Object>) Mockito.any(WebServiceMessageExtractor.class));
    new DirectFieldAccessor(this.httpOutboundGateway).setPropertyValue("webServiceTemplate", webServiceTemplate);
    Message<?> message = MessageBuilder.withPayload("<spring/>").setHeader("x", "integration").setHeader("param", "test1 & test2").build();
    try {
        this.inputHttp.send(message);
    } catch (MessageHandlingException e) {
        // expected
        // offline
        assertThat(e.getCause(), Matchers.is(Matchers.instanceOf(WebServiceIOException.class)));
    }
    assertEquals("http://localhost/spring-integration?param=test1%20&%20test2", uri.get());
}
Also used : WebServiceMessageCallback(org.springframework.ws.client.core.WebServiceMessageCallback) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) AtomicReference(java.util.concurrent.atomic.AtomicReference) WebServiceIOException(org.springframework.ws.client.WebServiceIOException) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) MessageHandlingException(org.springframework.messaging.MessageHandlingException) Test(org.junit.Test)

Example 5 with WebServiceTemplate

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

the class WebServiceTemplateBuilderTests method additionalCustomizersShouldAddToExisting.

@Test
void additionalCustomizersShouldAddToExisting() {
    WebServiceTemplateCustomizer customizer1 = mock(WebServiceTemplateCustomizer.class);
    WebServiceTemplateCustomizer customizer2 = mock(WebServiceTemplateCustomizer.class);
    WebServiceTemplate template = this.builder.customizers(customizer1).additionalCustomizers(customizer2).build();
    then(customizer1).should().customize(template);
    then(customizer2).should().customize(template);
}
Also used : 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