camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/4] camel git commit: An option (allowResponseHeaderOverride) added to allow soap header to be overwritten in in/out message in ws-producer from the soapHeader of underlying spring web service. Currently there is no way to replace this header from spri
Date Thu, 24 Nov 2016 08:35:36 GMT
An option (allowResponseHeaderOverride) added to allow soap header to be
overwritten in in/out message in ws-producer from the soapHeader of
underlying spring web service. Currently there is no way to replace this
header from spring web service. This option is added to give room for
the header part to be overwritten when the actual spring web service
appends or re-writes something in the soap header part.

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ec4c689e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ec4c689e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ec4c689e

Branch: refs/heads/camel-2.18.x
Commit: ec4c689e33bc4f529b0c4a878d8dec6e17691db2
Parents: 35a12b9
Author: srinivasavasu <srinivasavasu@dhcp-0-130.blr.redhat.com>
Authored: Thu Nov 24 11:51:01 2016 +0530
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Nov 24 09:35:24 2016 +0100

----------------------------------------------------------------------
 .../src/main/docs/spring-ws-component.adoc      |  3 +-
 .../ws/SpringWebserviceConfiguration.java       | 23 +++++-
 .../spring/ws/SpringWebserviceProducer.java     | 77 ++++++++++++++------
 3 files changed, 79 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ec4c689e/components/camel-spring-ws/src/main/docs/spring-ws-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-spring-ws/src/main/docs/spring-ws-component.adoc b/components/camel-spring-ws/src/main/docs/spring-ws-component.adoc
index 49dd449..4959c61 100644
--- a/components/camel-spring-ws/src/main/docs/spring-ws-component.adoc
+++ b/components/camel-spring-ws/src/main/docs/spring-ws-component.adoc
@@ -93,7 +93,7 @@ The Spring WebService component has no options.
 
 
 // endpoint options: START
-The Spring WebService component supports 23 endpoint options which are listed below:
+The Spring WebService component supports 24 endpoint options which are listed below:
 
 {% raw %}
 [width="100%",cols="2,1,1m,1m,5",options="header"]
@@ -110,6 +110,7 @@ The Spring WebService component supports 23 endpoint options which are
listed be
 | sslContextParameters | consumer |  | SSLContextParameters | To configure security using
SSLContextParameters
 | exceptionHandler | consumer (advanced) |  | ExceptionHandler | To let the consumer use
a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this options
is not in use. By default the consumer will deal with exceptions that will be logged at WARN/ERROR
level and ignored.
 | exchangePattern | consumer (advanced) |  | ExchangePattern | Sets the exchange pattern
when the consumer creates an exchange.
+| allowResponseHeaderOverride | producer | false | boolean | Option to override soap response
header in in/out exchange with header info from the actual service layer. If the invoked service
appends or rewrites the soap header this option when set to true allows the modified soap
header to be overwritten in in/out message headers
 | faultAction | producer |  | URI | Signifies the value for the faultAction response WS-Addressing
Fault Action header that is provided by the method.
 | faultTo | producer |  | URI | Signifies the value for the faultAction response WS-Addressing
FaultTo header that is provided by the method.
 | messageFactory | producer |  | WebServiceMessageFactory | Option to provide a custom WebServiceMessageFactory.
For example when you want Apache Axiom to handle web service messages instead of SAAJ.

