cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1359300 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Mon, 09 Jul 2012 17:30:44 GMT
Author: sergeyb
Date: Mon Jul  9 17:30:44 2012
New Revision: 1359300

URL: http://svn.apache.org/viewvc?rev=1359300&view=rev
Log:
[CXF-4409] Updating ProviderFactory to avoid clearing the proxies during recursive calls

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java?rev=1359300&r1=1359299&r2=1359300&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
Mon Jul  9 17:30:44 2012
@@ -75,6 +75,7 @@ import org.apache.cxf.message.MessageUti
 public class MultipartProvider extends AbstractConfigurableProvider
     implements MessageBodyReader<Object>, MessageBodyWriter<Object> {
     
+    private static final String ACTIVE_JAXRS_PROVIDER_KEY = "active.jaxrs.provider";
     private static final Logger LOG = LogUtils.getL7dLogger(MultipartProvider.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(MultipartProvider.class);
 
@@ -366,8 +367,14 @@ public class MultipartProvider extends A
                                             Annotation[] anns,
                                             String mimeType, int id) {
         MediaType mt = MediaType.valueOf(mimeType);
-        MessageBodyWriter<T> r = 
-            mc.getProviders().getMessageBodyWriter(cls, genericType, anns, mt);
+        mc.put(ACTIVE_JAXRS_PROVIDER_KEY, this);
+        
+        MessageBodyWriter<T> r = null;
+        try {
+            r = mc.getProviders().getMessageBodyWriter(cls, genericType, anns, mt);
+        } finally {
+            mc.put("active.jaxrs.provider", null); 
+        }
         if (r == null) {
             org.apache.cxf.common.i18n.Message message = 
                 new org.apache.cxf.common.i18n.Message("NO_MSG_WRITER",
@@ -376,6 +383,7 @@ public class MultipartProvider extends A
             LOG.severe(message.toString());
             throw new WebApplicationException(500);
         }
+        
         return new MessageBodyWriterDataHandler<T>(r, obj, cls, genericType, anns,
mt);
     }
     private <T> DataHandler getHandlerForObject(T obj, 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1359300&r1=1359299&r2=1359300&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Mon Jul  9 17:30:44 2012
@@ -66,6 +66,7 @@ import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageUtils;
 
 public final class ProviderFactory {
+    private static final String ACTIVE_JAXRS_PROVIDER_KEY = "active.jaxrs.provider";
     private static final Logger LOG = LogUtils.getL7dLogger(ProviderFactory.class);
     private static final ProviderFactory SHARED_FACTORY = getInstance();
     
@@ -685,7 +686,8 @@ public final class ProviderFactory {
             return false;
         }
         boolean injected = false;
-        if (this != SHARED_FACTORY || !isJaxbBasedProvider(ep)) {
+        if ((this != SHARED_FACTORY || !isJaxbBasedProvider(ep))
+            && m.get(ACTIVE_JAXRS_PROVIDER_KEY) != ep) {
             injectContextValues(pi, m);
             injected = true;
         }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=1359300&r1=1359299&r2=1359300&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
Mon Jul  9 17:30:44 2012
@@ -240,7 +240,6 @@ public class JAXRSMultipartTest extends 
     public void testAddBookAsJAXBJSONProxy() throws Exception {
         MultipartStore store = 
             JAXRSClientFactory.create("http://localhost:" + PORT, MultipartStore.class);
-        
         Book b = store.addBookJaxbJsonWithConsumes(new Book2("CXF in Action", 1L), 
                                            new Book("CXF in Action - 2", 2L));
         assertEquals(124L, b.getId());
@@ -248,6 +247,15 @@ public class JAXRSMultipartTest extends 
     }
     
     @Test
+    public void testUseProxyToAddBookAndSimpleParts() throws Exception {
+        MultipartStore store = 
+            JAXRSClientFactory.create("http://localhost:" + PORT, MultipartStore.class);
+        Book b = store.testAddBookAndSimpleParts(new Book("CXF in Action", 124L), "1", "2");
+        assertEquals(124L, b.getId());
+        assertEquals("CXF in Action - 12", b.getName());
+    }
+    
+    @Test
     public void testAddBookAsJAXBOnlyProxy() throws Exception {
         MultipartStore store = 
             JAXRSClientFactory.create("http://localhost:" + PORT, MultipartStore.class);

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java?rev=1359300&r1=1359299&r2=1359300&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
Mon Jul  9 17:30:44 2012
@@ -374,6 +374,17 @@ public class MultipartStore {
     }
     
     @POST
+    @Path("/books/jaxbandsimpleparts")
+    @Consumes("multipart/related")
+    @Produces("text/xml")
+    public Book testAddBookAndSimpleParts(
+        @Multipart(value = "rootPart", type = "text/xml") Book b1,
+        @Multipart(value = "simplePart1") String simplePart1,
+        @Multipart(value = "simplePart2") String simplePart2) throws Exception {
+        return new Book(b1.getName() + " - " + simplePart1 + simplePart2, b1.getId());  

+    }
+    
+    @POST
     @Path("/books/jaxbonly")
     @Consumes("multipart/related")
     @Produces("text/xml")



Mime
View raw message