cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r613272 - in /incubator/cxf/trunk: rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/ rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/ rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/ rt/databinding/ae...
Date Fri, 18 Jan 2008 21:08:22 GMT
Author: bimargulies
Date: Fri Jan 18 13:08:21 2008
New Revision: 613272

URL: http://svn.apache.org/viewvc?rev=613272&view=rev
Log:
MtoM is specified as an optimization. This change allows the DataHandler
binding to work, somewhat, when mtom is turned off, rather than going ahead
and creating attachments even when it has been sternly instructed not to do so.



Modified:
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/Context.java
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMappingRegistry.java
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/Type.java
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/Base64Type.java
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/ByteArrayType.java
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java
    incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataSourceType.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java

Modified: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/Context.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/Context.java?rev=613272&r1=613271&r2=613272&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/Context.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/Context.java
Fri Jan 18 13:08:21 2008
@@ -38,6 +38,8 @@
     private Collection<Attachment> attachments;
     private Fault fault;
     private Map<Class<?>, Object> properties;
+    // this is used as part of dealing with unoptimized base64binary issues.
+    private String contentType;
     
     public Context(AegisContext aegisContext) {
         this.globalContext = aegisContext;
@@ -87,6 +89,14 @@
     
     public void setProperty(Object value) {
         properties.put(value.getClass(), value);
+    }
+
+    public String getContentType() {
+        return contentType;
+    }
+
+    public void setContentType(String contentType) {
+        this.contentType = contentType;
     }
 
 }

Modified: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java?rev=613272&r1=613271&r2=613272&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/databinding/AegisDatabinding.java
Fri Jan 18 13:08:21 2008
@@ -206,6 +206,11 @@
                 overrideTypes.addAll(typeNames);
             }
             
