camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ricke...@apache.org
Subject [1/2] git commit: CAMEL-7231: Support receiving attachments with Spring-WS
Date Mon, 17 Mar 2014 14:46:20 GMT
Repository: camel
Updated Branches:
  refs/heads/master 3e7dbf574 -> 6a23191c8


CAMEL-7231: Support receiving attachments with Spring-WS


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

Branch: refs/heads/master
Commit: fd8bfb691ef3000e7f763895b943377da3ea96d3
Parents: f105ac2
Author: Richard Kettelerij <r.kettelerij@avisi.nl>
Authored: Mon Mar 17 15:45:10 2014 +0100
Committer: Richard Kettelerij <r.kettelerij@avisi.nl>
Committed: Mon Mar 17 15:45:10 2014 +0100

----------------------------------------------------------------------
 .../spring/ws/SpringWebserviceConsumer.java     | 25 ++++++++++++++++----
 1 file changed, 20 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/fd8bfb69/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConsumer.java
b/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConsumer.java
index 4a5ee7d..5514ff5 100644
--- a/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConsumer.java
+++ b/components/camel-spring-ws/src/main/java/org/apache/camel/component/spring/ws/SpringWebserviceConsumer.java
@@ -32,6 +32,8 @@ import org.apache.camel.impl.DefaultConsumer;
 import org.apache.camel.impl.DefaultExchange;
 import org.springframework.ws.WebServiceMessage;
 import org.springframework.ws.context.MessageContext;
+import org.springframework.ws.mime.Attachment;
+import org.springframework.ws.mime.MimeMessage;
 import org.springframework.ws.server.endpoint.MessageEndpoint;
 import org.springframework.ws.soap.SoapHeader;
 import org.springframework.ws.soap.SoapHeaderElement;
@@ -44,7 +46,7 @@ public class SpringWebserviceConsumer extends DefaultConsumer implements
Message
 
     public SpringWebserviceConsumer(Endpoint endpoint, Processor processor) {
         super(endpoint, processor);
-        this.endpoint = (SpringWebserviceEndpoint) endpoint;
+        this.endpoint = (SpringWebserviceEndpoint)endpoint;
         this.configuration = this.endpoint.getConfiguration();
     }
 
@@ -81,10 +83,12 @@ public class SpringWebserviceConsumer extends DefaultConsumer implements
Message
         WebServiceMessage request = messageContext.getRequest();
         SpringWebserviceMessage inMessage = new SpringWebserviceMessage(request);
         extractSourceFromSoapHeader(inMessage.getHeaders(), request);
+        extractAttachmentsFromRequest(request, inMessage);
         exchange.setIn(inMessage);
     }
 
-    private void populateExchangeWithPropertiesFromMessageContext(MessageContext messageContext,
Exchange exchange) {
+    private void populateExchangeWithPropertiesFromMessageContext(MessageContext messageContext,
+                                                                  Exchange exchange) {
         // convert WebserviceMessage properties (added through interceptors) to
         // Camel exchange properties
         String[] propertyNames = messageContext.getPropertyNames();
@@ -100,12 +104,12 @@ public class SpringWebserviceConsumer extends DefaultConsumer implements
Message
      * 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
+     * @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;
+            SoapMessage soapMessage = (SoapMessage)request;
             SoapHeader soapHeader = soapMessage.getSoapHeader();
 
             if (soapHeader != null) {
@@ -131,6 +135,17 @@ public class SpringWebserviceConsumer extends DefaultConsumer implements
Message
         }
     }
 
+    private void extractAttachmentsFromRequest(final WebServiceMessage request,
+                                               final SpringWebserviceMessage inMessage) {
+        if (request instanceof MimeMessage) {
+            Iterator<Attachment> attachmentsIterator = ((MimeMessage)request).getAttachments();
+            while (attachmentsIterator.hasNext()) {
+                Attachment attachment = attachmentsIterator.next();
+                inMessage.addAttachment(attachment.getContentId(), attachment.getDataHandler());
+            }
+        }
+    }
+
     @Override
     protected void doStop() throws Exception {
         if (configuration.getEndpointMapping() != null) {


Mime
View raw message