cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r889805 - in /cxf/branches/2.2.x-fixes: ./ rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/ rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/
Date Fri, 11 Dec 2009 20:37:25 GMT
Author: dkulp
Date: Fri Dec 11 20:37:24 2009
New Revision: 889805

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

........
  r889790 | dkulp | 2009-12-11 14:55:59 -0500 (Fri, 11 Dec 2009) | 1 line
  
  [CXF-1510] Support for anonymous root types
........
  r889796 | dkulp | 2009-12-11 15:24:14 -0500 (Fri, 11 Dec 2009) | 1 line
  
  [CXF-1510] Only if it's not in a wrapper element
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
    cxf/branches/2.2.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Dec 11 20:37:24 2009
@@ -1 +1 @@
-/cxf/trunk:889426,889595,889601,889740
+/cxf/trunk:889426,889595,889601,889740,889790-889796

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

Modified: cxf/branches/2.2.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java?rev=889805&r1=889804&r2=889805&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBContextInitializer.java
Fri Dec 11 20:37:24 2009
@@ -35,11 +35,16 @@
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlSeeAlso;
 import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.XmlType;
 import javax.xml.bind.annotation.adapters.XmlAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import javax.xml.namespace.QName;
 
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
+import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.service.ServiceModelVisitor;
 import org.apache.cxf.service.model.MessageInfo;
 import org.apache.cxf.service.model.MessagePartInfo;
@@ -53,10 +58,14 @@
 class JAXBContextInitializer extends ServiceModelVisitor {
 
     private Set<Class<?>> classes;
+    private Collection<Object> typeReferences;
 
-    public JAXBContextInitializer(ServiceInfo serviceInfo, Set<Class<?>> classes)
{
+    public JAXBContextInitializer(ServiceInfo serviceInfo,
+                                  Set<Class<?>> classes,
+                                  Collection<Object> typeReferences) {
         super(serviceInfo);
         this.classes = classes;
+        this.typeReferences = typeReferences;
     }
 
     @Override
@@ -149,9 +158,39 @@
             }
         }
         if (clazz != null) {
+            if (!isFromWrapper 
+                && clazz.getAnnotation(XmlRootElement.class) == null
+                && clazz.getAnnotation(XmlType.class) != null
+                && StringUtils.isEmpty(clazz.getAnnotation(XmlType.class).name()))
{
+                createTypeReference(part.getName(), clazz);
+            }
+            
             addClass(clazz);
         }
     }
