use of org.springframework.ws.soap.SoapMessage in project webservices-axiom by apache.
the class TestCreateWebServiceMessageFromInputStream method runTest.
@Override
protected void runTest(SoapMessageFactory messageFactory) throws Throwable {
SoapMessage message = messageFactory.createWebServiceMessage(new TransportInputStreamImpl(SOAPSampleSet.NO_HEADER.getMessage(spec)));
SoapEnvelope env = message.getEnvelope();
assertNull(env.getHeader());
assertNotNull(env.getBody());
}
use of org.springframework.ws.soap.SoapMessage 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.soap.SoapMessage in project spring-integration by spring-projects.
the class SimpleWebServiceOutboundGatewayTests method soapActionAndCustomCallback.
// INT-1051
@Test
public void soapActionAndCustomCallback() {
String uri = "http://www.example.org";
SimpleWebServiceOutboundGateway gateway = new SimpleWebServiceOutboundGateway(new TestDestinationProvider(uri));
final AtomicReference<String> soapActionFromCallback = new AtomicReference<String>();
gateway.setRequestCallback(message -> {
SoapMessage soapMessage = (SoapMessage) message;
soapActionFromCallback.set(soapMessage.getSoapAction());
});
gateway.setBeanFactory(mock(BeanFactory.class));
gateway.afterPropertiesSet();
String soapActionHeaderValue = "testAction";
String request = "<test>foo</test>";
try {
gateway.handleMessage(MessageBuilder.withPayload(request).setHeader(WebServiceHeaders.SOAP_ACTION, soapActionHeaderValue).build());
fail("Expected MessageHandlingException");
} catch (MessageHandlingException e) {
// expected
}
assertNotNull(soapActionFromCallback.get());
assertEquals("\"" + soapActionHeaderValue + "\"", soapActionFromCallback.get());
}
use of org.springframework.ws.soap.SoapMessage in project spring-integration by spring-projects.
the class DefaultSoapHeaderMapperTests method testExtractStandardHeadersEmptySoapAction.
@Test
public void testExtractStandardHeadersEmptySoapAction() {
DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
SoapMessage soapMessage = mock(SoapMessage.class);
when(soapMessage.getSoapAction()).thenReturn("");
assertTrue(mapper.extractStandardHeaders(soapMessage).isEmpty());
}
use of org.springframework.ws.soap.SoapMessage in project spring-integration by spring-projects.
the class DefaultSoapHeaderMapperTests method testExtractStandardHeadersNonEmptySoapAction.
@Test
public void testExtractStandardHeadersNonEmptySoapAction() {
DefaultSoapHeaderMapper mapper = new DefaultSoapHeaderMapper();
SoapMessage soapMessage = mock(SoapMessage.class);
when(soapMessage.getSoapAction()).thenReturn("foo");
Map<String, Object> standardHeaders = mapper.toHeadersFromRequest(soapMessage);
assertEquals(1, standardHeaders.size());
assertTrue(standardHeaders.containsKey(WebServiceHeaders.SOAP_ACTION));
assertEquals("foo", standardHeaders.get(WebServiceHeaders.SOAP_ACTION));
}
Aggregations