use of org.springframework.ws.transport.WebServiceConnection in project spring-integration by spring-projects.
the class UriVariableTests method testInt2720EmailUriVariables.
@Test
public void testInt2720EmailUriVariables() {
final String testEmailTo = "user@example.com";
final String testEmailSubject = "Test subject";
Message<?> message = MessageBuilder.withPayload("<spring/>").setHeader("to", testEmailTo).setHeader("subject", testEmailSubject).build();
try {
this.inputEmail.send(message);
} catch (MessageHandlingException e) {
// expected
Class<?> causeType = e.getCause().getClass();
// offline
assertTrue(WebServiceIOException.class.equals(causeType));
}
WebServiceConnection webServiceConnection = this.emailInterceptor.getLastWebServiceConnection();
assertEquals(testEmailTo, TestUtils.getPropertyValue(webServiceConnection, "to").toString());
assertEquals(testEmailSubject, TestUtils.getPropertyValue(webServiceConnection, "subject"));
assertEquals("mailto:user@example.com?subject=Test%20subject", this.emailInterceptor.getLastUri().toString());
}
use of org.springframework.ws.transport.WebServiceConnection 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.transport.WebServiceConnection in project spring-integration by spring-projects.
the class SimpleWebServiceOutboundGatewayTests method createMockMessageSender.
public static WebServiceMessageSender createMockMessageSender(final String mockResponseMessage) throws Exception {
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();
WebServiceMessageFactory factory = (WebServiceMessageFactory) args[0];
return factory.createWebServiceMessage(new ByteArrayInputStream(mockResponseMessage.getBytes()));
}).when(wsConnection).receive(Mockito.any(WebServiceMessageFactory.class));
return messageSender;
}
Aggregations