cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r808540 - in /cxf/branches/2.2.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ systests/sr...
Date Thu, 27 Aug 2009 17:11:41 GMT
Author: dkulp
Date: Thu Aug 27 17:11:40 2009
New Revision: 808540

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

........
  r808107 | sergeyb | 2009-08-26 12:26:40 -0400 (Wed, 26 Aug 2009) | 1 line
  
  JAXRS : supporting the injection of proxified providers and sorting message providers by
type
........

Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
    cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
    cxf/branches/2.2.x-fixes/systests/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug 27 17:11:40 2009
@@ -1 +1 @@
-/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,794892,795044,795104,795160,795583,795907,796022-796023,796352,796593,796741,796780,796994-796997,797117,797159,797192,797194,797231-797233,797442,797505,797517,797534,797581-797583,797587,797640,797651,797699,797882-797883,798344-798346,798363,798461,798479,798533,798551,798557,798561-798562,798570,798573,79858
 4,798654,798748-798749,798816,798891,798929-798930,799245,799267,799439,799448,799637,799723-799724,799792,800453,800497-800498,801380-801381,801447,801962,802892,803056,803129,803419,803460,803493,803689,804002,804175,804276,805784,805907,805909,806020-806021,806023,806405-806406,806576,806602-806604,806620,806627,806631,806633,806638,806687,806876,806922,806979-806982,807181,807205,807295,807748,807807,808035,808069,808085
+/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396,794680,794728,794771,794778-794780,794892,795044,795104,795160,795583,795907,796022-796023,796352,796593,796741,796780,796994-796997,797117,797159,797192,797194,797231-797233,797442,797505,797517,797534,797581-797583,797587,797640,797651,797699,797882-797883,798344-798346,798363,798461,798479,798533,798551,798557,798561-798562,798570,798573,79858
 4,798654,798748-798749,798816,798891,798929-798930,799245,799267,799439,799448,799637,799723-799724,799792,800453,800497-800498,801380-801381,801447,801962,802892,803056,803129,803419,803460,803493,803689,804002,804175,804276,805784,805907,805909,806020-806021,806023,806405-806406,806576,806602-806604,806620,806627,806631,806633,806638,806687,806876,806922,806979-806982,807181,807205,807295,807748,807807,808035,808069,808085,808107

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

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=808540&r1=808539&r2=808540&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Thu Aug 27 17:11:40 2009
@@ -38,6 +38,7 @@
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.ClassHelper;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.jaxrs.client.ResponseExceptionMapper;
 import org.apache.cxf.jaxrs.ext.ParameterHandler;
@@ -185,7 +186,7 @@
         if (candidates.size() == 0) {
             return null;
         }
-        Collections.sort(candidates, new ParameterHandlerComparator());
+        Collections.sort(candidates, new ClassComparator());
         return candidates.get(0);
     }
     
@@ -201,20 +202,25 @@
         if (candidates.size() == 0) {
             return null;
         }
