cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1053660 - in /cxf/branches/2.3.x-fixes: ./ common/common/src/main/java/org/apache/cxf/jaxb/ rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/ap...
Date Wed, 29 Dec 2010 16:02:17 GMT
Author: sergeyb
Date: Wed Dec 29 16:02:17 2010
New Revision: 1053660

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

........
  r1053654 | sergeyb | 2010-12-29 15:38:14 +0000 (Wed, 29 Dec 2010) | 1 line
  
  [CXF-3154] Enhancing JAXBElementProvider to support single JAXBContexts
........

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
    cxf/branches/2.3.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanTest.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/servers.xml

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Dec 29 16:02:17 2010
@@ -1 +1 @@
-/cxf/trunk:1041183,1041790,1041993,1042346,1042571,1042724,1042805,1042821,1043225,1043229,1043902,1043907,1043954,1044085,1044238-1044305,1045024,1048915,1048919,1048930,1049078,1049426,1049937,1050005,1050021,1050095,1050102,1050113,1050156,1050165,1050280,1051115,1051613,1051790,1051792,1052338,1052516,1052541,1052990,1052993-1052994,1052996-1052997,1053114,1053119,1053123,1053239,1053290,1053402
+/cxf/trunk:1041183,1041790,1041993,1042346,1042571,1042724,1042805,1042821,1043225,1043229,1043902,1043907,1043954,1044085,1044238-1044305,1045024,1048915,1048919,1048930,1049078,1049426,1049937,1050005,1050021,1050095,1050102,1050113,1050156,1050165,1050280,1051115,1051613,1051790,1051792,1052338,1052516,1052541,1052990,1052993-1052994,1052996-1052997,1053114,1053119,1053123,1053239,1053290,1053402,1053654

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

Modified: cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java?rev=1053660&r1=1053659&r2=1053660&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
(original)
+++ cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/jaxb/JAXBUtils.java
Wed Dec 29 16:02:17 2010
@@ -789,8 +789,17 @@ public final class JAXBUtils {
         return null;
     }
     
-    public static void scanPackages(Set<Class<?>> classes, 
+    public static void scanPackages(Set<Class<?>> classes,
+                                    Class[] extraClass,
                                     Map<Package, CachedClass> objectFactoryCache) {
+        
+        // add user extra class into jaxb context
+        if (extraClass != null && extraClass.length > 0) {
+            for (Class clz : extraClass) {
+                classes.add(clz);
+            }
+        }
+        
         // try and read any jaxb.index files that are with the other classes.
         // This should
         // allow loading of extra classes (such as subclasses for inheritance

Modified: cxf/branches/2.3.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?rev=1053660&r1=1053659&r2=1053660&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
Wed Dec 29 16:02:17 2010
@@ -461,14 +461,7 @@ public class JAXBDataBinding extends Abs
                                                                String defaultNs)
         throws JAXBException {
 
-        // add user extra class into jaxb context
-        if (extraClass != null && extraClass.length > 0) {
-            for (Class clz : extraClass) {
-                classes.add(clz);
-            }
-        }
-
-        JAXBUtils.scanPackages(classes, OBJECT_FACTORY_CACHE);
+        JAXBUtils.scanPackages(classes, extraClass, OBJECT_FACTORY_CACHE);
         //JAXBUtils.scanPackages(classes, new HashMap<Package, CachedClass>());
         addWsAddressingTypes(classes);
 

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java?rev=1053660&r1=1053659&r2=1053660&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
Wed Dec 29 16:02:17 2010
@@ -282,6 +282,7 @@ public class AbstractJAXRSFactoryBean ex
         if (schemaLocations != null) {
             factory.setSchemaLocations(schemaLocations);
         }
+        factory.initProviders(serviceFactory.getRealClassResourceInfo());
         ep.put(ProviderFactory.class.getName(), factory);
         return factory;
     }

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=1053660&r1=1053659&r2=1053660&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Wed Dec 29 16:02:17 2010
@@ -47,7 +47,6 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
 import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.ParserConfigurationException;
@@ -171,8 +170,9 @@ public class WadlGenerator implements Re
         
         Set<Class<?>> allTypes = 
             ResourceUtils.getAllRequestResponseTypes(cris, useJaxbContextForQnames).keySet();
-        
-        JAXBContext context = createJaxbContext(allTypes);
+        JAXBContext context = useJaxbContextForQnames 
+            ? ResourceUtils.createJaxbContext(new HashSet<Class<?>>(allTypes),
null, null) : null;
+
         SchemaWriter schemaWriter = createSchemaWriter(context, ui);
         ElementQNameResolver qnameResolver = 
             schemaWriter == null ? null : createElementQNameResolver(context);
@@ -649,23 +649,7 @@ public class WadlGenerator implements Re
         return prefix;
     }
     
