cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1005257 - in /cxf/branches/2.2.x-fixes: ./ rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/ systests/databinding/src/test/java/org/apache/cxf/systest/xmlbeans/
Date Wed, 06 Oct 2010 21:14:40 GMT
Author: dkulp
Date: Wed Oct  6 21:14:37 2010
New Revision: 1005257

URL: http://svn.apache.org/viewvc?rev=1005257&view=rev
Log:
Merged revisions 1005254 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1005254 | dkulp | 2010-10-06 17:06:12 -0400 (Wed, 06 Oct 2010) | 2 lines
  
  [CXF-2959, CXF-2955] Support the catalogs within XmlBeans
  Support using XmlBeans for header objects
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
    cxf/branches/2.2.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansSchemaInitializer.java
    cxf/branches/2.2.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/xmlbeans/ClientServerXmlBeansTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.2.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java?rev=1005257&r1=1005256&r2=1005257&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/DataWriterImpl.java
Wed Oct  6 21:14:37 2010
@@ -20,7 +20,9 @@
 package org.apache.cxf.xmlbeans;
 
 
+import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.util.Collection;
 import java.util.logging.Logger;
 
@@ -45,6 +47,7 @@ import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.service.model.MessagePartInfo;
 import org.apache.cxf.staxutils.StaxUtils;
+import org.apache.ws.commons.schema.XmlSchemaAnnotated;
 import org.apache.ws.commons.schema.XmlSchemaElement;
 import org.apache.xmlbeans.SchemaType;
 import org.apache.xmlbeans.XmlAnySimpleType;
