camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject svn commit: r830701 - in /camel/trunk/components/camel-cxf/src: main/java/org/apache/camel/component/cxf/ main/java/org/apache/camel/component/cxf/interceptors/ test/java/org/apache/camel/component/cxf/ test/java/org/apache/camel/component/cxf/mtom/ te...
Date Wed, 28 Oct 2009 17:52:35 GMT
Author: wtam
Date: Wed Oct 28 17:52:34 2009
New Revision: 830701

URL: http://svn.apache.org/viewvc?rev=830701&view=rev
Log:
[CAMEL-2114] camel-cxf MTOM support in PAYLOAD mode

Added:
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/MtomOutInterceptor.java   (with props)
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomConsumerPayloadModeTest.java   (with props)
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomConsumerTest.java   (contents, props changed)
      - copied, changed from r829124, camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMtomConsumerTest.java
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomProducerPayloadModeTest.java   (with props)
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomRouterPayloadModeTest.java   (with props)
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/HelloImpl.java   (with props)
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/MtomTestHelper.java   (with props)
    camel/trunk/components/camel-cxf/src/test/resources/Splash.jpg   (with props)
    camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/
    camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomConsumerPayloadModeTest-context.xml   (with props)
    camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomProducerPayloadModeTest-context.xml   (with props)
    camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomRouterPayloadModeTest-context.xml   (with props)
Removed:
    camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMtomConsumerTest.java
Modified:
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
    camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/DOMOutInterceptor.java

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java?rev=830701&r1=830700&r2=830701&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConstants.java Wed Oct 28 17:52:34 2009
@@ -46,6 +46,7 @@
     String CAMEL_CXF_RS_VAR_VALUES = "CamelCxfRsVarValues";
     String CAMEL_CXF_RS_RESPONSE_CLASS = "CamelCxfRsResponseClass";
     String CAMEL_CXF_RS_OPERATION_RESOURCE_INFO_STACK = "CamelCxfRsOperationResourceInfoStack";
+    String ATTACHMENTS_PROP_KEY = "CamelAttachments";
 }
 
 

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java?rev=830701&r1=830700&r2=830701&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfEndpoint.java Wed Oct 28 17:52:34 2009
@@ -17,6 +17,7 @@
 package org.apache.camel.component.cxf;
 
 import java.lang.reflect.Proxy;
+import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicBoolean;
 
@@ -51,6 +52,7 @@
 import org.apache.cxf.jaxws.JaxWsClientFactoryBean;
 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
 import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