+            val = s.get("mtom-enabled");
+            if ("true".equals(val) || Boolean.TRUE.equals(val) || mtomEnabled) {
+                aegisContext.setMtomEnabled(true);
+            }
+            
             Map<Class<?>, String> implMap = new HashMap<Class<?>, String>();
             // now for a really annoying case, the .implementation objects.
             for (String key : s.keySet()) {

Modified: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMappingRegistry.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMappingRegistry.java?rev=613272&r1=613271&r2=613272&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMappingRegistry.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/DefaultTypeMappingRegistry.java
Fri Jan 18 13:08:21 2008
@@ -341,8 +341,10 @@
         register(soapTM, Element.class, XSD_ANY, new JDOMElementType());
         register(soapTM, org.jdom.Document.class, XSD_ANY, new JDOMDocumentType());
         register(soapTM, Object.class, XSD_ANY, new ObjectType());
-        register(soapTM, DataSource.class, XSD_BASE64, new DataSourceType());
-        register(soapTM, DataHandler.class, XSD_BASE64, new DataHandlerType());
+        // unless there is customization, we use no expectedContentTypes.
+        // however, if we want to implement xmime:contentType, we'll need to make this more
complex.
+        register(soapTM, DataSource.class, XSD_BASE64, new DataSourceType(null));
+        register(soapTM, DataHandler.class, XSD_BASE64, new DataHandlerType(null));
         register(soapTM, BigInteger.class, XSD_INTEGER, new BigIntegerType());
 
         register(ENCODED_NS, soapTM);
@@ -384,8 +386,9 @@
         register(tm, Element.class, XSD_ANY, new JDOMElementType());
         register(tm, org.jdom.Document.class, XSD_ANY, new JDOMDocumentType());
         register(tm, Object.class, XSD_ANY, new ObjectType());
-        register(tm, DataSource.class, XSD_BASE64, new DataSourceType());
-        register(tm, DataHandler.class, XSD_BASE64, new DataHandlerType());
+        // no expected content types in default registry.
+        register(tm, DataSource.class, XSD_BASE64, new DataSourceType(null));
+        register(tm, DataHandler.class, XSD_BASE64, new DataHandlerType(null));
 
         if (isJDK5andAbove()) {
             registerIfAvailable(tm, "javax.xml.datatype.Duration", XSD_DURATION,

Modified: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/Type.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/Type.java?rev=613272&r1=613271&r2=613272&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/Type.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/Type.java
Fri Jan 18 13:08:21 2008
@@ -71,7 +71,20 @@
     public abstract void writeObject(Object object, MessageWriter writer, Context context)
         throws DatabindingException;
 
+    /**
+     * If this type should correspond to a global, named, schema type, here is where the
+     * type object adds it to the schema.
+     * @param root root of the XSD document.
+     */
     public void writeSchema(Element root) {
+    }
+    
+    /**
+     * If the type object merely wants to contribute attributes to the 
+     * xsd:element element, it can implement this. 
+     * @param schemaElement
+     */
+    public void addToSchemaElement(Element schemaElement) {
     }
 
     /**

Modified: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/Base64Type.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/Base64Type.java?rev=613272&r1=613271&r2=613272&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/Base64Type.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/Base64Type.java
Fri Jan 18 13:08:21 2008
@@ -36,16 +36,23 @@
 
 /**
  * Converts back and forth to byte[] objects.
- * 
+ * There is a co-routine between this class and the MTOM ByteArrayType. This class can accept
either 
+ * inline base64 or an MTOM attachment. It passes the problem over the ByteArrayType for
the later. 
  * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
  */
 public class Base64Type extends Type {
-    private static ByteArrayType optimizedType = new ByteArrayType();
+    private AbstractXOPType optimizedType;
 
     public Base64Type() {
         super();
+        optimizedType = new ByteArrayType(null);
     }
-
+    
+    public Base64Type(AbstractXOPType xopType) {
+        super();
+        optimizedType = xopType;
+    }
+    
     @Override
     public Object readObject(MessageReader mreader, Context context) throws DatabindingException
{
         boolean mtomEnabled = context.isMtomEnabled();
@@ -58,10 +65,16 @@
             while (!reader.isCharacters() && !reader.isEndElement() && !reader.isStartElement())
{
                 reader.next();
             }
-
+            
+            if (reader.isStartElement()) {
+                String contentType = reader.getAttributeValue(AbstractXOPType.XML_MIME_NS,
+                                                              AbstractXOPType.XML_MIME_ATTR_LOCAL_NAME);
+                context.setContentType(contentType);
+            }
+            
             if (reader.isStartElement() && reader.getName().equals(AbstractXOPType.XOP_INCLUDE))
{
                 if (mtomEnabled) {
-                    return optimizedType.readObject(mreader, context);
+                    return optimizedType.readMtoM(mreader, context);
                 } else {
                     throw new DatabindingException("Unexpected element: " + reader.getName());
                 }
@@ -111,7 +124,7 @@
             optimizedType.writeObject(object, writer, context);
             return;
         }
-
+        
         byte[] data = (byte[])object;
 
         if (data != null && data.length > 0) {

Modified: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java?rev=613272&r1=613271&r2=613272&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/AbstractXOPType.java
Fri Jan 18 13:08:21 2008
@@ -27,26 +27,44 @@
 import org.apache.cxf.aegis.Context;
 import org.apache.cxf.aegis.DatabindingException;
 import org.apache.cxf.aegis.type.Type;
+import org.apache.cxf.aegis.type.basic.Base64Type;
 import org.apache.cxf.aegis.xml.MessageReader;
 import org.apache.cxf.aegis.xml.MessageWriter;
 import org.apache.cxf.message.Attachment;
+import org.jdom.Attribute;
+import org.jdom.Element;
+import org.jdom.Namespace;
 
 /**
+ * Base class for MtoM types.
  * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
  */
 public abstract class AbstractXOPType extends Type {
     public static final String XOP_NS = "http://www.w3.org/2004/08/xop/include";
-    public static final String XML_MIME_NS = "http://www.w3.org/2004/11/xmlmime";
+    public static final String XML_MIME_NS = "http://www.w3.org/2005/05/xmlmime";
+    public static final String XML_MIME_ATTR_LOCAL_NAME = "expectedContentTypes";
 
     public static final QName XOP_INCLUDE = new QName(XOP_NS, "Include");
     public static final QName XOP_HREF = new QName("href");
-    public static final QName XML_MIME_TYPE = new QName(XML_MIME_NS, "mimeType");
-
-    public AbstractXOPType() {
+    
+    private String expectedContentTypes;
+    // the base64 type knows how to deal with just plain base64 here, which is essentially
always 
+    // what we get in the absence of the optimization. So we need something of a coroutine.
+    private Base64Type fallbackDelegate;
+
+    public AbstractXOPType(String expectedContentTypes) {
+        this.expectedContentTypes = expectedContentTypes;
+        fallbackDelegate = new Base64Type(this);
     }
 
-    @Override
-    public Object readObject(MessageReader reader, Context context) throws DatabindingException
{
+    /**
+     * This is called from base64Type when it recognizes an XOP attachment.
+     * @param reader
+     * @param context
+     * @return
+     * @throws DatabindingException
+     */
+    public Object readMtoM(MessageReader reader, Context context) throws DatabindingException
{
         Object o = null;
         while (reader.hasMoreElementReaders()) {
             MessageReader child = reader.getNextElementReader();
@@ -61,7 +79,25 @@
         return o;
     }
 
-    public Object readInclude(String type, MessageReader reader,
+    /**
+     * This defers to the plain base64 type, which calls back into here above for XOP.
+     * {@inheritDoc}
+     */
+    @Override
+    public Object readObject(MessageReader reader, Context context) throws DatabindingException
{
+        Object thingRead = fallbackDelegate.readObject(reader, context);
+        // If there was actually an attachment, the delegate will have called back to us
and gotten
+        // the appropriate data type. If there wasn't an attachment, it just returned the
bytes. 
+        // Our subclass have to package them.
+        if (thingRead.getClass() == (new byte[0]).getClass()) {
+            String contentType = context.getContentType();
+            return wrapBytes((byte[])thingRead, contentType);
+        }
+
+        return thingRead;
+    }
+    
+    private Object readInclude(String type, MessageReader reader,
                               Context context) throws DatabindingException {
         String href = reader.getAttributeReader(XOP_HREF).getValue();
 
@@ -83,6 +119,11 @@
     @Override
     public void writeObject(Object object, MessageWriter writer,
                             Context context) throws DatabindingException {
+        if (!context.isMtomEnabled()) {
+            fallbackDelegate.writeObject(getBytes(object), writer, context);
+            return;
+        }
+        
         Collection<Attachment> attachments = context.getAttachments();
         if (attachments == null) {
             attachments = new ArrayList<Attachment>();
@@ -105,4 +146,30 @@
     protected abstract Attachment createAttachment(Object object, String id);
 
     protected abstract String getContentType(Object object, Context context);
+    
+    /**
+     * If one of these types arrives unoptimized, we need to convert it to the 
+     * desired return type.
+     * @param bareBytes the bytes pulled out of the base64.
+     * @param contentType when we support xmime:contentType, this will be passed along.
+     * @return
+     */
+    protected abstract Object wrapBytes(byte[] bareBytes, String contentType);
+
+    /**
+     * if MtoM is not enabled, we need bytes to turn into base64.
+     * @return
+     */
+    protected abstract byte[] getBytes(Object object);
+
+    @Override
+    public void addToSchemaElement(Element schemaElement) {
+        if (expectedContentTypes != null) {
+            Namespace ns = Namespace.getNamespace("xmime", XML_MIME_NS);
+            Attribute expectedContentTypeAttribute = new Attribute(XML_MIME_ATTR_LOCAL_NAME,

+                                                                   expectedContentTypes,
+                                                                   ns);
+            schemaElement.setAttribute(expectedContentTypeAttribute);
+        }
+    }
 }

Modified: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/ByteArrayType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/ByteArrayType.java?rev=613272&r1=613271&r2=613272&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/ByteArrayType.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/ByteArrayType.java
Fri Jan 18 13:08:21 2008
@@ -36,7 +36,8 @@
  * @author Dan Diephouse
  */
 public class ByteArrayType extends AbstractXOPType {
-    public ByteArrayType() {
+    public ByteArrayType(String expectedContentTypes) {
+        super(expectedContentTypes);
         setTypeClass(byte[].class);
         setSchemaType(new QName(SOAPConstants.XSD, "base64Binary"));
     }
@@ -94,5 +95,15 @@
     @Override
     protected String getContentType(Object object, Context context) {
         return "application/octet-stream";
+    }
+
+    @Override
+    protected Object wrapBytes(byte[] bareBytes, String contentType) {
+        return bareBytes;
+    }
+
+    @Override
+    protected byte[] getBytes(Object object) {
+        return (byte[])object;
     }
 }

Modified: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java?rev=613272&r1=613271&r2=613272&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataHandlerType.java
Fri Jan 18 13:08:21 2008
@@ -18,13 +18,23 @@
  */
 package org.apache.cxf.aegis.type.mtom;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
 import javax.activation.DataHandler;
 
 import org.apache.cxf.aegis.Context;
 import org.apache.cxf.attachment.AttachmentImpl;
+import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.message.Attachment;
 
 public class DataHandlerType extends AbstractXOPType {
+    
+    public DataHandlerType(String expectedContentTypes) {
+        super(expectedContentTypes);
+    }
+
     @Override
     protected Object readAttachment(Attachment att, Context context) {
         return att.getDataHandler();
@@ -43,5 +53,23 @@
     @Override
     protected String getContentType(Object object, Context context) {
         return ((DataHandler)object).getContentType();
+    }
+
+    @Override
+    protected Object wrapBytes(byte[] bareBytes, String contentType) {
+        return new DataHandler(bareBytes, contentType);
+    }
+    
+    @Override
+    protected byte[] getBytes(Object object) {
+        DataHandler handler = (DataHandler) object;
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        try {
+            InputStream stream = handler.getInputStream();
+            IOUtils.copy(stream, baos);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return baos.toByteArray();
     }
 }

Modified: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataSourceType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataSourceType.java?rev=613272&r1=613271&r2=613272&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataSourceType.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/mtom/DataSourceType.java
Fri Jan 18 13:08:21 2008
@@ -18,14 +18,23 @@
  */
 package org.apache.cxf.aegis.type.mtom;
 
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
 import javax.activation.DataHandler;
 import javax.activation.DataSource;
 
 import org.apache.cxf.aegis.Context;
 import org.apache.cxf.attachment.AttachmentImpl;
+import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.message.Attachment;
 
 public class DataSourceType extends AbstractXOPType {
+    public DataSourceType(String expectedContentTypes) {
+        super(expectedContentTypes);
+    }
+
     @Override
     protected Object readAttachment(Attachment att, Context context) {
         return att.getDataHandler().getDataSource();
@@ -44,5 +53,23 @@
     @Override
     protected String getContentType(Object object, Context context) {
         return ((DataSource)object).getContentType();
+    }
+
+    @Override
+    protected Object wrapBytes(byte[] bareBytes, String contentType) {
+        return new DataHandler(bareBytes, contentType).getDataSource();
+    }
+
+    @Override
+    protected byte[] getBytes(Object object) {
+        DataSource dataSource = (DataSource) object;
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        try {
+            InputStream stream = dataSource.getInputStream();
+            IOUtils.copy(stream, baos);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+        return baos.toByteArray();
     }
 }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java?rev=613272&r1=613271&r2=613272&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java
Fri Jan 18 13:08:21 2008
@@ -23,12 +23,18 @@
 import java.util.Map;
 
 import javax.activation.DataHandler;
+import javax.xml.namespace.QName;
 
+import org.w3c.dom.Document;
+
+import org.apache.cxf.Bus;
 import org.apache.cxf.aegis.databinding.AegisDatabinding;
+import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.frontend.ClientProxyFactoryBean;
 import org.apache.cxf.interceptor.LoggingOutInterceptor;
 import org.apache.cxf.systest.aegis.mtom.fortest.DataHandlerBean;
 import org.apache.cxf.systest.aegis.mtom.fortest.MtomTestImpl;
+import org.apache.cxf.test.TestUtilities;
 import org.junit.Test;
 import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
 
@@ -39,21 +45,28 @@
     
     private org.apache.cxf.systest.aegis.mtom.fortest.MtomTestImpl impl;
     private org.apache.cxf.systest.aegis.mtom.fortest.MtomTest client;
+    private TestUtilities testUtilities;
+    
+    public MtomTest() {
+        testUtilities = new TestUtilities(getClass());
+    }
     
     @Override
     protected String[] getConfigLocations() {
         return new String[] {"classpath:mtomTestBeans.xml"};
     }
     
-    private void getClient() throws Exception {
+    private void setupForTest(boolean enableClientMTOM) throws Exception {
         AegisDatabinding aegisBinding = new AegisDatabinding();
-        aegisBinding.setMtomEnabled(true);
+        aegisBinding.setMtomEnabled(enableClientMTOM);
         ClientProxyFactoryBean proxyFac = new ClientProxyFactoryBean();
         proxyFac.setDataBinding(aegisBinding);
         proxyFac.setAddress("http://localhost:9002/mtom");
         proxyFac.setServiceClass(org.apache.cxf.systest.aegis.mtom.fortest.MtomTest.class);
         Map<String, Object> props = new HashMap<String, Object>();
-        props.put("mtom-enabled", Boolean.TRUE);
+        if (enableClientMTOM) {
+            props.put("mtom-enabled", Boolean.TRUE);
+        }
         proxyFac.setProperties(props);
         proxyFac.getOutInterceptors().add(new LoggingOutInterceptor());
         client = (org.apache.cxf.systest.aegis.mtom.fortest.MtomTest)proxyFac.create();
@@ -62,7 +75,7 @@
     
     @Test 
     public void testAcceptDataHandler() throws Exception {
-        getClient();
+        setupForTest(true);
         DataHandlerBean dhBean = new DataHandlerBean();
         dhBean.setName("some name");
         // some day, we might need this to be higher than some threshold.
@@ -74,6 +87,45 @@
         assertNotNull(accepted);
         String data = (String) accepted.getDataHandler().getContent();
         assertNotNull(data);
+        assertEquals("This is the cereal shot from guns.", data);
     }
+
+    @Test 
+    public void testAcceptDataHandlerNoMTOM() throws Exception {
+        setupForTest(false);
+        DataHandlerBean dhBean = new DataHandlerBean();
+        dhBean.setName("some name");
+        // some day, we might need this to be higher than some threshold.
+        String someData = "This is the cereal shot from guns.";
+        DataHandler dataHandler = new DataHandler(someData, "text/plain;charset=utf-8");
+        dhBean.setDataHandler(dataHandler);
+        client.acceptDataHandler(dhBean);
+        DataHandlerBean accepted = impl.getLastDhBean();
+        assertNotNull(accepted);
+        Object data = accepted.getDataHandler().getContent();
+        assertNotNull(data);
+        // we would like to see the right content type. However, without xmime:contentType,
we cannot.
+    }
+
+    // we aren't ready for this one ...
+    @Test
+    public void testMtomSchema() throws Exception {
+        testUtilities.setBus((Bus)applicationContext.getBean("cxf"));
+        testUtilities.addDefaultNamespaces();
+        testUtilities.addNamespace("xmime", "http://www.w3.org/2005/05/xmlmime");
+        Server s = testUtilities.
+            getServerForService(new QName("http://fortest.mtom.aegis.systest.cxf.apache.org/",

+                                          "MtomTest"));
+        Document wsdl = testUtilities.getWSDLDocument(s); 
+        assertNotNull(wsdl);
+        
+        /*
+        testUtilities.assertValid("//xsd:complexType[@name='inputDhBean']/xsd:sequence/"
+                                  + "xsd:element[@name='dataHandler']/"
+                                  + "@xmime:expectedContentType/text()", 
+                                  wsdl);
+                                  */
+    }
+
 
 }



Mime
View raw message