use of org.springframework.ws.WebServiceMessage in project camel by apache.
the class SpringWebserviceConsumer method populateExchangeFromMessageContext.
private void populateExchangeFromMessageContext(MessageContext messageContext, Exchange exchange) {
populateExchangeWithPropertiesFromMessageContext(messageContext, exchange);
// create inbound message
WebServiceMessage request = messageContext.getRequest();
SpringWebserviceMessage inMessage = new SpringWebserviceMessage(request);
extractSourceFromSoapHeader(inMessage.getHeaders(), request);
extractAttachmentsFromRequest(request, inMessage);
exchange.setIn(inMessage);
}
use of org.springframework.ws.WebServiceMessage in project camel by apache.
the class SpringWebserviceProducer method process.
public void process(Exchange exchange) throws Exception {
// Let Camel TypeConverter hierarchy handle the conversion of XML messages to Source objects
Source sourcePayload = exchange.getIn().getMandatoryBody(Source.class);
// Extract optional headers
String endpointUriHeader = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_ENDPOINT_URI, String.class);
String soapActionHeader = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_SOAP_ACTION, String.class);
URI wsAddressingActionHeader = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_ADDRESSING_ACTION, URI.class);
URI wsReplyToHeader = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_ADDRESSING_PRODUCER_REPLY_TO, URI.class);
URI wsFaultToHeader = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_ADDRESSING_PRODUCER_FAULT_TO, URI.class);
Source soapHeaderSource = exchange.getIn().getHeader(SpringWebserviceConstants.SPRING_WS_SOAP_HEADER, Source.class);
WebServiceMessageCallback callback = new DefaultWebserviceMessageCallback(soapActionHeader, wsAddressingActionHeader, wsReplyToHeader, wsFaultToHeader, soapHeaderSource, getEndpoint().getConfiguration(), exchange);
if (endpointUriHeader == null) {
endpointUriHeader = getEndpoint().getConfiguration().getWebServiceTemplate().getDefaultUri();
}
getEndpoint().getConfiguration().getWebServiceTemplate().sendAndReceive(endpointUriHeader, new WebServiceMessageCallback() {
@Override
public void doWithMessage(WebServiceMessage requestMessage) throws IOException, TransformerException {
XML_CONVERTER.toResult(sourcePayload, requestMessage.getPayloadResult());
callback.doWithMessage(requestMessage);
}
}, new WebServiceMessageCallback() {
@Override
public void doWithMessage(WebServiceMessage responseMessage) throws IOException, TransformerException {
SoapMessage soapMessage = (SoapMessage) responseMessage;
if (ExchangeHelper.isOutCapable(exchange)) {
exchange.getOut().copyFromWithNewBody(exchange.getIn(), soapMessage.getPayloadSource());
populateHeaderAndAttachmentsFromResponse(exchange.getOut(), soapMessage);
} else {
exchange.getIn().setBody(soapMessage.getPayloadSource());
populateHeaderAndAttachmentsFromResponse(exchange.getIn(), soapMessage);
}
}
});
}
use of org.springframework.ws.WebServiceMessage in project spring-integration by spring-projects.
the class SimpleWebServiceInboundGateway method doInvoke.
@Override
protected void doInvoke(MessageContext messageContext) throws Exception {
WebServiceMessage request = messageContext.getRequest();
Assert.notNull(request, "Invalid message context: request was null.");
AbstractIntegrationMessageBuilder<?> builder = this.getMessageBuilderFactory().withPayload((this.extractPayload) ? request.getPayloadSource() : request);
this.fromSoapHeaders(messageContext, builder);
Message<?> replyMessage = this.sendAndReceiveMessage(builder.build());
if (replyMessage != null) {
Object replyPayload = replyMessage.getPayload();
Source responseSource = null;
if (replyPayload instanceof WebServiceMessage) {
messageContext.setResponse((WebServiceMessage) replyPayload);
} else {
if (replyPayload instanceof Source) {
responseSource = (Source) replyPayload;
} else if (replyPayload instanceof Document) {
responseSource = new DOMSource((Document) replyPayload);
} else if (replyPayload instanceof String) {
responseSource = new StringSource((String) replyPayload);
} else {
throw new IllegalArgumentException("The reply Message payload must be a [" + Source.class.getName() + "], [" + Document.class.getName() + "], [java.lang.String] or [" + WebServiceMessage.class.getName() + "]. " + "The actual type was [" + replyPayload.getClass().getName() + "]");
}
WebServiceMessage response = messageContext.getResponse();
this.transformerSupportDelegate.transformSourceToResult(responseSource, response.getPayloadResult());
toSoapHeaders(response, replyMessage);
}
}
}
use of org.springframework.ws.WebServiceMessage 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.WebServiceMessage in project spring-integration by spring-projects.
the class AbstractWebServiceInboundGateway method fromSoapHeaders.
protected void fromSoapHeaders(MessageContext messageContext, AbstractIntegrationMessageBuilder<?> builder) {
WebServiceMessage request = messageContext.getRequest();
String[] propertyNames = messageContext.getPropertyNames();
if (propertyNames != null) {
for (String propertyName : propertyNames) {
builder.setHeader(propertyName, messageContext.getProperty(propertyName));
}
}
if (request instanceof SoapMessage) {
SoapMessage soapMessage = (SoapMessage) request;
Map<String, ?> headers = this.headerMapper.toHeadersFromRequest(soapMessage);
if (!CollectionUtils.isEmpty(headers)) {
builder.copyHeaders(headers);
}
}
}
Aggregations