-    private JAXBContext createJaxbContext(Set<Class<?>> classes) {
-        if (!useJaxbContextForQnames || classes.isEmpty()) {
-            return null;
-        }
-        Set<Class<?>> classesToBeBound = new HashSet<Class<?>>(classes);
-        JAXBUtils.scanPackages(classesToBeBound, null);
 
-        JAXBContext ctx;
-        try {
-            ctx = JAXBContext.newInstance(classesToBeBound.toArray(new Class[classes.size()]));
-            return ctx;
-        } catch (JAXBException ex) {
-            LOG.fine("No JAXB context can be created");
-        }
-        return null;
-    }
-    
     private boolean isFormRequest(OperationResourceInfo ori) {
         for (Parameter p : ori.getParameters()) {
             if (p.getType() == ParameterType.FORM) {

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java?rev=1053660&r1=1053659&r2=1053660&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java
Wed Dec 29 16:02:17 2010
@@ -23,6 +23,7 @@ import java.util.List;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 
 public abstract class AbstractConfigurableProvider {
 
@@ -64,4 +65,8 @@ public abstract class AbstractConfigurab
     public boolean getEnableBuffering() {
         return enableBuffering;
     }
+    
+    public void init(List<ClassResourceInfo> resources) {
+        // complete
+    }
 }

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1053660&r1=1053659&r2=1053660&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Wed Dec 29 16:02:17 2010
@@ -71,9 +71,11 @@ import org.apache.cxf.jaxb.JAXBBeanInfo;
 import org.apache.cxf.jaxb.JAXBContextProxy;
 import org.apache.cxf.jaxb.JAXBUtils;
 import org.apache.cxf.jaxrs.ext.MessageContext;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.jaxrs.utils.schemas.SchemaHandler;
 import org.apache.cxf.staxutils.DelegatingXMLStreamWriter;
 import org.apache.cxf.staxutils.DepthXMLStreamReader;
@@ -117,6 +119,31 @@ public abstract class AbstractJAXBProvid
     private Map<String, Object> uProperties;
     
     private boolean skipJaxbChecks;
+    private boolean singleJaxbContext;
+    private Class[] extraClass;
+    
+    public void setSingleJaxbContext(boolean useSingleContext) {
+        singleJaxbContext = useSingleContext;
+    }
+    
+    public void setExtraClass(Class[] userExtraClass) {
+        extraClass = userExtraClass;
+    }
+    
+    @Override
+    public void init(List<ClassResourceInfo> cris) {
+        if (singleJaxbContext) {
+            Set<Class<?>> allTypes = 
+                new HashSet<Class<?>>(ResourceUtils.getAllRequestResponseTypes(cris,
true).keySet());
+            JAXBContext context = 
+                ResourceUtils.createJaxbContext(allTypes, extraClass, cProperties);
+            if (context != null) {
+                for (Class<?> cls : allTypes) {
+                    classContexts.put(cls, context);
+                }
+            }
+        }
+    }
     
     public void setContextProperties(Map<String, Object> contextProperties) {
         cProperties = contextProperties;
@@ -496,7 +523,7 @@ public abstract class AbstractJAXBProvid
     }
 
     
-    static void clearContexts() {
+    public static void clearContexts() {
         classContexts.clear();
         packageContexts.clear();
     }

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1053660&r1=1053659&r2=1053660&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Wed Dec 29 16:02:17 2010
@@ -27,8 +27,10 @@ import java.lang.reflect.TypeVariable;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Set;
 import java.util.logging.Logger;
 
 import javax.ws.rs.core.MediaType;
@@ -48,6 +50,7 @@ import org.apache.cxf.jaxrs.ext.RequestH
 import org.apache.cxf.jaxrs.ext.ResponseHandler;
 import org.apache.cxf.jaxrs.impl.RequestPreprocessor;
 import org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.model.wadl.WadlGenerator;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
@@ -649,6 +652,21 @@ public final class ProviderFactory {
             }
         }
     }
+
+    public void initProviders(List<ClassResourceInfo> cris) {
+        Set<Object> set = new HashSet<Object>();
+        set.addAll(messageReaders);
+        set.addAll(messageWriters);
+        for (Object o : set) {
+            Object provider = ((ProviderInfo)o).getProvider();
+            if (provider instanceof AbstractConfigurableProvider) {
+                ((AbstractConfigurableProvider)provider).init(cris);
+            }
+        }
+        if (this != SHARED_FACTORY) {
+            SHARED_FACTORY.initProviders(cris);
+        }
+    }
     
     private static class ExceptionMapperComparator implements 
         Comparator<ExceptionMapper<? extends Throwable>> {

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=1053660&r1=1053659&r2=1053660&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
Wed Dec 29 16:02:17 2010
@@ -56,7 +56,9 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.Provider;
+import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
 
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
@@ -68,6 +70,7 @@ import org.apache.cxf.common.i18n.Bundle
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.jaxb.JAXBUtils;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
@@ -621,4 +624,24 @@ public final class ResourceUtils {
         }
         return true;
     }
+    
+    //TODO : consider moving JAXBDataBinding.createContext to JAXBUtils
+    public static JAXBContext createJaxbContext(Set<Class<?>> classes, Class[]
extraClass, 
+                                          Map<String, Object> contextProperties) {
+        if (classes == null || classes.isEmpty()) {
+            return null;
+        }
+        JAXBUtils.scanPackages(classes, extraClass, null);
+
+        JAXBContext ctx;
+        try {
+            ctx = JAXBContext.newInstance(classes.toArray(new Class[classes.size()]),
+                                          contextProperties);
+            return ctx;
+        } catch (JAXBException ex) {
+            LOG.fine("No JAXB context can be created");
+        }
+        return null;
+    }
+                                         
 }

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java?rev=1053660&r1=1053659&r2=1053660&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/JAXBElementProviderTest.java
Wed Dec 29 16:02:17 2010
@@ -38,6 +38,8 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
 import javax.ws.rs.core.MediaType;
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBElement;
@@ -61,14 +63,17 @@ import org.w3c.dom.Node;
 import org.xml.sax.ContentHandler;
 
 import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.provider.index.TestBean;
 import org.apache.cxf.jaxrs.resources.Book;
+import org.apache.cxf.jaxrs.resources.BookStore;
 import org.apache.cxf.jaxrs.resources.CollectionsResource;
 import org.apache.cxf.jaxrs.resources.ManyTags;
 import org.apache.cxf.jaxrs.resources.SuperBook;
 import org.apache.cxf.jaxrs.resources.TagVO;
 import org.apache.cxf.jaxrs.resources.TagVO2;
 import org.apache.cxf.jaxrs.resources.Tags;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -76,6 +81,33 @@ import org.junit.Test;
 public class JAXBElementProviderTest extends Assert {
 
     @Test
+    public void testSingleJAXBContext() throws Exception {
+        ClassResourceInfo cri = 
+            ResourceUtils.createClassResourceInfo(JAXBResource.class, JAXBResource.class,
true, true);
+        JAXBElementProvider provider = new JAXBElementProvider();
+        provider.setSingleJaxbContext(true);
+        provider.init(Collections.singletonList(cri));
+        JAXBContext bookContext = provider.getJAXBContext(Book.class, Book.class);
+        assertNotNull(bookContext);
+        JAXBContext superBookContext = provider.getJAXBContext(SuperBook.class, SuperBook.class);
+        assertSame(bookContext, superBookContext);
+    }
+    
+    @Test
+    public void testExtraClass() throws Exception {
+        ClassResourceInfo cri = 
+            ResourceUtils.createClassResourceInfo(BookStore.class, BookStore.class, true,
true);
+        JAXBElementProvider provider = new JAXBElementProvider();
+        provider.setSingleJaxbContext(true);
+        provider.setExtraClass(new Class[]{SuperBook.class});
+        provider.init(Collections.singletonList(cri));
+        JAXBContext bookContext = provider.getJAXBContext(Book.class, Book.class);
+        assertNotNull(bookContext);
+        JAXBContext superBookContext = provider.getJAXBContext(SuperBook.class, SuperBook.class);
+        assertSame(bookContext, superBookContext);
+    }
+    
+    @Test
     public void testIsWriteableList() throws Exception {
         testIsWriteableCollection("getBooks");
     }
@@ -1029,4 +1061,18 @@ public class JAXBElementProviderTest ext
         }
         
     }
