cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5853] Avoding releasing the provider tls state immediately after a non-match as it may override the state set by the same thread in case of multiparts, the state is cleared up at the end of the request anyway
Date Mon, 07 Jul 2014 16:41:45 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.6.x-fixes 53c8b7152 -> c97b70d3b


[CXF-5853] Avoding releasing the provider tls state immediately after a non-match as it may
override the state set by the same thread in case of multiparts, the state is cleared up at
the end of the request anyway


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/c97b70d3
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/c97b70d3
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/c97b70d3

Branch: refs/heads/2.6.x-fixes
Commit: c97b70d3b798acafea448ba18dfad93c38d0af02
Parents: 53c8b71
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Mon Jul 7 16:31:32 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Mon Jul 7 17:41:23 2014 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/provider/ProviderFactory.java     | 16 ++-----------
 systests/jaxrs/pom.xml                          |  2 +-
 ...ServerResourceJacksonSpringProviderTest.java | 24 ++++++++++++++++++++
 .../cxf/systest/jaxrs/JAXRSMultipartTest.java   |  1 +
 .../cxf/systest/jaxrs/MultipartStore.java       | 14 ++++++++++++
 .../jaxrs_jackson_provider/WEB-INF/beans.xml    | 11 +++++++++
 6 files changed, 53 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c97b70d3/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
