use of org.springframework.integration.ws.AbstractWebServiceOutboundGateway 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);
}
Aggregations