cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r559870 - in /incubator/cxf/trunk: api/pom.xml rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ServiceImplTest.java
Date Thu, 26 Jul 2007 16:09:02 GMT
Author: dkulp
Date: Thu Jul 26 09:09:00 2007
New Revision: 559870

URL: http://svn.apache.org/viewvc?view=rev&rev=559870
Log:
[CXF-850] JAXB Context caching

Modified:
    incubator/cxf/trunk/api/pom.xml
    incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ServiceImplTest.java

Modified: incubator/cxf/trunk/api/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/pom.xml?view=diff&rev=559870&r1=559869&r2=559870
==============================================================================
--- incubator/cxf/trunk/api/pom.xml (original)
+++ incubator/cxf/trunk/api/pom.xml Thu Jul 26 09:09:00 2007
@@ -202,6 +202,32 @@
             </plugin>
         </plugins>
 
+        <pluginManagement>
+             <plugins>
+                 <plugin>
+                     <groupId>org.apache.maven.plugins</groupId>
+                     <artifactId>maven-javadoc-plugin</artifactId>
+                     <executions>
+                         <execution>
+                             <id>package</id>
+                             <phase>package</phase>
+                             <goals>
+                                 <goal>jar</goal>
+                             </goals>
+                         </execution>
+                     </executions>
+                     <configuration>
+                         <attach>true</attach>
+                         <quiet>true</quiet>
+                         <bottom>Apache CXF is an effort undergoing incubation at the
Apache Software Foundation(ASF) and sponsored by the Apache Incubator PMC.</bottom>
+                         <header>Apache CXF API</header>
+                         <footer>Apache CXF API</footer>
+                         <sourcepath>${basedir}/src/main/java${path.separator}${basedir}/target/generated/src/main/java</sourcepath>
+                         <subpackages>org.apache.cxf</subpackages>
+                     </configuration>
+                 </plugin>
+             </plugins>
+        </pluginManagement>
     </build>
 
     <profiles>
@@ -210,7 +236,7 @@
         </profile>
         <profile>
             <!-- default profile enables javadoc stuff -->
-            <id>javadoc</id>
+            <id>everything</id>
             <activation>
                 <activeByDefault>true</activeByDefault>
             </activation>
@@ -219,24 +245,6 @@
                     <plugin>
                         <groupId>org.apache.maven.plugins</groupId>
                         <artifactId>maven-javadoc-plugin</artifactId>
-                        <executions>
-                            <execution>
-                                <id>package</id>
-                                <phase>package</phase>
-                                <goals>
-                                    <goal>jar</goal>
-                                </goals>
-                            </execution>
-                        </executions>
-                        <configuration>
-                            <attach>true</attach>
-                            <quiet>true</quiet>
-                            <bottom>Apache CXF is an effort undergoing incubation at
the Apache Software Foundation(ASF) and sponsored by the Apache Incubator PMC.</bottom>
-                            <header>Apache CXF API</header>
-                            <footer>Apache CXF API</footer>
-                            <sourcepath>${basedir}/src/main/java${path.separator}${basedir}/target/generated/src/main/java</sourcepath>
-                            <subpackages>org.apache.cxf</subpackages>
-                        </configuration>
                     </plugin>
                 </plugins>
             </build>

Modified: incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?view=diff&rev=559870&r1=559869&r2=559870
==============================================================================
--- incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
(original)
+++ incubator/cxf/trunk/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
Thu Jul 26 09:09:00 2007
@@ -54,6 +54,7 @@
 
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.util.CacheMap;
 import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.databinding.DataBinding;
@@ -65,7 +66,7 @@
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.factory.ServiceConstructionException;
 import org.apache.cxf.service.model.ServiceInfo;
-import org.apache.cxf.ws.addressing.EndpointReferenceType;
+import org.apache.cxf.ws.addressing.ObjectFactory;
 import org.apache.cxf.wsdl11.WSDLServiceBuilder;
 import org.apache.ws.commons.schema.XmlSchemaCollection;
 
@@ -85,19 +86,24 @@
                                                                                XMLEventWriter.class,
                                                                                XMLStreamWriter.class};
 
+    private static final Map<Set<Class<?>>, JAXBContext> JAXBCONTEXT_CACHE
= 
+        new CacheMap<Set<Class<?>>, JAXBContext>();
+
     Class[] extraClass;
+    
     JAXBContext context;
+    Set<Class<?>> contextClasses;
 
-    Class cls;
-    
+    Class<?> cls;
 
+    
     public JAXBDataBinding() {
     }
     
     public JAXBDataBinding(Class<?>...classes) throws JAXBException {
-        Set<Class<?>> classSet = new HashSet<Class<?>>();
-        classSet.addAll(Arrays.asList(classes));
-        setContext(createJAXBContext(classSet));
+        contextClasses = new HashSet<Class<?>>();
+        contextClasses.addAll(Arrays.asList(classes));
+        setContext(createJAXBContext(contextClasses));
     }
 
     public JAXBDataBinding(JAXBContext context) {
@@ -143,7 +149,6 @@
             dr = (DataReader<T>)new DataReaderImpl<Node>(context);
         }
         
-        // TODO Auto-generated method stub
         return dr;
     }
 
@@ -157,10 +162,10 @@
             return;
         }
         
-        Set<Class<?>> classes = new HashSet<Class<?>>();
+        contextClasses = new HashSet<Class<?>>();
         for (ServiceInfo serviceInfo : service.getServiceInfos()) {
             JAXBContextInitializer initializer = 
-                new JAXBContextInitializer(serviceInfo, classes);
+                new JAXBContextInitializer(serviceInfo, contextClasses);
             initializer.walk();
     
         }