index 091e3be..e989a8a 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
@@ -668,16 +668,10 @@ public final class ProviderFactory {
         if (availableMimeTypes.size() == 0) {
             return false;
         }
-        boolean injected = false;
         if (this != SHARED_FACTORY || !isJaxbBasedProvider(ep)) {
             injectContextValues(pi, m);
-            injected = true;
         }
-        boolean matches = ep.isReadable(type, genericType, annotations, mediaType);
-        if (!matches && injected) {
-            pi.clearThreadLocalProxies();
-        }
-        return matches;
+        return ep.isReadable(type, genericType, annotations, mediaType);
     }
         
     /**
@@ -729,17 +723,11 @@ public final class ProviderFactory {
         if (availableMimeTypes.size() == 0) {
             return false;
         }
-        boolean injected = false;
         if ((this != SHARED_FACTORY || !isJaxbBasedProvider(ep))
             && m.get(ACTIVE_JAXRS_PROVIDER_KEY) != ep) {
             injectContextValues(pi, m);
-            injected = true;
-        }
-        boolean matches = ep.isWriteable(type, genericType, annotations, mediaType);
-        if (!matches && injected) {
-            pi.clearThreadLocalProxies();
         }
-        return matches;
+        return ep.isWriteable(type, genericType, annotations, mediaType);
     }
     
     List<ProviderInfo<MessageBodyReader<?>>> getMessageReaders() {

http://git-wip-us.apache.org/repos/asf/cxf/blob/c97b70d3/systests/jaxrs/pom.xml
----------------------------------------------------------------------
diff --git a/systests/jaxrs/pom.xml b/systests/jaxrs/pom.xml
index 1ff746f..b2dd45f 100644
--- a/systests/jaxrs/pom.xml
+++ b/systests/jaxrs/pom.xml
@@ -328,7 +328,7 @@
         <dependency>
           <groupId>com.fasterxml.jackson.jaxrs</groupId>
           <artifactId>jackson-jaxrs-json-provider</artifactId>
-          <version>2.1.5</version>
+          <version>2.4.1</version>
         </dependency>
         <dependency>
          <groupId>org.apache.httpcomponents</groupId>

http://git-wip-us.apache.org/repos/asf/cxf/blob/c97b70d3/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
index 177eff0..0b517c0 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceJacksonSpringProviderTest.java
@@ -22,9 +22,11 @@ package org.apache.cxf.systest.jaxrs;
 import java.io.InputStream;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 
 import javax.ws.rs.core.MediaType;
 
@@ -33,6 +35,7 @@ import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
 import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.ext.multipart.Attachment;
 import org.apache.cxf.jaxrs.model.AbstractResourceInfo;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 
@@ -78,6 +81,27 @@ public class JAXRSClientServerResourceJacksonSpringProviderTest extends
Abstract
     }
     
     @Test
+    public void testMultipart() throws Exception {
+        
+        String endpointAddress = "http://localhost:" + PORT + "/webapp/multipart";
+        MultipartStore proxy = JAXRSClientFactory.create(endpointAddress, MultipartStore.class,

+            Collections.singletonList(new JacksonJsonProvider()));
+        Book json = new Book("json", 1L);
+        InputStream is1 =  getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
+        
+        Map<String, Object> attachments = proxy.addBookJsonImageStream(json, is1);

+        assertEquals(2, attachments.size());
+        Book json2 = ((Attachment)attachments.get("application/json")).getObject(Book.class);
+        assertEquals("json", json2.getName());
+        assertEquals(1L, json2.getId());
+        InputStream is2 = ((Attachment)attachments.get("application/octet-stream")).getObject(InputStream.class);
+        byte[] image1 = IOUtils.readBytesFromStream(
+            getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"));
+        byte[] image2 = IOUtils.readBytesFromStream(is2);
+        assertTrue(Arrays.equals(image1, image2));
+    }
+    
+    @Test
     public void testGetSuperBookCollectionProxy() throws Exception {
         
         String endpointAddress =

http://git-wip-us.apache.org/repos/asf/cxf/blob/c97b70d3/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
index 3e89339..c54f037 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
@@ -471,6 +471,7 @@ public class JAXRSMultipartTest extends AbstractBusClientServerTestBase
{
         assertNotNull(params.get("start"));
     }
     
+   
     private Map<String, String> doTestAddBookJaxbJsonImageWebClient(String multipartType)
throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/books/jaxbjsonimage";
         WebClient client = WebClient.create(address);

http://git-wip-us.apache.org/repos/asf/cxf/blob/c97b70d3/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
index 94489f8..e3b67c9 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
@@ -206,6 +206,20 @@ public class MultipartStore {
         
     }
     
+    @POST
+    @Path("/books/jsonimagestream")
+    @Consumes("multipart/mixed")
+    @Produces("multipart/mixed")
+    public Map<String, Object> addBookJsonImageStream(
+        @Multipart(value = "thejson", type = "application/json") Book json, 
+        @Multipart("theimage") InputStream image) throws Exception {
+        Map<String, Object> objects = new LinkedHashMap<String, Object>();
+        objects.put("application/json", json);
+        objects.put("application/octet-stream", image);
+        return objects;
+        
+    }
+    
     @GET
     @Path("/books/jaxbjsonimage/read")
     @Produces("multipart/mixed")

http://git-wip-us.apache.org/repos/asf/cxf/blob/c97b70d3/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml b/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
index f00cf8a..5c9a114 100644
--- a/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
+++ b/systests/jaxrs/src/test/resources/jaxrs_jackson_provider/WEB-INF/beans.xml
@@ -67,9 +67,20 @@ http://cxf.apache.org/schemas/jaxrs.xsd">
         </jaxrs:providers>
     </jaxrs:server>
     
+    <jaxrs:server id="multipart"
+    	          address="/multipart">
+        <jaxrs:serviceBeans>
+            <ref bean="multipartStore"/>
+        </jaxrs:serviceBeans>
+        <jaxrs:providers>
+            <ref bean="jackson"/>
+        </jaxrs:providers>
+    </jaxrs:server>
+    
     <bean id="jackson" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
     <bean id="bookstore" class="org.apache.cxf.systest.jaxrs.BookStore"/>
     <bean id="bookstore2" class="org.apache.cxf.systest.jaxrs.BookStoreSpring"/>
+    <bean id="multipartStore" class="org.apache.cxf.systest.jaxrs.MultipartStore"/>
   
     <bean id="gBookStore" class="org.apache.cxf.systest.jaxrs.GenericBookStoreSpring"/>
     <bean id="gBookStore2" class="org.apache.cxf.systest.jaxrs.GenericBookStoreSpring2"/>
 </beans>


Mime
View raw message