You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/04/27 08:37:33 UTC
svn commit: r1476503 - in /camel/branches/camel-2.11.x: ./
components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/
components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/
components/camel-spring-ws/src/test...
Author: davsclaus
Date: Sat Apr 27 06:37:33 2013
New Revision: 1476503
URL: http://svn.apache.org/r1476503
Log:
CAMEL-4515: spring-ws now supports SOAP header to/from Camel Message so end users can set/access it. Thanks to Damian for the patch.
Added:
camel/branches/camel-2.11.x/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/SoapHeaderResponseProcessor.java
- copied unchanged from r1476502, camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/SoapHeaderResponseProcessor.java
camel/branches/camel-2.11.x/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/SoapHeaderTest.java
- copied unchanged from r1476502, camel/trunk/components/camel-spring-ws/src/test/java/org/apache/camel/component/spring/ws/SoapHeaderTest.java
camel/branches/camel-2.11.x/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/SoapHeaderTest-context.xml
- copied unchanged from r1476502, camel/trunk/components/camel-spring-ws/src/test/resources/org/apache/camel/component/spring/ws/SoapHeaderTest-context.xml
Modified:
camel/branches/camel-2.11.x/ (props changed)
camel/branches/camel-2.11.x/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConstants.java
camel/branches/camel-2.11.x/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConsumer.java
camel/branches/camel-2.11.x/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceProducer.java
Propchange: camel/branches/camel-2.11.x/
------------------------------------------------------------------------------
Merged /camel/trunk:r1476502
Propchange: camel/branches/camel-2.11.x/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Sat Apr 27 06:37:33 2013
@@ -1 +1 @@
-/camel/trunk:1-1468763,1469704,1469819,1470420,1470426-1470427,1470429,1470508,1471293,1471330,1471407-1471408,1471543,1475657,1475677,1475742,1475786,1476113,1476428,1476442
+/camel/trunk:1-1468763,1469704,1469819,1470420,1470426-1470427,1470429,1470508,1471293,1471330,1471407-1471408,1471543,1475657,1475677,1475742,1475786,1476113,1476428,1476442,1476502
Modified: camel/branches/camel-2.11.x/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConstants.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.11.x/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConstants.java?rev=1476503&r1=1476502&r2=1476503&view=diff
==============================================================================
--- camel/branches/camel-2.11.x/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConstants.java (original)
+++ camel/branches/camel-2.11.x/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConstants.java Sat Apr 27 06:37:33 2013
@@ -18,14 +18,14 @@ package org.apache.camel.component.sprin
public final class SpringWebserviceConstants {
- /* Producer constants */
public static final String SPRING_WS_ENDPOINT_URI = "CamelSpringWebserviceEndpointUri";
+
public static final String SPRING_WS_SOAP_ACTION = "CamelSpringWebserviceSoapAction";
+ public static final String SPRING_WS_SOAP_HEADER = "CamelSpringWebserviceSoapHeader";
+
public static final String SPRING_WS_ADDRESSING_ACTION = "CamelSpringWebserviceAddressingAction";
public static final String SPRING_WS_ADDRESSING_PRODUCER_FAULT_TO = "CamelSpringWebserviceAddressingFaultTo";
public static final String SPRING_WS_ADDRESSING_PRODUCER_REPLY_TO = "CamelSpringWebserviceAddressingReplyTo";
-
- /* Consumers constants (reserved, not impl. yet) */
public static final String SPRING_WS_ADDRESSING_CONSUMER_OUTPUT_ACTION = "CamelSpringWebserviceAddressingOutputAction";
public static final String SPRING_WS_ADDRESSING_CONSUMER_FAULT_ACTION = "CamelSpringWebserviceAddressingFaultAction";
Modified: camel/branches/camel-2.11.x/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConsumer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.11.x/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConsumer.java?rev=1476503&r1=1476502&r2=1476503&view=diff
==============================================================================
--- camel/branches/camel-2.11.x/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConsumer.java (original)
+++ camel/branches/camel-2.11.x/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConsumer.java Sat Apr 27 06:37:33 2013
@@ -16,7 +16,6 @@
*/
package org.apache.camel.component.spring.ws;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -66,9 +65,9 @@ public class SpringWebserviceConsumer ex
if (responseMessage != null) {
Source responseBody = responseMessage.getBody(Source.class);
WebServiceMessage response = messageContext.getResponse();
-
+
configuration.getMessageFilter().filterConsumer(exchange, response);
-
+
XmlConverter xmlConverter = configuration.getXmlConverter();
xmlConverter.toResult(responseBody, response.getPayloadResult());
}
@@ -81,7 +80,7 @@ public class SpringWebserviceConsumer ex
// create inbound message
WebServiceMessage request = messageContext.getRequest();
SpringWebserviceMessage inMessage = new SpringWebserviceMessage(request);
- inMessage.setHeaders(extractSoapHeadersFromWebServiceMessage(request));
+ extractSourceFromSoapHeader(inMessage.getHeaders(), request);
exchange.setIn(inMessage);
}
@@ -96,28 +95,40 @@ public class SpringWebserviceConsumer ex
}
}
- private Map<String, Object> extractSoapHeadersFromWebServiceMessage(WebServiceMessage request) {
- Map<String, Object> headers = new HashMap<String, Object>();
+ /**
+ * Extracts the SOAP headers and set them as headers in the Exchange. Also sets
+ * it as a header with the key SpringWebserviceConstants.SPRING_WS_SOAP_HEADER
+ * and a value of type Source.
+ *
+ * @param headers the Exchange Headers
+ * @param request the WebService Request
+ */
+ private void extractSourceFromSoapHeader(Map<String, Object> headers, WebServiceMessage request) {
if (request instanceof SoapMessage) {
SoapMessage soapMessage = (SoapMessage) request;
SoapHeader soapHeader = soapMessage.getSoapHeader();
+
if (soapHeader != null) {
- Iterator<?> attibutesIterator = soapHeader.getAllAttributes();
- while (attibutesIterator.hasNext()) {
- QName name = (QName) attibutesIterator.next();
- headers.put(name.toString(), soapHeader.getAttributeValue(name));
+ //Set the raw soap header as a header in the exchange.
+ headers.put(SpringWebserviceConstants.SPRING_WS_SOAP_HEADER, soapHeader.getSource());
+
+ //Set header values for the soap header attributes
+ Iterator<QName> attIter = soapHeader.getAllAttributes();
+ while (attIter.hasNext()) {
+ QName name = attIter.next();
+ headers.put(name.getLocalPart(), soapHeader.getAttributeValue(name));
}
- Iterator<?> elementIter = soapHeader.examineAllHeaderElements();
+
+ //Set header values for the soap header elements
+ Iterator<SoapHeaderElement> elementIter = soapHeader.examineAllHeaderElements();
while (elementIter.hasNext()) {
- Object element = elementIter.next();
- if (element instanceof SoapHeaderElement) {
- QName name = ((SoapHeaderElement) element).getName();
- headers.put(name.toString(), element);
- }
+ SoapHeaderElement element = elementIter.next();
+ QName name = element.getName();
+ headers.put(name.getLocalPart(), element);
+
}
}
}
- return headers;
}
@Override
Modified: camel/branches/camel-2.11.x/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.11.x/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceProducer.java?rev=1476503&r1=1476502&r2=1476503&view=diff
==============================================================================
--- camel/branches/camel-2.11.x/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceProducer.java (original)
+++ camel/branches/camel-2.11.x/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceProducer.java Sat Apr 27 06:37:33 2013
@@ -30,6 +30,7 @@ import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.TypeConverter;
+import org.apache.camel.converter.jaxp.XmlConverter;
import org.apache.camel.impl.DefaultProducer;
import org.apache.camel.util.ExchangeHelper;
import org.slf4j.Logger;
@@ -38,6 +39,8 @@ import org.springframework.ws.WebService
import org.springframework.ws.client.core.SourceExtractor;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.ws.client.core.WebServiceTemplate;
+import org.springframework.ws.soap.SoapHeader;
+import org.springframework.ws.soap.SoapMessage;
import org.springframework.ws.soap.addressing.client.ActionCallback;
import org.springframework.ws.soap.addressing.core.EndpointReference;
import org.springframework.ws.soap.client.core.SoapActionCallback;
@@ -52,6 +55,7 @@ public class SpringWebserviceProducer ex
private static final Logger LOG = LoggerFactory.getLogger(SpringWebserviceProducer.class);
private static final SourceExtractor<Object> SOURCE_EXTRACTOR = new NoopSourceExtractor();
+ private static final XmlConverter XML_CONVERTER = new XmlConverter();
public SpringWebserviceProducer(Endpoint endpoint) {
super(endpoint);
@@ -73,15 +77,18 @@ public class SpringWebserviceProducer ex
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, getEndpoint().getConfiguration(), exchange);
- Object body = null;
+ WebServiceMessageCallback callback = new DefaultWebserviceMessageCallback(soapActionHeader, wsAddressingActionHeader,
+ wsReplyToHeader, wsFaultToHeader, soapHeaderSource, getEndpoint().getConfiguration(), exchange);
+
+ Object body;
if (endpointUriHeader != null) {
body = getEndpoint().getConfiguration().getWebServiceTemplate().sendSourceAndReceive(endpointUriHeader, sourcePayload, callback, SOURCE_EXTRACTOR);
} else {
body = getEndpoint().getConfiguration().getWebServiceTemplate().sendSourceAndReceive(sourcePayload, callback, SOURCE_EXTRACTOR);
}
+
if (ExchangeHelper.isOutCapable(exchange)) {
exchange.getOut().copyFrom(exchange.getIn());
exchange.getOut().setBody(body);
@@ -99,19 +106,19 @@ public class SpringWebserviceProducer ex
WebServiceTemplate webServiceTemplate = configuration.getWebServiceTemplate();
WebServiceMessageSender[] messageSenders = webServiceTemplate.getMessageSenders();
-
+
for (int i = 0; i < messageSenders.length; i++) {
WebServiceMessageSender messageSender = messageSenders[i];
if (messageSender instanceof CommonsHttpMessageSender) {
if (configuration.getSslContextParameters() != null) {
LOG.warn("Not applying SSLContextParameters based configuration to CommonsHttpMessageSender. "
- + "If you are using this MessageSender, which you are not by default, you will need "
- + "to configure SSL using the Commons HTTP 3.x Protocol registry.");
+ + "If you are using this MessageSender, which you are not by default, you will need "
+ + "to configure SSL using the Commons HTTP 3.x Protocol registry.");
}
-
+
if (configuration.getTimeout() > -1) {
if (messageSender.getClass().equals(CommonsHttpMessageSender.class)) {
- ((CommonsHttpMessageSender)messageSender).setReadTimeout(configuration.getTimeout());
+ ((CommonsHttpMessageSender) messageSender).setReadTimeout(configuration.getTimeout());
} else {
LOG.warn("Not applying timeout configuration to CommonsHttpMessageSender based implementation. "
+ "You are using what appears to be a custom MessageSender, which you are not doing by default. "
@@ -121,7 +128,7 @@ public class SpringWebserviceProducer ex
} else if (messageSender.getClass().equals(HttpUrlConnectionMessageSender.class)) {
// Only if exact match denoting likely use of default configuration. We don't want to get
// sub-classes that might have been otherwise injected.
- messageSenders[i] = new AbstractHttpWebServiceMessageSenderDecorator((HttpUrlConnectionMessageSender)messageSender, configuration);
+ messageSenders[i] = new AbstractHttpWebServiceMessageSenderDecorator((HttpUrlConnectionMessageSender) messageSender, configuration);
} else {
// For example this will be the case during unit-testing with the net.javacrumbs.spring-ws-test API
LOG.warn("Ignoring the timeout and SSLContextParameters options for {}. You will need to configure "
@@ -129,20 +136,20 @@ public class SpringWebserviceProducer ex
}
}
}
-
+
/**
* A decorator of {@link HttpUrlConnectionMessageSender} instances that can apply configuration options
* from the Camel component/endpoint configuration without replacing the actual implementation which may
* actually be an end-user implementation and not one of the built-in implementations.
*/
protected static final class AbstractHttpWebServiceMessageSenderDecorator extends AbstractHttpWebServiceMessageSender {
-
+
private final AbstractHttpWebServiceMessageSender delegate;
-
+
private final SpringWebserviceConfiguration configuration;
-
+
private SSLContext sslContext;
-
+
public AbstractHttpWebServiceMessageSenderDecorator(AbstractHttpWebServiceMessageSender delegate, SpringWebserviceConfiguration configuration) {
this.delegate = delegate;
this.configuration = configuration;
@@ -152,12 +159,12 @@ public class SpringWebserviceProducer ex
public WebServiceConnection createConnection(URI uri) throws IOException {
WebServiceConnection wsc = delegate.createConnection(uri);
if (wsc instanceof HttpUrlConnection) {
- HttpURLConnection connection = ((HttpUrlConnection)wsc).getConnection();
-
+ HttpURLConnection connection = ((HttpUrlConnection) wsc).getConnection();
+
if (configuration.getTimeout() > -1) {
connection.setReadTimeout(configuration.getTimeout());
}
-
+
if (configuration.getSslContextParameters() != null && connection instanceof HttpsURLConnection) {
try {
synchronized (this) {
@@ -168,14 +175,14 @@ public class SpringWebserviceProducer ex
} catch (GeneralSecurityException e) {
throw new RuntimeCamelException("Error creating SSLContext based on SSLContextParameters.", e);
}
-
+
((HttpsURLConnection) connection).setSSLSocketFactory(sslContext.getSocketFactory());
}
} else {
throw new RuntimeCamelException("Unsupported delegate. Delegate must return a org.springframework.ws.transport.http.HttpUrlConnection. Found "
+ wsc.getClass());
}
-
+
return wsc;
}
@@ -200,14 +207,17 @@ public class SpringWebserviceProducer ex
private final URI wsAddressingActionHeader;
private final URI wsReplyToHeader;
private final URI wsFaultToHeader;
+ private final Source soapHeaderSource;
private final SpringWebserviceConfiguration configuration;
private final Exchange exchange;
- public DefaultWebserviceMessageCallback(String soapAction, URI wsAddressingAction, URI wsReplyTo, URI wsFaultTo, SpringWebserviceConfiguration configuration, Exchange exchange) {
+ public DefaultWebserviceMessageCallback(String soapAction, URI wsAddressingAction, URI wsReplyTo, URI wsFaultTo, Source soapHeaderSource,
+ SpringWebserviceConfiguration configuration, Exchange exchange) {
this.soapActionHeader = soapAction;
this.wsAddressingActionHeader = wsAddressingAction;
this.wsReplyToHeader = wsReplyTo;
this.wsFaultToHeader = wsFaultTo;
+ this.soapHeaderSource = soapHeaderSource;
this.configuration = configuration;
this.exchange = exchange;
}
@@ -225,7 +235,13 @@ public class SpringWebserviceProducer ex
URI wsAddressingAction = wsAddressingActionHeader != null ? wsAddressingActionHeader : configuration.getWsAddressingAction();
URI wsReplyTo = wsReplyToHeader != null ? wsReplyToHeader : configuration.getReplyTo();
URI wsFaultTo = wsFaultToHeader != null ? wsFaultToHeader : configuration.getFaultTo();
-
+
+ // Create the SOAP header
+ if (soapHeaderSource != null) {
+ SoapHeader header = ((SoapMessage) message).getSoapHeader();
+ XML_CONVERTER.toResult(soapHeaderSource, header.getResult());
+ }
+
if (wsAddressingAction != null) {
ActionCallback actionCallback = new ActionCallback(wsAddressingAction);
if (wsReplyTo != null) {
@@ -237,7 +253,7 @@ public class SpringWebserviceProducer ex
}
actionCallback.doWithMessage(message);
}
-
+
configuration.getMessageFilter().filterProducer(exchange, message);
}
}