+import org.apache.cxf.message.Attachment;
 import org.apache.cxf.message.Message;
 
 /**
@@ -176,7 +178,7 @@
             @Override
             protected void createClient(Endpoint ep) {
                 setClient(new CamelCxfClientImpl(getBus(), ep));
-            }    
+            }
             
             @Override
             protected void initializeAnnotationInterceptors(Endpoint ep, Class<?> cls) {
@@ -463,8 +465,16 @@
             super(bus, ep);
         }
         
+        @SuppressWarnings("unchecked")
         @Override
         protected void setParameters(Object[] params, Message message) {
+            
+            Object attachements = message.get(CxfConstants.ATTACHMENTS_PROP_KEY);
+            if (attachements != null) {
+                message.setAttachments((Collection<Attachment>)attachements);
+                message.remove(CxfConstants.ATTACHMENTS_PROP_KEY);
+            }
+            
             if (DataFormat.PAYLOAD == message.get(DataFormat.class)) {
                 CxfPayload<?> payload = (CxfPayload<?>)params[0];
                 message.put(List.class, payload.getBody());
@@ -472,6 +482,8 @@
             } else {
                 super.setParameters(params, message);
             }
+            
+            message.remove(DataFormat.class);
         }
     }
 }

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java?rev=830701&r1=830700&r2=830701&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java Wed Oct 28 17:52:34 2009
@@ -20,10 +20,12 @@
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import javax.activation.DataHandler;
 import javax.xml.namespace.QName;
 
 import org.w3c.dom.Element;
@@ -34,6 +36,7 @@
 import org.apache.camel.spi.HeaderFilterStrategyAware;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.cxf.attachment.AttachmentImpl;
 import org.apache.cxf.binding.soap.SoapHeader;
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.endpoint.Endpoint;
@@ -41,6 +44,7 @@
 import org.apache.cxf.headers.Header;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
+import org.apache.cxf.message.Attachment;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageContentsList;
 import org.apache.cxf.service.Service;
@@ -81,6 +85,20 @@
         propagateHeadersFromCamelToCxf(camelExchange, camelHeaders, cxfExchange, 
                 requestContext);
         
+        // propagate attachments
+        Set<Attachment> attachments = null;
+        for (Map.Entry<String, DataHandler> entry : camelExchange.getIn().getAttachments().entrySet()) {
+            if (attachments == null) {
+                attachments = new HashSet<Attachment>();
+            }
+            AttachmentImpl attachment = new AttachmentImpl(entry.getKey(), entry.getValue());
+            attachment.setXOP(true); // only supports MTOM
+            attachments.add(attachment);
+        }
+        
+        if (attachments != null) {
+            requestContext.put(CxfConstants.ATTACHMENTS_PROP_KEY, attachments);
+        }
     }
     
     /**
@@ -113,6 +131,21 @@
         
         // propagate protocol headers
         propagateHeadersFromCxfToCamel(cxfMessage, camelExchange.getOut(), camelExchange);
+        
+        if (cxfMessage.getAttachments() != null) {
+            // TODO: workaround for CXF-2503
+            try {
+                cxfMessage.getAttachments().size();
+            } catch (java.util.ConcurrentModificationException e) {
+                // ignore
+            }
+            // end of workaround
+
+            // propagate attachments
+            for (Attachment attachment : cxfMessage.getAttachments()) {
+                camelExchange.getOut().addAttachment(attachment.getId(), attachment.getDataHandler());
+            }        
+        }
     }
     
     /**
@@ -197,6 +230,13 @@
         if (body != null) {
             camelExchange.getIn().setBody(body);
         }  
+        
+        // propagate attachments
+        if (cxfMessage.getAttachments() != null) {
+            for (Attachment attachment : cxfMessage.getAttachments()) {
+                camelExchange.getIn().addAttachment(attachment.getId(), attachment.getDataHandler());
+            }
+        }
     }
 
     /**
@@ -267,6 +307,21 @@
                 }
             }
         }         
+        
+        // propagate attachments
+        Set<Attachment> attachments = null;
+        for (Map.Entry<String, DataHandler> entry : camelExchange.getOut().getAttachments().entrySet()) {
+            if (attachments == null) {
+                attachments = new HashSet<Attachment>();
+            }
+            AttachmentImpl attachment = new AttachmentImpl(entry.getKey(), entry.getValue());
+            attachment.setXOP(true); // only supports MTOM
+            attachments.add(attachment);
+        }
+        
+        if (attachments != null) {
+            outMessage.setAttachments(attachments);
+        }
        
         BindingOperationInfo boi = cxfExchange.get(BindingOperationInfo.class);
         if (boi != null) {

Modified: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/DOMOutInterceptor.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/DOMOutInterceptor.java?rev=830701&r1=830700&r2=830701&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/DOMOutInterceptor.java (original)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/DOMOutInterceptor.java Wed Oct 28 17:52:34 2009
@@ -39,7 +39,6 @@
         this.addBefore(MessageSenderInterceptor.class.getName());
     }
     
-    @SuppressWarnings("unchecked")
     public void handleMessage(Message message) throws Fault {
         if (message instanceof XMLMessage) {
             xmlInterceptor.handleMessage((XMLMessage)message);

Added: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/MtomOutInterceptor.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/MtomOutInterceptor.java?rev=830701&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/MtomOutInterceptor.java (added)
+++ camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/MtomOutInterceptor.java Wed Oct 28 17:52:34 2009
@@ -0,0 +1,265 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.cxf.interceptors;
+
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.MediaTracker;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.UUID;
+import java.util.logging.Logger;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.imageio.ImageIO;
+import javax.imageio.ImageWriter;
+import javax.imageio.stream.ImageOutputStream;
+import javax.mail.util.ByteArrayDataSource;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.cxf.attachment.AttachmentImpl;
+import org.apache.cxf.binding.soap.SoapMessage;
+import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
+import org.apache.cxf.binding.soap.model.SoapBodyInfo;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.interceptor.AttachmentOutInterceptor;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.message.Attachment;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.service.model.BindingMessageInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.cxf.staxutils.StaxUtils;
+
+/**
+ *
+ * @version $Revision$
+ */
+public class MtomOutInterceptor extends AbstractSoapInterceptor {
+    private static final Logger LOG = LogUtils.getL7dLogger(MtomOutInterceptor.class);
+
+    public MtomOutInterceptor() {
+        super(Phase.PREPARE_SEND);
+        this.addBefore(DOMOutInterceptor.class.getName());
+    }
+
+    public void handleMessage(SoapMessage message) throws Fault {
+
+        Exchange ex = message.getExchange();
+        BindingOperationInfo bop = ex.get(BindingOperationInfo.class);
+        if (bop == null) {
+            return;
+        }
+        
+        if (bop.isUnwrapped()) {
+            bop = bop.getWrappedOperation();
+        }
+        
+        boolean client = isRequestor(message);
+        BindingMessageInfo bmi = client ? bop.getInput() : bop.getOutput();
+        
+        if (bmi == null) {
+            return;
+        }
+        
+        SoapBodyInfo sbi = bmi.getExtensor(SoapBodyInfo.class);
+        processAttachments(message, sbi);
+
+    }
+
+
+    protected void processAttachments(SoapMessage message, SoapBodyInfo sbi) {
+        Collection<Attachment> atts = setupAttachmentOutput(message);
+        List<Object> outObjects = CastUtils.cast(message.getContent(List.class));
+        
+        for (MessagePartInfo mpi : sbi.getAttachments()) {
+            String partName = mpi.getConcreteName().getLocalPart();
+            String ct = (String) mpi.getProperty(Message.CONTENT_TYPE);
+            
+            String id = new StringBuilder().append(partName)
+                .append("=")
+                .append(UUID.randomUUID())
+                .append("@apache.org").toString();
+            
+            // this assumes things are in order...
+            int idx = mpi.getIndex();
+            Object o = outObjects.get(idx);
+            
+            if (o == null) {
+                continue;
+            }
+            outObjects.set(idx, null);
+            DataHandler dh = null;
+            
+            // This code could probably be refactored out somewhere...
+            if (o instanceof Source) {
+                dh = new DataHandler(createDataSource((Source)o, ct));
+            } else if (o instanceof Image) {
+                // TODO: make this streamable. This is one of my pet
+                // peeves in JAXB RI as well, so if you fix this, submit the 
+                // code to the JAXB RI as well (see RuntimeBuiltinLeafInfoImpl)! - DD
+                ByteArrayOutputStream bos = new ByteArrayOutputStream(2048);
+                Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(ct);
+                if (writers.hasNext()) {
+                    ImageWriter writer = writers.next();
+                    
+                    try {
+                        BufferedImage bimg = convertToBufferedImage((Image) o);
+                        ImageOutputStream out = ImageIO.createImageOutputStream(bos); 
+                        writer.setOutput(out);
+                        writer.write(bimg);
+                        writer.dispose();
+                        out.flush();
+                        out.close();
+                        bos.close();
+                    } catch (IOException e) {
+                        throw new Fault(e);
+                    }
+                } else {
+                    throw new Fault(new org.apache.cxf.common.i18n.Message("ATTACHMENT_NOT_SUPPORTED", 
+                                     LOG, ct));                    
+                }
+                
+                dh = new DataHandler(new ByteArrayDataSource(bos.toByteArray(), ct));
+            } else if (o instanceof DataHandler) {
+                dh = (DataHandler) o;
+                ct = dh.getContentType();
+                
+                try {
+                    if ("text/xml".equals(ct)
+                        && dh.getContent() instanceof Source) {
+                        dh = new DataHandler(createDataSource((Source)dh.getContent(), ct));
+                    }
+                } catch (IOException e) {
+                    //ignore, use same dh
+                }
+            } else if (o instanceof byte[]) {
+                if (ct == null) {
+                    ct = "application/octet-stream";
+                }
+                dh = new DataHandler(new ByteArrayDataSource((byte[])o, ct));                
+            } else if (o instanceof String) {
+                if (ct == null) {
+                    ct = "text/plain; charset=\'UTF-8\'";
+                }
+                try {
+                    dh = new DataHandler(new ByteArrayDataSource((String)o, ct));
+                } catch (IOException e) {
+                    throw new Fault(e);
+                }                
+            } else {
+                throw new Fault(new org.apache.cxf.common.i18n.Message("ATTACHMENT_NOT_SUPPORTED", 
+                                                                       LOG, o.getClass()));
+            }
+            
+            AttachmentImpl att = new AttachmentImpl(id);
+            att.setDataHandler(dh);
+            att.setHeader("Content-Type", ct);
+            atts.add(att);
+        }
+    }
+    
+    private Collection<Attachment> setupAttachmentOutput(SoapMessage message) {
+        // We have attachments, so add the interceptor
+        message.getInterceptorChain().add(new AttachmentOutInterceptor());
+        // We should probably come up with another property for this
+        message.put(AttachmentOutInterceptor.WRITE_ATTACHMENTS, Boolean.TRUE);
+        
+        
+        Collection<Attachment> atts = message.getAttachments();
+        if (atts == null) {
+            atts = new ArrayList<Attachment>();
+            message.setAttachments(atts);
+        }
+        return atts;
+    }
+    
+    private BufferedImage convertToBufferedImage(Image image) throws IOException {
+        if (image instanceof BufferedImage) {
+            return (BufferedImage)image;
+        }
+        
+        // Wait until the image is completely loaded
+        MediaTracker tracker = new MediaTracker(new Component() { });
+        tracker.addImage(image, 0);
+        try {
+            tracker.waitForAll();
+        } catch (InterruptedException e) {
+            throw new Fault(e);
+        }
+        
+        // Create a BufferedImage so we can write it out later
+        BufferedImage bufImage = new BufferedImage(
+                image.getWidth(null),
+                image.getHeight(null),
+                BufferedImage.TYPE_INT_ARGB);
+
+        Graphics g = bufImage.createGraphics();
+        g.drawImage(image, 0, 0, null);
+        return bufImage;
+    }
+    
+    
+    private DataSource createDataSource(Source o, String ct) {
+        DataSource ds = null;
+        
+        if (o instanceof StreamSource) {
+            StreamSource src = (StreamSource)o;
+            try {
+                if (src.getInputStream() != null) {
+                    ByteArrayOutputStream bos = new ByteArrayOutputStream(2048);
+                    IOUtils.copy(src.getInputStream(), bos, 1024);
+                    ds = new ByteArrayDataSource(bos.toByteArray(), ct);
+                } else {
+                    ds = new ByteArrayDataSource(IOUtils.toString(src.getReader()),
+                                                 ct);                            
+                }
+            } catch (IOException e) {
+                throw new Fault(e);
+            }
+        } else {
+            StringWriter stringWriter = new StringWriter();
+            XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(stringWriter);
+            try {
+                StaxUtils.copy((Source)o, writer);
+                writer.flush();
+                ds = new ByteArrayDataSource(stringWriter.toString(), ct);
+            } catch (XMLStreamException e1) {
+                throw new Fault(e1);
+            } catch (IOException e) {
+                throw new Fault(e);
+            }
+        }
+        return ds;
+    }
+
+}

