use of org.springframework.ws.pox.dom.DomPoxMessageFactory in project spring-integration by spring-projects.
the class SimpleWebServiceOutboundGatewayTests method testDomPoxMessageFactory.
@Test
public void testDomPoxMessageFactory() throws Exception {
String uri = "http://www.example.org";
SimpleWebServiceOutboundGateway gateway = new SimpleWebServiceOutboundGateway(uri);
gateway.setBeanFactory(mock(BeanFactory.class));
final SettableListenableFuture<WebServiceMessage> requestFuture = new SettableListenableFuture<>();
ClientInterceptorAdapter interceptorAdapter = new ClientInterceptorAdapter() {
@Override
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
requestFuture.set(messageContext.getRequest());
return super.handleRequest(messageContext);
}
};
gateway.setInterceptors(interceptorAdapter);
gateway.setMessageFactory(new DomPoxMessageFactory());
gateway.afterPropertiesSet();
String request = "<test>foo</test>";
try {
gateway.handleMessage(new GenericMessage<>(request));
fail("Expected MessageHandlingException");
} catch (MessageHandlingException e) {
// expected
}
WebServiceMessage requestMessage = requestFuture.get(10, TimeUnit.SECONDS);
assertNotNull(requestMessage);
assertThat(requestMessage, instanceOf(PoxMessage.class));
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
StringResult stringResult = new StringResult();
transformer.transform(requestMessage.getPayloadSource(), stringResult);
assertEquals(request, stringResult.toString());
}
use of org.springframework.ws.pox.dom.DomPoxMessageFactory in project camel by apache.
the class BasicMessageFilterTest method nonSoapMessageShouldBeSkipped.
@Test
public void nonSoapMessageShouldBeSkipped() throws Exception {
DomPoxMessage domPoxMessage = new DomPoxMessageFactory().createWebServiceMessage();
filter.filterConsumer(exchange, domPoxMessage);
filter.filterProducer(exchange, domPoxMessage);
}
use of org.springframework.ws.pox.dom.DomPoxMessageFactory in project spring-integration-samples by spring-projects.
the class InboundGatewayTests method testSendAndReceive.
/**
* Emulate the Spring WS MessageDispatcherServlet by calling the gateway
* with a DOMSource object representing the payload of the original SOAP
* 'echoRequest' message. Expect an 'echoResponse' DOMSource object
* to be returned in synchronous fashion, which the MessageDispatcherServlet
* would in turn wrap in a SOAP envelope and return to the client.
*/
@Test
public void testSendAndReceive() throws Exception {
String xml = "<echoRequest xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoRequest>";
DomPoxMessageFactory messageFactory = new DomPoxMessageFactory();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(new InputSource(new StringReader(xml)));
Transformer transformer = TransformerFactory.newInstance().newTransformer();
DomPoxMessage request = new DomPoxMessage(document, transformer, "text/xml");
MessageContext messageContext = new DefaultMessageContext(request, messageFactory);
gateway.invoke(messageContext);
Object reply = messageContext.getResponse().getPayloadSource();
assertThat(reply, is(instanceOf(DOMSource.class)));
DOMSource replySource = (DOMSource) reply;
Element element = (Element) replySource.getNode().getFirstChild();
assertThat(element.getTagName(), equalTo("echoResponse"));
}
use of org.springframework.ws.pox.dom.DomPoxMessageFactory 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