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);
}
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);
}
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);
}
}
}
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);
}
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);
}
Aggregations