+    
+    @Path("/")
+    public static class JAXBResource {
+        
+        @GET
+        public Book getBook() {
+            return null;
+        }
+        
+        @GET
+        public SuperBook getSuperBook() {
+            return null;
+        }
+    }
 }

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanTest.java?rev=1053660&r1=1053659&r2=1053660&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanTest.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/JAXRSServerFactoryBeanTest.java
Wed Dec 29 16:02:17 2010
@@ -18,13 +18,19 @@
  */
 package org.apache.cxf.jaxrs.spring;
 
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
 import javax.xml.namespace.QName;
 
 import org.apache.cxf.BusFactory;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
+import org.apache.cxf.jaxrs.resources.Book;
 import org.apache.cxf.jaxrs.resources.BookStore;
 import org.apache.cxf.jaxrs.resources.BookStoreNoAnnotations;
 import org.apache.cxf.jaxrs.resources.BookStoreSubresourcesOnly;
+import org.apache.cxf.jaxrs.resources.SuperBook;
 
 import org.junit.After;
 import org.junit.Assert;
@@ -62,8 +68,8 @@ public class JAXRSServerFactoryBeanTest 
         
         sfb = (JAXRSServerFactoryBean)ctx.getBean("inlineProvider");
         assertNotNull("The provider should not be null", sfb.getProviders());