+    
+    private void createTypeReference(QName n, Class<?> cls) {
+        Class<?> refClass = null;
+        try {
+            refClass = ClassLoaderUtils.loadClass("com.sun.xml.bind.api.TypeReference", this.getClass());
+        } catch (Throwable ex) {
+            try {
+                refClass = ClassLoaderUtils.loadClass("com.sun.xml.internal.bind.api.TypeReference",
+                                                      this.getClass());
+            } catch (Throwable ex2) {
+                //ignore
+            }
+        }
+        if (refClass != null) {
+            try {
+                Object o =  refClass.getConstructor(QName.class, Type.class, new Annotation[0].getClass())
+                    .newInstance(n, cls, new Annotation[0]);
+                typeReferences.add(o);
+            } catch (Throwable e) {
+                //ignore
+            }
+        }
+    }
 
     private void checkForAdapter(Class<?> clazz, Annotation[] anns) {
         if (anns != null) {

Modified: cxf/branches/2.2.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?rev=889805&r1=889804&r2=889805&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
Fri Dec 11 20:37:24 2009
@@ -61,6 +61,7 @@
 import org.xml.sax.SAXException;
 
 import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.common.util.CacheMap;
 import org.apache.cxf.common.util.CachedClass;
@@ -212,6 +213,7 @@
 
     JAXBContext context;
     Set<Class<?>> contextClasses;
+    Collection<Object> typeRefs = new ArrayList<Object>();
 
     Class<?> cls;
 
@@ -320,7 +322,8 @@
 
         contextClasses = new LinkedHashSet<Class<?>>();
         for (ServiceInfo serviceInfo : service.getServiceInfos()) {
-            JAXBContextInitializer initializer = new JAXBContextInitializer(serviceInfo,
contextClasses);
+            JAXBContextInitializer initializer 
+                = new JAXBContextInitializer(serviceInfo, contextClasses, typeRefs);
             initializer.walk();
             if (serviceInfo.getProperty("extra.class") != null) {
                 Set<Class<?>> exClasses = serviceInfo.getProperty("extra.class",
Set.class);
@@ -503,32 +506,86 @@
         }
 
         CachedContextAndSchemas cachedContextAndSchemas = null;
-        synchronized (JAXBCONTEXT_CACHE) {
-            cachedContextAndSchemas = JAXBCONTEXT_CACHE.get(classes);
+        if (typeRefs.isEmpty()) {
+            synchronized (JAXBCONTEXT_CACHE) {
+                cachedContextAndSchemas = JAXBCONTEXT_CACHE.get(classes);
+            }
         }
         if (cachedContextAndSchemas == null) {
-            JAXBContext ctx;
-            try {
-                ctx = JAXBContext.newInstance(classes.toArray(new Class[classes.size()]),
map);
-            } catch (JAXBException ex) {
-                if (map.containsKey("com.sun.xml.bind.defaultNamespaceRemap")
-                    && ex.getMessage().contains("com.sun.xml.bind.defaultNamespaceRemap"))
{
-                    map.put("com.sun.xml.internal.bind.defaultNamespaceRemap",
-                            map.remove("com.sun.xml.bind.defaultNamespaceRemap"));
-                    ctx = JAXBContext.newInstance(classes.toArray(new Class[classes.size()]),
map);
-                } else {
-                    throw ex;
-                }
-            }
+            JAXBContext ctx = createContext(classes, map);
             cachedContextAndSchemas = new CachedContextAndSchemas(ctx);
             synchronized (JAXBCONTEXT_CACHE) {
-                JAXBCONTEXT_CACHE.put(classes, cachedContextAndSchemas);
+                if (typeRefs.isEmpty()) {
+                    JAXBCONTEXT_CACHE.put(classes, cachedContextAndSchemas);
+                }
             }
         }
 
         return cachedContextAndSchemas;
     }
     
+    private JAXBContext createContext(Set<Class<?>> classes, 
+                                      Map<String, Object> map)
+        throws JAXBException {
+        JAXBContext ctx;
+        if (!typeRefs.isEmpty()) {
+            Class<?> fact = null;
+            String pfx = "com.sun.xml.bind.";
+            try {
+                fact = ClassLoaderUtils.loadClass("com.sun.xml.bind.v2.ContextFactory",
+                                                  getClass());
+            } catch (Throwable t) {
+                try {
+                    fact = ClassLoaderUtils.loadClass("com.sun.xml.internal.bind.v2.ContextFactory",
+                                                      getClass());
+                    pfx = "com.sun.xml.internal.bind.";
+                } catch (Throwable t2) {
+                    //ignore
+                }
+            }
+            if (fact != null) {
+                for (Method m : fact.getMethods()) {
+                    if ("createContext".equals(m.getName())
+                        && m.getParameterTypes().length == 9) {
+                        try {
+                            return (JAXBContext)m.invoke(null, 
+                                     classes.toArray(new Class[classes.size()]),
+                                     typeRefs,
+                                     map.get(pfx + "subclassReplacements"),
+                                     map.get(pfx + "defaultNamespaceRemap"),
+                                     map.get(pfx + "c14n") == null
+                                         ? Boolean.FALSE 
+                                             : map.get(pfx + "c14n"),
+                                     map.get(pfx + "v2.model.annotation.RuntimeAnnotationReader"),
+                                     map.get(pfx + "XmlAccessorFactory") == null 
+                                         ? Boolean.FALSE 
+                                             : map.get(pfx + "XmlAccessorFactory"),
+                                     map.get(pfx + "treatEverythingNillable") == null
+                                         ? Boolean.FALSE : map.get(pfx + "treatEverythingNillable"),
+                                     map.get("retainReferenceToInfo") == null 
+                                         ? Boolean.FALSE : map.get("retainReferenceToInfo"));

+                        } catch (Throwable e) {
+                            //ignore
+                        }
+                    }
+                }
+            }
+        }
+        try {
+            ctx = JAXBContext.newInstance(classes.toArray(new Class[classes.size()]), map);
+        } catch (JAXBException ex) {
+            if (map.containsKey("com.sun.xml.bind.defaultNamespaceRemap")
+                && ex.getMessage().contains("com.sun.xml.bind.defaultNamespaceRemap"))
{
+                map.put("com.sun.xml.internal.bind.defaultNamespaceRemap",
+                        map.remove("com.sun.xml.bind.defaultNamespaceRemap"));
+                ctx = JAXBContext.newInstance(classes.toArray(new Class[classes.size()]),
map);
+            } else {
+                throw ex;
+            }
+        }
+        return ctx;
+    }
+    
     private boolean checkObjectFactoryNamespaces(Class<?> clz) {
         for (Method meth : clz.getMethods()) {
             XmlElementDecl decl = meth.getAnnotation(XmlElementDecl.class);

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java?rev=889805&r1=889804&r2=889805&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/CodeFirstTest.java
Fri Dec 11 20:37:24 2009
@@ -24,8 +24,14 @@
 import java.util.List;
 import java.util.concurrent.Executor;
 
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
 import javax.wsdl.Definition;
 import javax.wsdl.factory.WSDLFactory;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
 import javax.xml.namespace.QName;
 
 import org.w3c.dom.Document;
@@ -327,10 +333,82 @@
     }
     
     public static class GenericsServiceImpl implements GenericsService<Entity<String>,
QuerySummary> {
-
         public QueryResult<Entity<String>, QuerySummary> read(String query, String
uc) {
             return null;
         }
+    }
+    
+    @Test
+    public void testCXF1510() throws Exception {
+        JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean(); 
+        factory.setServiceClass(NoRootBare.class); 
+        factory.setServiceBean(new NoRootBareImpl()); 
+        factory.setAddress("local://localhost/testNoRootBare"); 
+        Server server = factory.create();
+        server.start();
+        
+        QName serviceName = new QName("http://service.jaxws.cxf.apache.org/", "NoRootBareService");
+        QName portName = new QName("http://service.jaxws.cxf.apache.org/", "NoRootBarePort");
+
+        ServiceImpl service = new ServiceImpl(getBus(), (URL)null, serviceName, null);
+        service.addPort(portName, "http://schemas.xmlsoap.org/soap/",
+                        "local://localhost/testNoRootBare"); 
         
+        NoRootBare proxy = service.getPort(portName, NoRootBare.class);
+        assertEquals("hello", proxy.echoString(new NoRootRequest("hello")).getMessage());
+    }
+    
+    @WebService
+    @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
+    public static interface NoRootBare {
+        NoRootResponse echoString(NoRootRequest request);
+    }
+    
+    @WebService
+    public static class NoRootBareImpl implements NoRootBare {
+        public NoRootResponse echoString(NoRootRequest request) {
+            return new NoRootResponse(request.getMessage());
+        }
+    }
+    
+    @XmlType(name = "")
+    @XmlAccessorType(XmlAccessType.FIELD)
+    public static class NoRootRequest {
+        @XmlElement
+        private String message;
+
+        public NoRootRequest() {
+        }
+        public NoRootRequest(String m) {
+            message = m;
+        }
+
+        public void setMessage(String message) {
+            this.message = message;
+        }
+
+        public String getMessage() {
+            return message;
+        }
+    }
+    @XmlType(name = "")
+    @XmlAccessorType(XmlAccessType.FIELD)
+    public static class NoRootResponse {
+        @XmlElement
+        private String message;
+        
+        public NoRootResponse() {
+        }
+        public NoRootResponse(String m) {
+            message = m;
+        }
+
+        public void setMessage(String message) {
+            this.message = message;
+        }
+
+        public String getMessage() {
+            return message;
+        }
     }
 }



Mime
View raw message