-        Collections.sort(candidates, new ResponseExceptionMapperComparator());
+        Collections.sort(candidates, new ClassComparator());
         return candidates.get(0);
     }
     
     private static void handleMapper(List<Object> candidates, ProviderInfo em, 
                                      Class<?> expectedType, Message m) {
         
-        Type[] types = em.getProvider().getClass().getGenericInterfaces();
+        Class<?> mapperClass =  ClassHelper.getRealClass(em.getProvider());
+        Type[] types = getGenericInterfaces(mapperClass);
         for (Type t : types) {
             if (t instanceof ParameterizedType) {
                 ParameterizedType pt = (ParameterizedType)t;
                 Type[] args = pt.getActualTypeArguments();
                 for (int i = 0; i < args.length; i++) {
-                    if (((Class<?>)args[i]).isAssignableFrom(expectedType)) {
+                    Class<?> actualClass = InjectionUtils.getRawType(args[i]);
+                    if (actualClass == null) {
+                        continue;
+                    }
+                    if (actualClass.isAssignableFrom(expectedType)) {
                         if (m != null) {
                             InjectionUtils.injectContextFields(em.getProvider(), em, m);
                             InjectionUtils.injectContextMethods(em.getProvider(), em, m);
@@ -294,35 +300,37 @@
             if (o == null) {
                 continue;
             }
-            if (MessageBodyReader.class.isAssignableFrom(o.getClass())) {
+            Class<?> oClass = ClassHelper.getRealClass(o);
+            
+            if (MessageBodyReader.class.isAssignableFrom(oClass)) {
                 messageReaders.add(new ProviderInfo<MessageBodyReader>((MessageBodyReader)o));

             }
             
-            if (MessageBodyWriter.class.isAssignableFrom(o.getClass())) {
+            if (MessageBodyWriter.class.isAssignableFrom(oClass)) {
                 messageWriters.add(new ProviderInfo<MessageBodyWriter>((MessageBodyWriter)o));

             }
             
-            if (ContextResolver.class.isAssignableFrom(o.getClass())) {
+            if (ContextResolver.class.isAssignableFrom(oClass)) {
                 contextResolvers.add(new ProviderInfo<ContextResolver>((ContextResolver)o));

             }
             
-            if (RequestHandler.class.isAssignableFrom(o.getClass())) {
+            if (RequestHandler.class.isAssignableFrom(oClass)) {
                 requestHandlers.add(new ProviderInfo<RequestHandler>((RequestHandler)o));

             }
             
-            if (ResponseHandler.class.isAssignableFrom(o.getClass())) {
+            if (ResponseHandler.class.isAssignableFrom(oClass)) {
                 responseHandlers.add(new ProviderInfo<ResponseHandler>((ResponseHandler)o));

             }
             
-            if (ExceptionMapper.class.isAssignableFrom(o.getClass())) {
+            if (ExceptionMapper.class.isAssignableFrom(oClass)) {
                 exceptionMappers.add(new ProviderInfo<ExceptionMapper>((ExceptionMapper)o));

             }
             
-            if (ResponseExceptionMapper.class.isAssignableFrom(o.getClass())) {
+            if (ResponseExceptionMapper.class.isAssignableFrom(oClass)) {
                 responseExceptionMappers.add(new ProviderInfo<ResponseExceptionMapper>((ResponseExceptionMapper)o));

             }
             
-            if (ParameterHandler.class.isAssignableFrom(o.getClass())) {
+            if (ParameterHandler.class.isAssignableFrom(oClass)) {
                 paramHandlers.add(new ProviderInfo<ParameterHandler>((ParameterHandler)o));

             }
         }
@@ -377,16 +385,23 @@
                                                          Annotation[] annotations,
                                                          MediaType mediaType,
                                                          Message m) {
+        List<MessageBodyReader<T>> candidates = new LinkedList<MessageBodyReader<T>>();
         for (ProviderInfo<MessageBodyReader> ep : messageReaders) {
-            
             if (matchesReaderCriterias(ep.getProvider(), type, genericType, annotations,
mediaType)) {
-                InjectionUtils.injectContextFields(ep.getProvider(), ep, m);
-                InjectionUtils.injectContextMethods(ep.getProvider(), ep, m);
-                return ep.getProvider();
+                if (this == SHARED_FACTORY) {
+                    InjectionUtils.injectContextFields(ep.getProvider(), ep, m);
+                    InjectionUtils.injectContextMethods(ep.getProvider(), ep, m);
+                    return ep.getProvider();
+                }
+                handleMapper((List)candidates, ep, type, m);
             }
         }     
         
-        return null;
+        if (candidates.size() == 0) {
+            return null;
+        }
+        Collections.sort(candidates, new ClassComparator());
+        return candidates.get(0);
         
     }
     
@@ -424,16 +439,22 @@
                                                          Annotation[] annotations,
                                                          MediaType mediaType,
                                                          Message m) {
+        List<MessageBodyWriter<T>> candidates = new LinkedList<MessageBodyWriter<T>>();
         for (ProviderInfo<MessageBodyWriter> ep : messageWriters) {
             if (matchesWriterCriterias(ep.getProvider(), type, genericType, annotations,
mediaType)) {
-                InjectionUtils.injectContextFields(ep.getProvider(), ep, m);
-                InjectionUtils.injectContextMethods(ep.getProvider(), ep, m);
-                return ep.getProvider();
+                if (this == SHARED_FACTORY) {
+                    InjectionUtils.injectContextFields(ep.getProvider(), ep, m);
+                    InjectionUtils.injectContextMethods(ep.getProvider(), ep, m);
+                    return ep.getProvider();
+                }
+                handleMapper((List)candidates, ep, type, m);
             }
         }     
-        
-        return null;
-        
+        if (candidates.size() == 0) {
+            return null;
+        }
+        Collections.sort(candidates, new ClassComparator());
+        return candidates.get(0);
     }
     
     private <T> boolean matchesWriterCriterias(MessageBodyWriter<T> ep,
@@ -490,7 +511,6 @@
             types2 = JAXRSUtils.sortMediaTypes(types2);
     
             return JAXRSUtils.compareSortedMediaTypes(types1, types2);
-            
         }
     }
     
@@ -508,7 +528,6 @@
                 JAXRSUtils.sortMediaTypes(JAXRSUtils.getProviderProduceTypes(e2));
     
             return JAXRSUtils.compareSortedMediaTypes(types1, types2);
-            
         }
     }
     
@@ -596,34 +615,32 @@
 
         public int compare(ExceptionMapper<? extends Throwable> em1, 
                            ExceptionMapper<? extends Throwable> em2) {
-            return compareClasses(em1.getClass(), em2.getClass());
+            return compareClasses(em1, em2);
         }
         
     }
     
-    private static class ResponseExceptionMapperComparator implements 
-        Comparator<ResponseExceptionMapper<? extends Throwable>> {
+    private static class ClassComparator implements 
+        Comparator<Object> {
     
-        public int compare(ResponseExceptionMapper<? extends Throwable> em1, 
-                           ResponseExceptionMapper<? extends Throwable> em2) {
-            return compareClasses(em1.getClass(), em2.getClass());
+        public int compare(Object em1, Object em2) {
+            return compareClasses(em1, em2);
         }
         
     }
     
-    private static class ParameterHandlerComparator implements 
-        Comparator<ParameterHandler<? extends Object>> {
-
-        public int compare(ParameterHandler<? extends Object> em1, 
-                           ParameterHandler<? extends Object> em2) {
-            return compareClasses(em1.getClass(), em2.getClass());
+    private static int compareClasses(Object o1, Object o2) {
+        Class<?> cl1 = ClassHelper.getRealClass(o1); 
+        Class<?> cl2 = ClassHelper.getRealClass(o2);
+        
+        Type[] types1 = getGenericInterfaces(cl1);
+        Type[] types2 = getGenericInterfaces(cl2);
+        
+        if (types1.length == 0 && types2.length > 0) {
+            return 1;
+        } else if (types1.length > 0 && types2.length == 0) {
+            return -1;
         }
-    
-    }
-    
-    private static int compareClasses(Class<?> cl1, Class<?> cl2) {
-        Type[] types1 = cl1.getGenericInterfaces();
-        Type[] types2 = cl2.getGenericInterfaces();
         
         Class<?> realClass1 = InjectionUtils.getActualType(types1[0]);
         Class<?> realClass2 = InjectionUtils.getActualType(types2[0]);
@@ -636,4 +653,15 @@
         }
         return -1;
     }
+    
+    private static Type[] getGenericInterfaces(Class<?> cls) {
+        if (Object.class == cls) {
+            return new Type[]{};
+        }
+        Type[] types = cls.getGenericInterfaces();
+        if (types.length > 0) {
+            return types;
+        }
+        return getGenericInterfaces(cls.getSuperclass());
+    }
 }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=808540&r1=808539&r2=808540&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Thu Aug 27 17:11:40 2009
@@ -209,6 +209,22 @@
         return t instanceof Class ? (Class<?>)t : getActualType(t, pos);
     }
     
+    public static Class<?> getRawType(Type genericType) {
+        
+        if (genericType == null) {
+            return null;
+        }
+        if (!ParameterizedType.class.isAssignableFrom(genericType.getClass())) {
+            return (Class<?>)genericType;
+        }
+        ParameterizedType paramType = (ParameterizedType)genericType;
+        
+        Type t = paramType.getRawType();
+        
+        return t instanceof Class ? (Class<?>)t : null;
+    }
+    
+    
     public static Type[] getActualTypes(Type genericType) {
         if (genericType == null 
             || !ParameterizedType.class.isAssignableFrom(genericType.getClass())) {

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java?rev=808540&r1=808539&r2=808540&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
Thu Aug 27 17:11:40 2009
@@ -55,6 +55,7 @@
 import org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper;
 import org.apache.cxf.jaxrs.model.ProviderInfo;
 import org.apache.cxf.jaxrs.resources.Book;
+import org.apache.cxf.jaxrs.resources.SuperBook;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.ExchangeImpl;
@@ -164,6 +165,29 @@
     }
     
     @Test
+    public void testMessageBodyHandlerHierarchy() throws Exception {
+        ProviderFactory pf = ProviderFactory.getInstance();
+        List<Object> providers = new ArrayList<Object>();
+        BookReaderWriter bookHandler = new BookReaderWriter();
+        providers.add(bookHandler);
+        SuperBookReaderWriter superBookHandler = new SuperBookReaderWriter();
+        providers.add(superBookHandler);
+        pf.setUserProviders(providers);
+        assertSame(bookHandler, 
+                   pf.createMessageBodyReader(Book.class, Book.class, new Annotation[]{},

+                                              MediaType.APPLICATION_XML_TYPE, new MessageImpl()));
+        assertSame(superBookHandler, 
+                   pf.createMessageBodyReader(SuperBook.class, SuperBook.class, new Annotation[]{},

+                                              MediaType.APPLICATION_XML_TYPE, new MessageImpl()));
+        assertSame(bookHandler, 
+                   pf.createMessageBodyWriter(Book.class, Book.class, new Annotation[]{},

+                                              MediaType.APPLICATION_XML_TYPE, new MessageImpl()));
+        assertSame(superBookHandler, 
+                   pf.createMessageBodyWriter(SuperBook.class, SuperBook.class, new Annotation[]{},

+                                              MediaType.APPLICATION_XML_TYPE, new MessageImpl()));
+    }
+    
+    @Test
     public void testSortEntityProviders() throws Exception {
         ProviderFactory pf = ProviderFactory.getInstance();
         pf.registerUserProvider(new TestStringProvider());
@@ -179,8 +203,6 @@
         assertTrue(indexOf(writers, TestStringProvider.class) 
                    < indexOf(writers, PrimitiveTextProvider.class));
         
-        //REVISIT the compare algorithm
-        //assertTrue(indexOf(providers, JSONProvider.class) < indexOf(providers, TestStringProvider.class));
     }
     
     @Test
@@ -284,7 +306,7 @@
     public void testRegisterCustomJSONEntityProvider() throws Exception {
         ProviderFactory pf = ProviderFactory.getInstance();
         pf.registerUserProvider(new CustomJSONProvider());
-        verifyProvider(pf, org.apache.cxf.jaxrs.resources.Book.class, CustomJSONProvider.class,

+        verifyProvider(pf, Book.class, CustomJSONProvider.class, 
                        "application/json");
     }
     
@@ -375,7 +397,7 @@
     @Consumes("application/json")
     @Produces("application/json")
     private final class CustomJSONProvider 
-        implements MessageBodyReader<String>, MessageBodyWriter<String>  {
+        implements MessageBodyReader<Book>, MessageBodyWriter<Book>  {
 
         public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations,
                                   MediaType m) {
@@ -387,18 +409,18 @@
             return type.getAnnotation(XmlRootElement.class) != null;
         }
         
-        public long getSize(String s, Class<?> type, Type genericType, Annotation[]
annotations,
+        public long getSize(Book b, Class<?> type, Type genericType, Annotation[] annotations,
                             MediaType m) {
-            return s.length();
+            return -1;
         }
 
-        public String readFrom(Class<String> clazz, Type genericType, Annotation[]
annotations, 
+        public Book readFrom(Class<Book> clazz, Type genericType, Annotation[] annotations,

                                MediaType m, MultivaluedMap<String, String> headers,
InputStream is) {    
             //Dummy
             return null;
         }
 
-        public void writeTo(String obj, Class<?> clazz, Type genericType, Annotation[]
annotations,  
+        public void writeTo(Book obj, Class<?> clazz, Type genericType, Annotation[]
annotations,  
             MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) {
             //Dummy
         }
@@ -408,7 +430,7 @@
     @Consumes("application/widget")
     @Produces("application/widget")
     private final class CustomWidgetProvider
-        implements MessageBodyReader<String>, MessageBodyWriter<String>  {
+        implements MessageBodyReader<Book>, MessageBodyWriter<Book>  {
 
         public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations,
                                   MediaType m) {
@@ -420,19 +442,19 @@
             return type.getAnnotation(XmlRootElement.class) != null;
         }
         
-        public long getSize(String s, Class<?> type, Type genericType, Annotation[]
annotations,
+        public long getSize(Book s, Class<?> type, Type genericType, Annotation[] annotations,
                             MediaType m) {
-            return s.length();
+            return -1;
         }
 
 
-        public String readFrom(Class<String> clazz, Type genericType, Annotation[]
annotations, 
+        public Book readFrom(Class<Book> clazz, Type genericType, Annotation[] annotations,

                                MediaType m, MultivaluedMap<String, String> headers,
InputStream is) {    
             //Dummy
             return null;
         }
 
-        public void writeTo(String obj, Class<?> clazz, Type genericType, Annotation[]
annotations,  
+        public void writeTo(Book obj, Class<?> clazz, Type genericType, Annotation[]
annotations,  
             MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) {
             //Dummy
         }
@@ -460,5 +482,78 @@
         }
         
     }
-     
+    
+    @Produces("application/xml")
+    @Consumes("application/xml")
+    private static class BookReaderWriter 
+        implements MessageBodyReader<Book>, MessageBodyWriter<Book> {
+
+        public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations,

+                                  MediaType mediaType) {
+            return true;
+        }
+
+        public Book readFrom(Class<Book> arg0, Type arg1, Annotation[] arg2, 
+                             MediaType arg3, MultivaluedMap<String, String> arg4, InputStream
arg5) 
+            throws IOException, WebApplicationException {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public long getSize(Book t, Class<?> type, Type genericType, Annotation[] annotations,

+                            MediaType mediaType) {
+            // TODO Auto-generated method stub
+            return 0;
+        }
+
+        public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations,

+                                   MediaType mediaType) {
+            return true;
+        }
+
+        public void writeTo(Book arg0, Class<?> arg1, Type arg2, Annotation[] arg3,

+                            MediaType arg4, MultivaluedMap<String, Object> arg5, OutputStream
arg6) 
+            throws IOException, WebApplicationException {
+            // TODO Auto-generated method stub
+            
+        }
+    }
+    
+    @Produces("application/xml")
+    @Consumes("application/xml")
+    private static class SuperBookReaderWriter 
+        implements MessageBodyReader<SuperBook>, MessageBodyWriter<SuperBook>
{
+
+        public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations,

+                                  MediaType mediaType) {
+            return true;
+        }
+
+        public SuperBook readFrom(Class<SuperBook> arg0, Type arg1, Annotation[] arg2,
MediaType arg3, 
+                                  MultivaluedMap<String, String> arg4, InputStream
arg5) 
+            throws IOException, WebApplicationException {
+            // TODO Auto-generated method stub
+            return null;
+        }
+
+        public long getSize(SuperBook t, Class<?> type, Type genericType, 
+                            Annotation[] annotations, MediaType mediaType) {
+            // TODO Auto-generated method stub
+            return 0;
+        }
+
+        public boolean isWriteable(Class<?> type, Type genericType, 
+                                   Annotation[] annotations, MediaType mediaType) {
+            return true;
+        }
+
+        public void writeTo(SuperBook arg0, Class<?> arg1, Type arg2, 
+                            Annotation[] arg3, MediaType arg4, MultivaluedMap<String,
Object> arg5, 
+                            OutputStream arg6) throws IOException, WebApplicationException
{
+            // TODO Auto-generated method stub
+            
+        }
+        
+    }
+    
 }

Modified: cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java?rev=808540&r1=808539&r2=808540&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
Thu Aug 27 17:11:40 2009
@@ -20,6 +20,7 @@
 package org.apache.cxf.systest.jaxrs;
 
 import java.io.InputStream;
+import java.net.HttpURLConnection;
 import java.net.URL;
 import java.net.URLConnection;
 
@@ -38,6 +39,26 @@
     }
     
     @Test
+    public void testGetBookNotFound() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:9080/test/bookstore/books/12345"; 
+        URL url = new URL(endpointAddress);
+        HttpURLConnection connect = (HttpURLConnection)url.openConnection();
+        connect.addRequestProperty("Accept", "text/plain,application/xml");
+        assertEquals(500, connect.getResponseCode());
+        InputStream in = connect.getErrorStream();
+        assertNotNull(in);           
+
+        InputStream expected = getClass()
+            .getResourceAsStream("resources/expected_get_book_notfound_mapped.txt");
+
+        assertEquals("Exception is not mapped correctly", 
+                     getStringFromInputStream(expected).trim(),
+                     getStringFromInputStream(in).trim());
+    }
+    
+    @Test
     public void testGetThatBook123() throws Exception {
         getBook("http://localhost:9080/test/bookstorestorage/thosebooks/123");
     }

Modified: cxf/branches/2.2.x-fixes/systests/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml?rev=808540&r1=808539&r2=808540&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml (original)
+++ cxf/branches/2.2.x-fixes/systests/src/test/resources/jaxrs_proxy/WEB-INF/beans.xml Thu
Aug 27 17:11:40 2009
@@ -45,11 +45,18 @@
     <jaxrs:serviceBeans>
       <ref bean="bookstore"/>
       <ref bean="bookstoreInterface"/>
-    </jaxrs:serviceBeans>		   
+    </jaxrs:serviceBeans>
+    <jaxrs:providers>
+      <ref bean="exceptionMapper"/>
+      <ref bean="exceptionMapper2"/>
+    </jaxrs:providers>		   
   </jaxrs:server>
   <bean id="bookstore" class="org.apache.cxf.systest.jaxrs.BookStore"/>
   <bean id="bookstoreInterface" class="org.apache.cxf.systest.jaxrs.BookStoreWithInterface"/>
-  
+  <bean id="exceptionMapper" class="org.apache.cxf.systest.jaxrs.BookExceptionMapper">
+      <property name="toHandle" value="true"/>
+  </bean>   
+  <bean id="exceptionMapper2" class="org.apache.cxf.systest.jaxrs.BookExceptionMapper"/>
 
   <jaxrs:server id="bookservice2" address="/2"
     modelRef="classpath:/org/apache/cxf/systest/jaxrs/resources/resources.xml">
     <jaxrs:serviceBeans>
@@ -71,10 +78,10 @@
 		<aop:aspect id="loggingAspect" ref="simpleLogger">
 			<aop:before
 			      method="logBefore"
-			      pointcut="execution(* org.apache.cxf.systest.jaxrs.BookStore*.*(..))"/>
+			      pointcut="execution(* org.apache.cxf.systest.jaxrs.Book*.*(..))"/>
 			<aop:after-returning
 			      method="logAfter"
-			      pointcut="execution(* org.apache.cxf.systest.jaxrs.BookStore*.*(..))"/>
+			      pointcut="execution(* org.apache.cxf.systest.jaxrs.Book*.*(..))"/>
 		</aop:aspect>
 	</aop:config>
 



Mime
View raw message