http://git-wip-us.apache.org/repos/asf/camel/blob/ec4c689e/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConfiguration.java
b/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConfiguration.java
index a62e588..ae61fcc 100644
--- a/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConfiguration.java
+++ b/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConfiguration.java
@@ -70,6 +70,8 @@ public class SpringWebserviceConfiguration {
     private MessageIdStrategy messageIdStrategy;
     @UriParam(label = "producer")
     private int timeout = -1;
+    @UriParam(label = "producer")
+    private boolean allowResponseHeaderOverride;
 
     /* Consumer configuration */
     @UriParam(label = "consumer")
@@ -380,5 +382,24 @@ public class SpringWebserviceConfiguration {
     public void setMessageIdStrategy(MessageIdStrategy messageIdStrategy) {
         this.messageIdStrategy = messageIdStrategy;
     }
-    
+
+    /**
+     * @return boolean - true, will override header with spring-ws response message header
+     */
+    public boolean isAllowResponseHeaderOverride() {
+        return allowResponseHeaderOverride;
+    }
+
+    /**
+     * Option to override soap response header in in/out exchange with header info from the
actual service layer.
+     * If the invoked service appends or rewrites the soap header this option when set to
true, allows the modified
+     * soap header to be overwritten in in/out message headers
+     * 
+     * @param allowResponseHeaderOverride
+     *            - true, will override header with spring-ws response message header
+     */
+    public void setAllowResponseHeaderOverride(boolean allowResponseHeaderOverride) {
+        this.allowResponseHeaderOverride = allowResponseHeaderOverride;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/ec4c689e/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceProducer.java
b/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceProducer.java
index a4bef18..489397c 100644
--- a/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceProducer.java
+++ b/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceProducer.java
@@ -20,27 +20,29 @@ import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URI;
 import java.security.GeneralSecurityException;
+import java.util.Iterator;
 
 import javax.net.ssl.HttpsURLConnection;
 import javax.net.ssl.SSLContext;
+import javax.xml.namespace.QName;
 import javax.xml.transform.Source;
 import javax.xml.transform.TransformerException;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
+import org.apache.camel.Message;
 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;
 import org.slf4j.LoggerFactory;
 import org.springframework.ws.WebServiceMessage;
-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.SoapHeaderElement;
 import org.springframework.ws.soap.SoapMessage;
 import org.springframework.ws.soap.addressing.client.ActionCallback;
 import org.springframework.ws.soap.addressing.core.EndpointReference;
@@ -55,7 +57,6 @@ import org.springframework.ws.transport.http.HttpUrlConnectionMessageSender;
 public class SpringWebserviceProducer extends DefaultProducer {
 
     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) {
@@ -83,18 +84,59 @@ public class SpringWebserviceProducer extends DefaultProducer {
         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 (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(), responseMessage.getPayloadSource());
+                    if (soapMessage.getSoapHeader() != null && getEndpoint().getConfiguration().isAllowResponseHeaderOverride())
{
+                        populateMessageHeaderFromResponse(exchange.getOut(), soapMessage.getSoapHeader());
+                    }
+                } else {
+                    exchange.getIn().setBody(responseMessage.getPayloadSource());
+                    if (soapMessage.getSoapHeader() != null && getEndpoint().getConfiguration().isAllowResponseHeaderOverride())
{
+                        populateMessageHeaderFromResponse(exchange.getIn(), soapMessage.getSoapHeader());
+                    }
+                }
+
+            }
+        });
+    }
+
+    /**
+     * Populates message headers from soapHeader response
+     * 
+     * @param message
+     *            Message
+     * @param soapHeader
+     *            SoapHeader
+     */
+    private void populateMessageHeaderFromResponse(Message message, SoapHeader soapHeader)
{
+        message.setHeader(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();
+            message.getHeaders().put(name.getLocalPart(), soapHeader.getAttributeValue(name));
+        }
+
+        // Set header values for the soap header elements
+        Iterator<SoapHeaderElement> elementIter = soapHeader.examineAllHeaderElements();
+        while (elementIter.hasNext()) {
+            SoapHeaderElement element = elementIter.next();
+            QName name = element.getName();
+            message.getHeaders().put(name.getLocalPart(), element);
 
-        if (ExchangeHelper.isOutCapable(exchange)) {
-            exchange.getOut().copyFrom(exchange.getIn());
-            exchange.getOut().setBody(body);
-        } else {
-            exchange.getIn().setBody(body);
         }
     }
 
@@ -260,13 +302,4 @@ public class SpringWebserviceProducer extends DefaultProducer {
         }
     }
 
-    /**
-     * A {@link SourceExtractor} that performs no conversion, instead conversion
-     * is handled by Camel's {@link TypeConverter} hierarchy.
-     */
-    private static class NoopSourceExtractor implements SourceExtractor<Object> {
-        public Object extractData(Source source) throws IOException, TransformerException
{
-            return source;
-        }
-    }
 }


Mime
View raw message