-        assertEquals("Get a wrong provider size", sfb.getProviders().size(), 2);
-        
+        assertEquals("Get a wrong provider size", sfb.getProviders().size(), 3);
+        verifyJaxbProvider(sfb.getProviders());
         sfb = (JAXRSServerFactoryBean)ctx.getBean("moduleServer");
         assertNotNull("The resource classes should not be null", sfb.getResourceClasses());
         assertEquals("Get a wrong ResourceClasses size", 1, sfb.getResourceClasses().size());
@@ -71,4 +77,20 @@ public class JAXRSServerFactoryBeanTest 
                      sfb.getResourceClasses().get(0));
         
     }
+    
+    private void verifyJaxbProvider(List<?> providers) throws Exception {
+        JAXBElementProvider provider = null;
+        for (Object o : providers) {
+            if (o instanceof JAXBElementProvider) {
+                provider = (JAXBElementProvider)o;
+                
+            }
+        }
+        assertNotNull(provider);
+        JAXBContext c1 = provider.getClassContext(Book.class);
+        assertNotNull(c1);
+        JAXBContext c2 = provider.getClassContext(SuperBook.class);
+        assertSame(c1, c2);
+        JAXBElementProvider.clearContexts();
+    }
 }

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/servers.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/servers.xml?rev=1053660&r1=1053659&r2=1053660&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/servers.xml
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/spring/servers.xml
Wed Dec 29 16:02:17 2010
@@ -57,6 +57,7 @@ http://cxf.apache.org/jaxrs http://cxf.a
     <jaxrs:providers>
         <ref bean="feed"/>
         <ref bean="entry"/>
+        <ref bean="jaxb"/>
     </jaxrs:providers>	
     <jaxrs:extensionMappings>
       <entry key="json" value="application/json"/>
@@ -65,6 +66,14 @@ http://cxf.apache.org/jaxrs http://cxf.a
   
   <bean id="feed" class="org.apache.cxf.jaxrs.provider.AtomFeedProvider"/>
   <bean id="entry" class="org.apache.cxf.jaxrs.provider.AtomEntryProvider"/>
+  <bean id="jaxb" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
+      <property name="singleJaxbContext" value="true"/>
+      <property name="extraClass">
+         <list>
+           <value>org.apache.cxf.jaxrs.resources.SuperBook</value>
+         </list>
+      </property>
+  </bean>
   
   <jaxrs:server id="moduleServer"
     modelRef="classpath:/org/apache/cxf/jaxrs/spring/resources.xml"



Mime
View raw message