@@ -68,7 +71,12 @@ public class DataWriterImpl implements D
     public void write(Object obj, MessagePartInfo part, XMLStreamWriter output) {
         try {
             Class<?> typeClass = part.getTypeClass();
-            if (!XmlObject.class.isAssignableFrom(typeClass)) {
+            if (typeClass == null) {
+                typeClass = obj.getClass();
+            }
+            XmlSchemaAnnotated schemaType = part ==  null ? null : part.getXmlSchema();
+            
+            if (!XmlObject.class.isAssignableFrom(typeClass) && part != null) {
                 typeClass = (Class<?>)part.getProperty(XmlAnySimpleType.class.getName());
                 
                 Class<?> cls[] = typeClass.getDeclaredClasses();
@@ -95,7 +103,7 @@ public class DataWriterImpl implements D
 
             
             if (obj != null
-                || !(part.getXmlSchema() instanceof XmlSchemaElement)) {
+                || !(schemaType instanceof XmlSchemaElement)) {
                 XmlOptions options = new XmlOptions();
                 if (schema != null) {
                     options.setValidateOnSet();
@@ -143,7 +151,20 @@ public class DataWriterImpl implements D
                     XmlTokenSource source = (XmlTokenSource)obj;
                     reader = source.newCursor().newXMLStreamReader(options);            
       
                 }
-                SchemaType st = (SchemaType)part.getProperty(SchemaType.class.getName());
+                SchemaType st = part == null ? null 
+                    : (SchemaType)part.getProperty(SchemaType.class.getName());
+                if (st == null) {
+                    try {
+                        Field f = typeClass.getField("type");
+                        if (Modifier.isStatic(f.getModifiers())) {
+                            st = (SchemaType)f.get(null);
+                            part.setProperty(SchemaType.class.getName(), st);
+                        }
+                    } catch (Exception es) {
+                        //ignore
+                        es.printStackTrace();
+                    }
+                }
                 int i = reader.getEventType();
                 if (i == XMLStreamReader.START_DOCUMENT) {
                     i = reader.next();

Modified: cxf/branches/2.2.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansSchemaInitializer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansSchemaInitializer.java?rev=1005257&r1=1005256&r2=1005257&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansSchemaInitializer.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/databinding/xmlbeans/src/main/java/org/apache/cxf/xmlbeans/XmlBeansSchemaInitializer.java
Wed Oct  6 21:14:37 2010
@@ -54,6 +54,7 @@ import org.apache.cxf.service.model.Mess
 import org.apache.cxf.service.model.ServiceInfo;
 import org.apache.ws.commons.schema.XmlSchema;
 import org.apache.ws.commons.schema.XmlSchemaElement;
+import org.apache.ws.commons.schema.XmlSchemaException;
 import org.apache.ws.commons.schema.XmlSchemaType;
 import org.apache.ws.commons.schema.resolver.URIResolver;
 import org.apache.xmlbeans.SchemaType;
@@ -61,13 +62,15 @@ import org.apache.xmlbeans.SchemaTypeSys
 import org.apache.xmlbeans.XmlAnySimpleType;
 import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.impl.schema.BuiltinSchemaTypeSystem;
+import org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl;
 
 /**
  * Walks the service model and sets up the element/type names.
  */
 class XmlBeansSchemaInitializer extends ServiceModelVisitor {
 
-
+    public static final String XML_BEANS_SCHEMA_PREFIX = "schema" 
+        + SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/src/";
     private static final Logger LOG = LogUtils.getLogger(XmlBeansSchemaInitializer.class);
     private static final Map<Class<?>, Class<? extends XmlAnySimpleType>>
CLASS_MAP 
         = new HashMap<Class<?>, Class<? extends XmlAnySimpleType>>();
@@ -75,6 +78,7 @@ class XmlBeansSchemaInitializer extends 
     private XmlBeansDataBinding dataBinding;
     private Map<String, XmlSchema> schemaMap 
         = new HashMap<String, XmlSchema>();
+    private URIResolver schemaResolver;
     
     static {
         CLASS_MAP.put(String.class, org.apache.xmlbeans.XmlString.class);
@@ -105,6 +109,7 @@ class XmlBeansSchemaInitializer extends 
         super(serviceInfo);
         schemas = col;
         dataBinding = db;
+        schemaResolver = serviceInfo.getXmlSchemaCollection().getXmlSchemaCollection().getSchemaResolver();
     }
     
     public class XMLSchemaResolver implements URIResolver {
@@ -148,10 +153,29 @@ class XmlBeansSchemaInitializer extends 
 
         return schema;
     }
-    XmlSchema getSchema(SchemaTypeSystem sts, String file) {
+    protected XmlSchema getSchema(SchemaTypeSystem sts, String file) {
         if (schemaMap.containsKey(file)) {
             return schemaMap.get(file);
         }
+
+        try {
+            InputSource fileSource = schemaResolver.resolveEntity(null, 
+                                                                        file, 
+                                                                        null);
+            String systemId = removePrefix(fileSource.getSystemId(),
+                                           XML_BEANS_SCHEMA_PREFIX);
+
+            return getSchemaInternal(sts, systemId);
+        } catch (XmlSchemaException e) {
+            if (LOG.isLoggable(Level.FINEST)) {
+                LOG.log(Level.FINEST,
+                        "The XML catalog is not configured to map the file [" + file + "]
", e);
+            }
+        }
+        return getSchemaInternal(sts, file);
+    }
+        
+    protected XmlSchema getSchemaInternal(SchemaTypeSystem sts, String file) {
         InputStream ins = sts.getSourceAsStream(file);
         if (ins == null) {
             return null;
@@ -181,7 +205,18 @@ class XmlBeansSchemaInitializer extends 
             throw new RuntimeException("Failed to find schema for: " + file, e);
         }
     }
-
+    /**
+     * Removes the prefix ending with the given suffix. For instance, the value
+     * XYZ where the prefix is Y, the result will be Z. The removed string is XY.
+     *
+     * @param value the value from where the returned string is extracted
+     * @param prefixSuffix the prefix
+     * @return the rest of the string
+     */
+    protected String removePrefix(String value, String prefixSuffix) {
+        return value.substring(value.indexOf(prefixSuffix) + prefixSuffix.length());
+    } 
+    
     @Override
     public void begin(MessagePartInfo part) {
         LOG.finest(part.getName().toString());

Modified: cxf/branches/2.2.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/xmlbeans/ClientServerXmlBeansTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/xmlbeans/ClientServerXmlBeansTest.java?rev=1005257&r1=1005256&r2=1005257&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/xmlbeans/ClientServerXmlBeansTest.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/databinding/src/test/java/org/apache/cxf/systest/xmlbeans/ClientServerXmlBeansTest.java
Wed Oct  6 21:14:37 2010
@@ -19,10 +19,15 @@
 
 package org.apache.cxf.systest.xmlbeans;
 
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.math.BigDecimal;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.xml.namespace.QName;
+import javax.xml.ws.BindingProvider;
 import javax.xml.ws.Holder;
 import javax.xml.ws.WebServiceException;
 import javax.xml.ws.soap.SOAPBinding;
@@ -30,7 +35,9 @@ import javax.xml.ws.soap.SOAPBinding;
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.headers.Header;
 import org.apache.cxf.interceptor.LoggingInInterceptor;
 import org.apache.cxf.interceptor.LoggingOutInterceptor;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
@@ -207,5 +214,49 @@ public class ClientServerXmlBeansTest ex
         }
 
     }
-
+    @Test
+    public void testXmlBeansHeader() throws Exception {
+        //CXF-2955
+        SpringBusFactory factory = new SpringBusFactory();
+        Bus bus = factory.createBus("org/apache/cxf/systest/xmlbeans/cxf_no_wsdl.xml");
+        BusFactory.setDefaultBus(bus);
+        URL wsdl = this.getClass().getResource("/wsdl_systest_databinding/xmlbeans/hello_world.wsdl");
+        assertNotNull("We should have found the WSDL here. " , wsdl);      
+        
+        SOAPService ss = new SOAPService(wsdl, SERVICE_NAME);
+        QName soapPort = new QName("http://apache.org/hello_world_soap_http/xmlbeans", "SoapPort");
+        ss.addPort(soapPort, SOAPBinding.SOAP11HTTP_BINDING, "http://localhost:" 
+                   + NOWSDL_PORT + "/SoapContext/SoapPort");
+        Greeter port = ss.getPort(soapPort, Greeter.class);
+        
+        Client client = ClientProxy.getClient(port);
+        
+        List<Header> headers = new ArrayList<Header>();
+        org.apache.helloWorldSoapHttp.xmlbeans.types.GreetMeDocument doc 
+            = org.apache.helloWorldSoapHttp.xmlbeans.types.GreetMeDocument.Factory.newInstance();
+        doc.addNewGreetMe().setRequestType("doc format header");
+        Header head = new Header(new QName("", "doc"), doc,
+                                 client.getEndpoint().getService().getDataBinding());
+        headers.add(head);
+        org.apache.helloWorldSoapHttp.xmlbeans.types.GreetMeDocument.GreetMe gm 
+            = org.apache.helloWorldSoapHttp.xmlbeans.types.GreetMeDocument.GreetMe.Factory.newInstance();
+        gm.setRequestType("non-doc format header");
+        head = new Header(new QName("http://somenamespace.com", "nondocheader"), gm,
+                          client.getEndpoint().getService().getDataBinding());
+        headers.add(head);
+        ((BindingProvider)port).getRequestContext().put(Header.HEADER_LIST, headers);
+        
+        String resp; 
+        ClientProxy.getClient(port).getInInterceptors().add(new LoggingInInterceptor());
+        
+        StringWriter sw = new StringWriter();
+        PrintWriter pw = new PrintWriter(sw);
+        ClientProxy.getClient(port).getOutInterceptors().add(new LoggingOutInterceptor(pw));
+        resp = port.sayHi();
+        assertEquals("We should get the right response", resp, "Bonjour");
+        assertTrue(sw.toString().contains("doc format header"));
+        assertTrue(sw.toString().contains("non-doc format header"));
+        assertTrue(sw.toString().contains("nondocheader"));
+        
+    }
 }



Mime
View raw message