Propchange: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/MtomOutInterceptor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/interceptors/MtomOutInterceptor.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomConsumerPayloadModeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomConsumerPayloadModeTest.java?rev=830701&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomConsumerPayloadModeTest.java (added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomConsumerPayloadModeTest.java Wed Oct 28 17:52:34 2009
@@ -0,0 +1,125 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.cxf.mtom;
+
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.activation.DataHandler;
+import javax.mail.util.ByteArrayDataSource;
+import javax.xml.xpath.XPathConstants;
+
+import org.w3c.dom.Element;
+
+import junit.framework.Assert;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.component.cxf.CxfPayload;
+import org.apache.cxf.binding.soap.SoapHeader;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.helpers.XPathUtils;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+/**
+* Unit test for exercising MTOM feature of a CxfConsumer in PAYLOAD mode
+* 
+* @version $Revision$
+*/
+@ContextConfiguration
+public class CxfMtomConsumerPayloadModeTest extends AbstractJUnit4SpringContextTests {
+
+    @Autowired
+    protected CamelContext context;
+    
+    @Test
+    public void testConsumer() throws Exception {
+        context.createProducerTemplate().send("cxf:bean:consumerEndpoint", new Processor() {
+
+            public void process(Exchange exchange) throws Exception {
+                exchange.setPattern(ExchangePattern.InOut);
+                List<Element> elements = new ArrayList<Element>();
+                elements.add(DOMUtils.readXml(new StringReader(MtomTestHelper.REQ_MESSAGE)).getDocumentElement());
+                CxfPayload<SoapHeader> body = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(),
+                    elements);
+                exchange.getIn().setBody(body);
+                exchange.getIn().addAttachment(MtomTestHelper.REQ_PHOTO_CID, 
+                    new DataHandler(new ByteArrayDataSource(MtomTestHelper.REQ_PHOTO_DATA, "application/octet-stream")));
+
+                exchange.getIn().addAttachment(MtomTestHelper.REQ_IMAGE_CID, 
+                    new DataHandler(new ByteArrayDataSource(MtomTestHelper.requestJpeg, "image/jpeg")));
+            }
+        });
+    }
+
+   
+    public static class MyProcessor implements Processor {
+
+        @SuppressWarnings("unchecked")
+        public void process(Exchange exchange) throws Exception {
+            CxfPayload<SoapHeader> in = exchange.getIn().getBody(CxfPayload.class);
+            
+            // verify request
+            Assert.assertEquals(1, in.getBody().size());
+            
+            Map<String, String> ns = new HashMap<String, String>();
+            ns.put("ns", MtomTestHelper.SERVICE_TYPES_NS);
+            ns.put("xop", MtomTestHelper.XOP_NS);
+
+            XPathUtils xu = new XPathUtils(ns);
+            Element ele = (Element)xu.getValue("//ns:Detail/ns:photo/xop:Include", in.getBody().get(0),
+                                               XPathConstants.NODE);
+            String photoId = ele.getAttribute("href").substring(4); // skip "cid:"
+            Assert.assertEquals(MtomTestHelper.REQ_PHOTO_CID, photoId);
+
+            ele = (Element)xu.getValue("//ns:Detail/ns:image/xop:Include", in.getBody().get(0),
+                                               XPathConstants.NODE);
+            String imageId = ele.getAttribute("href").substring(4); // skip "cid:"
+            Assert.assertEquals(MtomTestHelper.REQ_IMAGE_CID, imageId);
+
+            DataHandler dr = exchange.getIn().getAttachment(photoId);
+            Assert.assertEquals("application/octet-stream", dr.getContentType());
+            MtomTestHelper.assertEquals(MtomTestHelper.REQ_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
+       
+            dr = exchange.getIn().getAttachment(imageId);
+            Assert.assertEquals("image/jpeg", dr.getContentType());
+            MtomTestHelper.assertEquals(MtomTestHelper.requestJpeg, IOUtils.readBytesFromStream(dr.getInputStream()));
+
+            // create response
+            List<Element> elements = new ArrayList<Element>();
+            elements.add(DOMUtils.readXml(new StringReader(MtomTestHelper.RESP_MESSAGE)).getDocumentElement());
+            CxfPayload<SoapHeader> body = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(),
+                elements);
+            exchange.getOut().setBody(body);
+            exchange.getOut().addAttachment(MtomTestHelper.RESP_PHOTO_CID, 
+                new DataHandler(new ByteArrayDataSource(MtomTestHelper.RESP_PHOTO_DATA, "application/octet-stream")));
+
+            exchange.getOut().addAttachment(MtomTestHelper.RESP_IMAGE_CID, 
+                new DataHandler(new ByteArrayDataSource(MtomTestHelper.responseJpeg, "image/jpeg")));
+
+        }
+    }
+}

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomConsumerPayloadModeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomConsumerPayloadModeTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomConsumerTest.java (from r829124, camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMtomConsumerTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomConsumerTest.java?p2=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomConsumerTest.java&p1=camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMtomConsumerTest.java&r1=829124&r2=830701&rev=830701&view=diff
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/CxfMtomConsumerTest.java (original)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomConsumerTest.java Wed Oct 28 17:52:34 2009
@@ -14,10 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.component.cxf;
+package org.apache.camel.component.cxf.mtom;
 
 import java.awt.Image;
-import java.io.UnsupportedEncodingException;
 import java.net.URL;
 import java.util.List;
 
@@ -35,7 +34,6 @@
 import org.apache.camel.cxf.mtom_feature.Hello;
 import org.apache.camel.cxf.mtom_feature.HelloService;
 import org.apache.camel.test.junit4.CamelTestSupport;
-import org.apache.cxf.BusFactory;
 import org.junit.Test;
 
 
@@ -89,7 +87,6 @@
     
     @Test
     public void testInvokingServiceFromCXFClient() throws Exception {        
-        System.out.println();
         
         if (Boolean.getBoolean("java.awt.headless") || System.getProperty("os.name").startsWith("Mac OS")) {
             System.out.println("Running headless. Skipping test as Images may not work.");

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomConsumerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomConsumerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomConsumerTest.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomProducerPayloadModeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomProducerPayloadModeTest.java?rev=830701&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomProducerPayloadModeTest.java (added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomProducerPayloadModeTest.java Wed Oct 28 17:52:34 2009
@@ -0,0 +1,135 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.cxf.mtom;
+
+import java.awt.image.BufferedImage;
+import java.io.StringReader;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.activation.DataHandler;
+import javax.imageio.ImageIO;
+import javax.mail.util.ByteArrayDataSource;
+import javax.xml.ws.Endpoint;
+import javax.xml.ws.soap.SOAPBinding;
+import javax.xml.xpath.XPathConstants;
+
+import org.w3c.dom.Element;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.Processor;
+import org.apache.camel.component.cxf.CxfPayload;
+import org.apache.cxf.binding.soap.SoapHeader;
+import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.helpers.XPathUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+/**
+* Unit test for exercising MTOM feature of a CxfProducer in PAYLOAD mode
+* 
+* @version $Revision$
+*/
+@ContextConfiguration
+public class CxfMtomProducerPayloadModeTest extends AbstractJUnit4SpringContextTests {
+
+    @Autowired
+    protected CamelContext context;
+    private Endpoint endpoint;
+
+    @Before
+    public void setUp() throws Exception {
+        endpoint = Endpoint.publish("http://localhost:9092/jaxws-mtom/hello", new HelloImpl());
+        SOAPBinding binding = (SOAPBinding)endpoint.getBinding();
+        binding.setMTOMEnabled(true);
+    }
+    
+    @After
+    public void tearDown() throws Exception {
+        if (endpoint != null) {
+            endpoint.stop();
+        }
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testProducer() throws Exception {
+        
+        if (Boolean.getBoolean("java.awt.headless") || System.getProperty("os.name").startsWith("Mac OS")) {
+            System.out.println("Running headless. Skipping test as Images may not work.");
+            return;
+        }     
+        
+        Exchange exchange = context.createProducerTemplate().send("direct:testEndpoint", new Processor() {
+
+            public void process(Exchange exchange) throws Exception {
+                exchange.setPattern(ExchangePattern.InOut);
+                List<Element> elements = new ArrayList<Element>();
+                elements.add(DOMUtils.readXml(new StringReader(MtomTestHelper.REQ_MESSAGE)).getDocumentElement());
+                CxfPayload<SoapHeader> body = new CxfPayload<SoapHeader>(new ArrayList<SoapHeader>(),
+                    elements);
+                exchange.getIn().setBody(body);
+                exchange.getIn().addAttachment(MtomTestHelper.REQ_PHOTO_CID, 
+                    new DataHandler(new ByteArrayDataSource(MtomTestHelper.REQ_PHOTO_DATA, "application/octet-stream")));
+
+                exchange.getIn().addAttachment(MtomTestHelper.REQ_IMAGE_CID, 
+                    new DataHandler(new ByteArrayDataSource(MtomTestHelper.requestJpeg, "image/jpeg")));
+
+            }
+            
+        });
+        
+        CxfPayload<SoapHeader> out = exchange.getOut().getBody(CxfPayload.class);
+        Assert.assertEquals(1, out.getBody().size());
+        
+        Map<String, String> ns = new HashMap<String, String>();
+        ns.put("ns", MtomTestHelper.SERVICE_TYPES_NS);
+        ns.put("xop", MtomTestHelper.XOP_NS);
+        
+        XPathUtils xu = new XPathUtils(ns);
+        Element ele = (Element)xu.getValue("//ns:DetailResponse/ns:photo/xop:Include", out.getBody().get(0),
+                                           XPathConstants.NODE);
+        String photoId = ele.getAttribute("href").substring(4); // skip "cid:"
+
+        ele = (Element)xu.getValue("//ns:DetailResponse/ns:image/xop:Include", out.getBody().get(0),
+                                           XPathConstants.NODE);
+        String imageId = ele.getAttribute("href").substring(4); // skip "cid:"
+
+        DataHandler dr = exchange.getOut().getAttachment(photoId);
+        Assert.assertEquals("application/octet-stream", dr.getContentType());
+        MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA, IOUtils.readBytesFromStream(dr.getInputStream()));
+   
+        dr = exchange.getOut().getAttachment(imageId);
+        Assert.assertEquals("image/jpeg", dr.getContentType());
+        
+        BufferedImage image = ImageIO.read(dr.getInputStream());
+        Assert.assertEquals(560, image.getWidth());
+        Assert.assertEquals(300, image.getHeight());
+
+    }
+    
+}

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomProducerPayloadModeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomProducerPayloadModeTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomRouterPayloadModeTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomRouterPayloadModeTest.java?rev=830701&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomRouterPayloadModeTest.java (added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomRouterPayloadModeTest.java Wed Oct 28 17:52:34 2009
@@ -0,0 +1,114 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.cxf.mtom;
+
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+import java.net.URL;
+
+import javax.imageio.ImageIO;
+import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.Endpoint;
+import javax.xml.ws.Holder;
+import javax.xml.ws.soap.SOAPBinding;
+
+import junit.framework.Assert;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.cxf.mtom_feature.Hello;
+import org.apache.camel.cxf.mtom_feature.HelloService;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
+
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Unit test for exercising MTOM enabled end-to-end router in PAYLOAD mode
+ * 
+ * @version $Revision$
+ */
+@ContextConfiguration
+public class CxfMtomRouterPayloadModeTest extends AbstractJUnit4SpringContextTests {
+    
+    protected final QName serviceName = new QName("http://apache.org/camel/cxf/mtom_feature", "HelloService");
+    
+    @Autowired
+    protected CamelContext context;
+    private Endpoint endpoint;
+
+    @Before
+    public void setUp() throws Exception {
+        endpoint = Endpoint.publish("http://localhost:9092/jaxws-mtom/hello", new HelloImpl());
+        SOAPBinding binding = (SOAPBinding)endpoint.getBinding();
+        binding.setMTOMEnabled(true);
+        
+    }
+    
+    @After
+    public void tearDown() throws Exception {
+        if (endpoint != null) {
+            endpoint.stop();
+        }
+    }
+
+    @Test
+    public void testInvokingServiceFromCXFClient() throws Exception {        
+        
+        if (Boolean.getBoolean("java.awt.headless") || System.getProperty("os.name").startsWith("Mac OS")) {
+            System.out.println("Running headless. Skipping test as Images may not work.");
+            return;
+        }        
+        
+        Holder<byte[]> photo = new Holder<byte[]>(MtomTestHelper.REQ_PHOTO_DATA);
+        Holder<Image> image = new Holder<Image>(getImage("/java.jpg"));
+
+        Hello port = getPort();
+
+        SOAPBinding binding = (SOAPBinding) ((BindingProvider)port).getBinding();
+        binding.setMTOMEnabled(true);
+
+        port.detail(photo, image);
+        
+        MtomTestHelper.assertEquals(MtomTestHelper.RESP_PHOTO_DATA,  photo.value);      
+        Assert.assertNotNull(image.value);
+        if (image.value instanceof BufferedImage) {
+            Assert.assertEquals(560, ((BufferedImage)image.value).getWidth());
+            Assert.assertEquals(300, ((BufferedImage)image.value).getHeight());            
+        }  
+        
+    }
+    
+    private Hello getPort() {
+        URL wsdl = getClass().getResource("/mtom.wsdl");
+        assertNotNull("WSDL is null", wsdl);
+
+        HelloService service = new HelloService(wsdl, serviceName);
+        assertNotNull("Service is null ", service);
+        return service.getHelloPort();
+    }
+    
+    private Image getImage(String name) throws Exception {
+        return ImageIO.read(getClass().getResource(name));
+    }
+    
+
+}

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomRouterPayloadModeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/CxfMtomRouterPayloadModeTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/HelloImpl.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/HelloImpl.java?rev=830701&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/HelloImpl.java (added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/HelloImpl.java Wed Oct 28 17:52:34 2009
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.cxf.mtom;
+
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+import javax.xml.ws.Holder;
+
+import junit.framework.Assert;
+
+import org.apache.camel.cxf.mtom_feature.Hello;
+
+/**
+ * Hello Test Impl class
+ * @version $Revision$
+ */
+public class HelloImpl implements Hello {
+
+    public void detail(Holder<byte[]> photo, Holder<Image> image) {
+        
+        MtomTestHelper.assertEquals(MtomTestHelper.REQ_PHOTO_DATA,  photo.value);      
+        Assert.assertNotNull(image.value);
+        if (image.value instanceof BufferedImage) {
+            Assert.assertEquals(41, ((BufferedImage)image.value).getWidth());
+            Assert.assertEquals(39, ((BufferedImage)image.value).getHeight());            
+        }
+
+        try {
+            image.value = ImageIO.read(getClass().getResource("/Splash.jpg"));
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        
+        photo.value = MtomTestHelper.RESP_PHOTO_DATA;
+
+    }
+
+    public void echoData(Holder<byte[]> data) {
+        throw new UnsupportedOperationException();
+    }
+
+}

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/HelloImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/HelloImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/MtomTestHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/MtomTestHelper.java?rev=830701&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/MtomTestHelper.java (added)
+++ camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/MtomTestHelper.java Wed Oct 28 17:52:34 2009
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.cxf.mtom;
+
+import java.io.IOException;
+
+import junit.framework.Assert;
+
+import org.apache.cxf.helpers.IOUtils;
+
+
+/**
+ * Package local test helper
+ * 
+ * @version $Revision$
+ */
+public final class MtomTestHelper {
+    
+    static final String SERVICE_TYPES_NS = "http://apache.org/camel/cxf/mtom_feature/types";
+    static final String XOP_NS = "http://www.w3.org/2004/08/xop/include";
+    static final byte[] REQ_PHOTO_DATA = {1, 0, -1, 34, 23, 3, 23, 55, 33};
+    static final byte[] RESP_PHOTO_DATA = {5, -7, 23, 1, 0, -1, 34, 23, 3, 23, 55, 33, 3};
+
+    static final String REQ_PHOTO_CID = "e33b6792-6666-4837-b0d9-68c88c8cadcb-1@apache.org";
+    static final String REQ_IMAGE_CID = "e33b6792-6666-4837-b0d9-68c88c8cadcb-2@apache.org";
+    
+    static final String REQ_MESSAGE = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+        + "<Detail xmlns=\"http://apache.org/camel/cxf/mtom_feature/types\">"
+        + "<photo><xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\""
+        + " href=\"cid:" + REQ_PHOTO_CID + "\"/>"
+        + "</photo><image><xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\""
+        + " href=\"cid:" + REQ_IMAGE_CID + "\"/></image></Detail>";
+    
+    static final String RESP_PHOTO_CID = "4c7b78dc-356a-4fca-8877-068ee2f31824-7@apache.org";
+    static final String RESP_IMAGE_CID = "4c7b78dc-356a-4fca-8877-068ee2f31824-8@apache.org";
+    
+    static final String RESP_MESSAGE = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+        + "<DetailResponse xmlns=\"http://apache.org/camel/cxf/mtom_feature/types\">"
+        + "<photo><xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\""
+        + " href=\"cid:" + RESP_PHOTO_CID + "\"/>"
+        + "</photo><image><xop:Include xmlns:xop=\"http://www.w3.org/2004/08/xop/include\""
+        + " href=\"cid:" + RESP_IMAGE_CID + "\"/></image></DetailResponse>";
+
+    static byte[] requestJpeg;
+    static byte[] responseJpeg;
+
+    static { 
+        try {
+            requestJpeg = IOUtils.readBytesFromStream(CxfMtomConsumerPayloadModeTest.class.getResourceAsStream("/java.jpg"));
+            responseJpeg = IOUtils.readBytesFromStream(CxfMtomConsumerPayloadModeTest.class.getResourceAsStream("/Splash.jpg"));
+        } catch (IOException e) {
+            
+            e.printStackTrace();
+        }
+    }
+    
+    private MtomTestHelper() {
+        // utility class
+    }
+
+    static void assertEquals(byte[] bytes1, byte[] bytes2) {
+        Assert.assertNotNull(bytes1);
+        Assert.assertNotNull(bytes2);
+        Assert.assertEquals(bytes1.length, bytes2.length);
+        for (int i = 0; i < bytes1.length; i++) {
+            Assert.assertEquals(bytes1[i], bytes2[i]);
+        }
+    }
+}

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/MtomTestHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/mtom/MtomTestHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/components/camel-cxf/src/test/resources/Splash.jpg
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/Splash.jpg?rev=830701&view=auto
==============================================================================
Binary file - no diff available.

Propchange: camel/trunk/components/camel-cxf/src/test/resources/Splash.jpg
------------------------------------------------------------------------------
    svn:mime-type = image/jpeg

Added: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomConsumerPayloadModeTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomConsumerPayloadModeTest-context.xml?rev=830701&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomConsumerPayloadModeTest-context.xml (added)
+++ camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomConsumerPayloadModeTest-context.xml Wed Oct 28 17:52:34 2009
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:cxf="http://camel.apache.org/schema/cxf"
+
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+   <cxf:cxfEndpoint id="consumerEndpoint" address="http://localhost:9091/jaxws-mtom/hello"
+            wsdlURL="mtom.wsdl"
+            serviceName="ns:HelloService"
+            endpointName="ns:HelloPort"
+            xmlns:ns="http://apache.org/camel/cxf/mtom_feature">
+
+        <cxf:properties>
+            <entry key="mtom-enabled" value="true"/>
+            <entry key="dataFormat" value="PAYLOAD"/>
+        </cxf:properties>      
+<!--                   
+        <cxf:inInterceptors>
+		    <ref bean="logInbound"/>
+		</cxf:inInterceptors>	
+		<cxf:outInterceptors>
+		    <ref bean="logOutbound"/>
+		</cxf:outInterceptors>
+-->	
+   </cxf:cxfEndpoint>            
+   
+   <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+      <route>
+          <from uri="cxf:bean:consumerEndpoint" />
+          <process ref="myProcessor" />
+      </route>
+   </camelContext>
+   
+   <bean id="logOutbound" class="org.apache.cxf.interceptor.LoggingOutInterceptor" />         
+   <bean id="logInbound" class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+   
+   <bean id="myProcessor" 
+   	          class="org.apache.camel.component.cxf.mtom.CxfMtomConsumerPayloadModeTest$MyProcessor" />
+
+</beans>
\ No newline at end of file

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomConsumerPayloadModeTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomConsumerPayloadModeTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomConsumerPayloadModeTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomProducerPayloadModeTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomProducerPayloadModeTest-context.xml?rev=830701&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomProducerPayloadModeTest-context.xml (added)
+++ camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomProducerPayloadModeTest-context.xml Wed Oct 28 17:52:34 2009
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:cxf="http://camel.apache.org/schema/cxf"
+
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+   <cxf:cxfEndpoint id="serviceEndpoint" address="http://localhost:9092/jaxws-mtom/hello"
+            wsdlURL="mtom.wsdl"
+            serviceName="ns:HelloService"
+            endpointName="ns:HelloPort"
+            xmlns:ns="http://apache.org/camel/cxf/mtom_feature">
+
+        <cxf:properties>
+            <entry key="mtom-enabled" value="true"/>
+            <entry key="dataFormat" value="PAYLOAD"/>
+        </cxf:properties>      
+<!--                   
+        <cxf:inInterceptors>
+		    <ref bean="logInbound"/>
+		</cxf:inInterceptors>	
+		<cxf:outInterceptors>
+		    <ref bean="logOutbound"/>
+		</cxf:outInterceptors>
+-->	
+   </cxf:cxfEndpoint>            
+   
+   <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+      <route>
+          <from uri="direct:testEndpoint" />
+          <to uri="cxf:bean:serviceEndpoint" />
+      </route>
+   </camelContext>
+   
+   <bean id="logOutbound" class="org.apache.cxf.interceptor.LoggingOutInterceptor" />         
+   <bean id="logInbound" class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+
+</beans>
\ No newline at end of file

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomProducerPayloadModeTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomProducerPayloadModeTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomProducerPayloadModeTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomRouterPayloadModeTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomRouterPayloadModeTest-context.xml?rev=830701&view=auto
==============================================================================
--- camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomRouterPayloadModeTest-context.xml (added)
+++ camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomRouterPayloadModeTest-context.xml Wed Oct 28 17:52:34 2009
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:cxf="http://camel.apache.org/schema/cxf"
+
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+   <cxf:cxfEndpoint id="routerEndpoint" address="http://localhost:9091/jaxws-mtom/hello"
+            wsdlURL="mtom.wsdl"
+            serviceName="ns:HelloService"
+            endpointName="ns:HelloPort"
+            xmlns:ns="http://apache.org/camel/cxf/mtom_feature">
+
+        <cxf:properties>
+            <entry key="mtom-enabled" value="true"/>
+            <entry key="dataFormat" value="PAYLOAD"/>
+        </cxf:properties>      
+                             
+<!--                   
+        <cxf:inInterceptors>
+		    <ref bean="logInbound"/>
+		</cxf:inInterceptors>	
+		<cxf:outInterceptors>
+		    <ref bean="logOutbound"/>
+		</cxf:outInterceptors>
+-->	
+   </cxf:cxfEndpoint>
+            
+   <cxf:cxfEndpoint id="serviceEndpoint" address="http://localhost:9092/jaxws-mtom/hello"
+            wsdlURL="mtom.wsdl"
+            serviceName="ns:HelloService"
+            endpointName="ns:HelloPort"
+            xmlns:ns="http://apache.org/camel/cxf/mtom_feature">
+            
+        <cxf:properties>
+            <entry key="mtom-enabled" value="true"/>
+            <entry key="dataFormat" value="PAYLOAD"/>            
+        </cxf:properties>  
+
+<!--                          
+        <cxf:inInterceptors>
+		    <ref bean="logInbound"/>
+		</cxf:inInterceptors>	
+		<cxf:outInterceptors>
+		    <ref bean="logOutbound"/>
+		</cxf:outInterceptors>
+-->
+   </cxf:cxfEndpoint>                        
+
+   <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+      <route>
+          <from uri="cxf:bean:routerEndpoint" />
+          <to uri="cxf:bean:serviceEndpoint" />
+      </route>
+   </camelContext>
+   
+   <bean id="logOutbound" class="org.apache.cxf.interceptor.LoggingOutInterceptor" />         
+   <bean id="logInbound" class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
+
+</beans>
\ No newline at end of file

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomRouterPayloadModeTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomRouterPayloadModeTest-context.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: camel/trunk/components/camel-cxf/src/test/resources/org/apache/camel/component/cxf/mtom/CxfMtomRouterPayloadModeTest-context.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message