cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r613340 - in /incubator/cxf/trunk: rt/core/src/main/java/org/apache/cxf/test/ rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/ rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/ rt/databinding/aegis/src/main/ja...
Date Sat, 19 Jan 2008 01:26:53 GMT
Author: bimargulies
Date: Fri Jan 18 17:26:52 2008
New Revision: 613340

URL: http://svn.apache.org/viewvc?rev=613340&view=rev
Log:
This time for sure, use xmime:base64Binary instead of xsd:base64Binary.

Modified:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/TestUtilities.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/BeanType.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/systests/src/test/java/org/apache/cxf/systest/aegis/mtom/MtomTest.java

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/TestUtilities.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/TestUtilities.java?rev=613340&r1=613339&r2=613340&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/TestUtilities.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/test/TestUtilities.java Fri Jan
18 17:26:52 2008
@@ -39,6 +39,7 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 
+import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -113,6 +114,27 @@
         addNamespace("soap", "http://schemas.xmlsoap.org/soap/");
         addNamespace("soap12env", "http://www.w3.org/2003/05/soap-envelope");
         addNamespace("xml", "http://www.w3.org/XML/1998/namespace");
+    }
+    
+    /**
+     * Handy function for checking correctness of qualifies names in schema attribute values.
+     * @param prefix
+     * @param node
+     * @return
+     * @throws Exception
+     */
+    public String resolveNamespacePrefix(String prefix, Node node) throws Exception {
+        String url = null;
+        NodeList nodeNamespaces = this.assertValid("namespace::*", node);
+        for (int x = 0; x < nodeNamespaces.getLength(); x++) {
+            Attr nsAttr = (Attr)nodeNamespaces.item(x);
+            String localName = nsAttr.getLocalName();
+            if (localName.equals(prefix)) {
+                url = nsAttr.getValue();
+                break;
+            }
+        }
+        return url;
     }
 
     /**

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=613340&r1=613339&r2=613340&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 17:26:52 2008
@@ -60,6 +60,7 @@
 import org.apache.cxf.aegis.type.basic.TimestampType;
 import org.apache.cxf.aegis.type.basic.URIType;
 import org.apache.cxf.aegis.type.java5.Java5TypeCreator;
+import org.apache.cxf.aegis.type.mtom.AbstractXOPType;
 import org.apache.cxf.aegis.type.mtom.DataHandlerType;
 import org.apache.cxf.aegis.type.mtom.DataSourceType;
 import org.apache.cxf.aegis.type.xml.DocumentType;
@@ -386,9 +387,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());
-        // 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));
+
+        register(tm, DataSource.class, AbstractXOPType.XML_MIME_BASE64, new DataSourceType(null));
+        register(tm, DataHandler.class, AbstractXOPType.XML_MIME_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=613340&r1=613339&r2=613340&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 17:26:52 2008
@@ -208,6 +208,10 @@
     public void setWriteOuter(boolean writeOuter) {
         this.writeOuter = writeOuter;
     }
+    
+    public boolean usesXmime() {
+        return false;
+    }
 
     @Override
     public String toString() {

Modified: incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java?rev=613340&r1=613339&r2=613340&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
(original)
+++ incubator/cxf/trunk/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanType.java
Fri Jan 18 17:26:52 2008
@@ -36,6 +36,7 @@
 import org.apache.cxf.aegis.type.Type;
 import org.apache.cxf.aegis.type.TypeMapping;
 import org.apache.cxf.aegis.type.TypeUtil;
+import org.apache.cxf.aegis.type.mtom.AbstractXOPType;
 import org.apache.cxf.aegis.util.NamespaceHelper;
 import org.apache.cxf.aegis.xml.MessageReader;
 import org.apache.cxf.aegis.xml.MessageWriter;
@@ -43,6 +44,7 @@
 import org.apache.cxf.common.util.SOAPConstants;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
+import org.jaxen.JaxenException;
 import org.jdom.Attribute;
 import org.jdom.Element;
 import org.jdom.Namespace;
@@ -453,7 +455,8 @@
         }
 
         Element seq = null;
-
+        boolean needXmime = false;
+        
         // Write out schema for elements
         for (Iterator itr = inf.getElements(); itr.hasNext();) {
 
@@ -484,6 +487,11 @@
             String prefix = NamespaceHelper.getUniquePrefix(root, type.getSchemaType().getNamespaceURI());
 
             writeTypeReference(name, nameWithPrefix, element, type, prefix, root);
+            needXmime |= type.usesXmime();
+        }
+        
+        if (needXmime) {
+            addXmimeToSchema(root);
         }
 
         /**
@@ -749,5 +757,19 @@
     private Element createAnyAttribute() {
         return new Element("anyAttribute", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
     }
-
+    
+    private void addXmimeToSchema(Element root) {
+        try {
+            Object node = AbstractXOPType.getXmimeXpathImport().selectSingleNode(root);
+            if (node != null) {
+                return;
+            }
+        } catch (JaxenException e) {
+            throw new RuntimeException(e);
+        }
+        Element element = new Element("import", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+        root.addContent(0, element);
+        element.setAttribute("namespace", AbstractXOPType.XML_MIME_NS);
+        root.addNamespaceDeclaration(Namespace.getNamespace("xmime", AbstractXOPType.XML_MIME_NS));
+    }
 }

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=613340&r1=613339&r2=613340&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 17:26:52 2008
@@ -34,7 +34,6 @@
 import org.apache.cxf.common.util.SOAPConstants;
 import org.apache.cxf.message.Attachment;
 import org.jaxen.JaxenException;
-import org.jaxen.XPath;
 import org.jaxen.jdom.JDOMXPath;
 import org.jdom.Attribute;
 import org.jdom.Element;
@@ -51,34 +50,36 @@
     public static final QName XOP_INCLUDE = new QName(XOP_NS, "Include");
     public static final QName XML_MIME_CONTENT_TYPE = new QName(XML_MIME_NS, "contentType");
     public static final QName XOP_HREF = new QName("href");
+    public static final QName XML_MIME_BASE64 = new QName(XML_MIME_NS, "base64Binary", "xmime");
+    private static JDOMXPath importXmimeXpath;
+    
+    static {
+        try {
+            importXmimeXpath = new JDOMXPath("xsd:import[@namespace='"
+                                             + XML_MIME_NS
+                                             + "']");
+            importXmimeXpath.addNamespace(SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
+        } catch (JaxenException e) {
+            throw new RuntimeException(e);
+        }
+    }
     
     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;
-    private XPath importXmimeXpath;
-
+    
     public AbstractXOPType(String expectedContentTypes) {
         this.expectedContentTypes = expectedContentTypes;
         fallbackDelegate = new Base64Type(this);
-        importXmimeXpath = getXmimeXpathImport();
+        // we use the XMIME type instead of the XSD type to allow for our content type attribute.
+        setSchemaType(XML_MIME_BASE64);
     }
     
     public static JDOMXPath getXmimeXpathImport() {
-        JDOMXPath importXmimeXpath;
-        try {
-            importXmimeXpath = new JDOMXPath("xsd:import[@namespace='"
-                                             + XML_MIME_NS
-                                             + "']");
-            importXmimeXpath.addNamespace(SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
-            return importXmimeXpath;
-        } catch (JaxenException e) {
-            throw new RuntimeException(e);
-        }
-        
-        
+        return importXmimeXpath;
     }
-    
+
     /**
      * This is called from base64Type when it recognizes an XOP attachment.
      * @param reader
@@ -207,17 +208,7 @@
     }
     
     @Override
-    public void writeSchema(Element root) {
-        try {
-            Object node = importXmimeXpath.selectSingleNode(root);
-            if (node != null) {
-                return;
-            }
-        } catch (JaxenException e) {
-            throw new RuntimeException(e);
-        }
-        Element element = new Element("import", SOAPConstants.XSD_PREFIX, SOAPConstants.XSD);
-        root.addContent(0, element);
-        element.setAttribute("namespace", XML_MIME_NS);
+    public boolean usesXmime() {
+        return true;
     }
 }

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=613340&r1=613339&r2=613340&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 17:26:52 2008
@@ -24,12 +24,10 @@
 import java.io.OutputStream;
 
 import javax.activation.DataHandler;
-import javax.xml.namespace.QName;
 
 import org.apache.cxf.aegis.Context;
 import org.apache.cxf.attachment.AttachmentImpl;
 import org.apache.cxf.attachment.ByteDataSource;
-import org.apache.cxf.common.util.SOAPConstants;
 import org.apache.cxf.message.Attachment;
 
 /**
@@ -39,7 +37,6 @@
     public ByteArrayType(String expectedContentTypes) {
         super(expectedContentTypes);
         setTypeClass(byte[].class);
-        setSchemaType(new QName(SOAPConstants.XSD, "base64Binary"));
     }
 
     @Override

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=613340&r1=613339&r2=613340&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 17:26:52 2008
@@ -25,10 +25,14 @@
 import javax.activation.DataHandler;
 import javax.xml.namespace.QName;
 
+import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.aegis.databinding.AegisDatabinding;
+import org.apache.cxf.aegis.type.mtom.AbstractXOPType;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.frontend.ClientProxyFactoryBean;
 import org.apache.cxf.interceptor.LoggingOutInterceptor;
@@ -95,7 +99,7 @@
         setupForTest(false);
         DataHandlerBean dhBean = new DataHandlerBean();
         dhBean.setName("some name");
-        // some day, we might need this to be higher than some threshold.
+        // some day, we might need this to be longer 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);
@@ -118,6 +122,19 @@
                                           "MtomTest"));
         Document wsdl = testUtilities.getWSDLDocument(s); 
         assertNotNull(wsdl);
+        NodeList typeAttrList = 
+            testUtilities.assertValid("//xsd:complexType[@name='inputDhBean']/xsd:sequence/"
+                                      + "xsd:element[@name='dataHandler']/"
+                                      + "@type", 
+                                      wsdl);
+        Attr typeAttr = (Attr)typeAttrList.item(0);
+        String typeAttrValue = typeAttr.getValue();
+        // now, this thing is a qname with a :, and we have to work out if it's correct.
+        String[] pieces = typeAttrValue.split(":");
+        assertEquals("base64Binary", pieces[1]);
+        Node elementNode = typeAttr.getOwnerElement();
+        String url = testUtilities.resolveNamespacePrefix(pieces[0], elementNode);
+        assertEquals(AbstractXOPType.XML_MIME_NS, url);
         
         /*
         testUtilities.assertValid("//xsd:complexType[@name='inputDhBean']/xsd:sequence/"



Mime
View raw message