@@ -169,7 +174,7 @@
             if (service.getServiceInfos().size() > 0) {
                 tns = service.getServiceInfos().get(0).getInterface().getName().getNamespaceURI();
             }
-            setContext(createJAXBContext(classes, tns));
+            setContext(createJAXBContext(contextClasses, tns));
         } catch (JAXBException e1) {
             throw new ServiceConstructionException(e1);
         }
@@ -210,7 +215,8 @@
                 // fall back if we're using another jaxb implementation
                 try {
                     riContext = (JAXBContextImpl)
-                        ContextFactory.createContext(classes.toArray(new Class[classes.size()]),
null);
+                        ContextFactory.createContext(
+                            contextClasses.toArray(new Class[contextClasses.size()]), null);
                 } catch (JAXBException e) {
                     throw new ServiceConstructionException(e);
                 }
@@ -335,25 +341,30 @@
             }
         }
         
-        JAXBContext ctx = JAXBContext.newInstance(classes.toArray(new Class[classes.size()]),
map);
-        if (ctx instanceof JAXBContextImpl) {
-            JAXBContextImpl rictx = (JAXBContextImpl)ctx;
-            if (rictx.getBeanInfo(EndpointReferenceType.class) != null) {
-                //ws-addressing is used, lets add the specific types
-                try {
-                    classes.add(Class.forName("org.apache.cxf.ws.addressing.wsdl.ObjectFactory"));
-                    classes.add(Class.forName("org.apache.cxf.ws.addressing.wsdl.AttributedQNameType"));

-                    classes.add(Class.forName("org.apache.cxf.ws.addressing.wsdl.ServiceNameType"));
-                    ctx = JAXBContext.newInstance(classes.toArray(new Class[classes.size()]),
map);
-                } catch (ClassNotFoundException e) {
-                    // REVISIT - ignorable if WS-ADDRESSING not available?
-                    // maybe add a way to allow interceptors to add stuff to the
-                    // context?
-                } 
+        addWsAddressingTypes(classes);
+
+        synchronized (JAXBCONTEXT_CACHE) {
+            if (!JAXBCONTEXT_CACHE.containsKey(classes)) {
+                JAXBContext ctx = JAXBContext.newInstance(classes.toArray(new Class[classes.size()]),
map);
+                JAXBCONTEXT_CACHE.put(classes, ctx);
             }
         }
-        
-        return ctx;
-    }
 
+        return JAXBCONTEXT_CACHE.get(classes);
+    }
+
+    private void addWsAddressingTypes(Set<Class<?>> classes) {
+        if (classes.contains(ObjectFactory.class)) {
+            // ws-addressing is used, lets add the specific types
+            try {
+                classes.add(Class.forName("org.apache.cxf.ws.addressing.wsdl.ObjectFactory"));
+                classes.add(Class.forName("org.apache.cxf.ws.addressing.wsdl.AttributedQNameType"));
+                classes.add(Class.forName("org.apache.cxf.ws.addressing.wsdl.ServiceNameType"));
+            } catch (ClassNotFoundException unused) {
+                // REVISIT - ignorable if WS-ADDRESSING not available?
+                // maybe add a way to allow interceptors to add stuff to the
+                // context?
+            } 
+        }
+    }
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ServiceImplTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ServiceImplTest.java?view=diff&rev=559870&r1=559869&r2=559870
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ServiceImplTest.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/ServiceImplTest.java
Thu Jul 26 09:09:00 2007
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.jaxws;
 
+import java.lang.reflect.Proxy;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -40,6 +41,7 @@
 import org.apache.cxf.endpoint.Client;
 import org.apache.cxf.endpoint.NullConduitSelector;
 import org.apache.cxf.frontend.ClientProxy;
+import org.apache.cxf.jaxb.JAXBDataBinding;
 import org.apache.hello_world_soap_http.Greeter;
 import org.apache.hello_world_soap_http.SOAPService;
 import org.junit.Test;
@@ -160,6 +162,36 @@
 
         CalculatorPortType cal = (CalculatorPortType)service.getPort(PORT_1, CalculatorPortType.class);
         assertNotNull(cal);
+    }
+
+    
+    @Test
+    public void testJAXBCachedOnRepeatGetPort() {
+        URL wsdl1 = getClass().getResource("/wsdl/calculator.wsdl");
+        assertNotNull(wsdl1);
+        
+        ServiceImpl service = new ServiceImpl(getBus(), wsdl1, SERVICE_1, ServiceImpl.class);
+
+        CalculatorPortType cal1 = (CalculatorPortType)service.getPort(PORT_1, CalculatorPortType.class);
+        assertNotNull(cal1);
+        
+        ClientProxy cp = (ClientProxy)Proxy.getInvocationHandler(cal1);
+        JAXBDataBinding db1 = (JAXBDataBinding) cp.getClient().getEndpoint().getService().getDataBinding();
+        assertNotNull(db1);
+        
+        System.gc();
+        System.gc();
+        System.gc();
+        System.gc();
+        
+        CalculatorPortType cal2 = (CalculatorPortType)service.getPort(PORT_1, CalculatorPortType.class);
+        assertNotNull(cal2);
+
+        cp = (ClientProxy)Proxy.getInvocationHandler(cal2);
+        JAXBDataBinding db2 = (JAXBDataBinding) cp.getClient().getEndpoint().getService().getDataBinding();
+        assertNotNull(db2);
+
+        assertEquals("got cached JAXBContext", db1.getContext(), db2.getContext());
     }
 
     @Test



Mime
View raw message