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 15:31:50 GMT
Repository: cxf
Updated Branches:
  refs/heads/master c39c04b24 -> fcb2f15aa


[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/fcb2f15a
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/fcb2f15a
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/fcb2f15a

Branch: refs/heads/master
Commit: fcb2f15aa194a7b2142a88528a4005bca74858fe
Parents: c39c04b
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 16:31:32 2014 +0100

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


http://git-wip-us.apache.org/repos/asf/cxf/blob/fcb2f15a/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 641f4db..2a0fed8 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
@@ -667,16 +667,10 @@ public abstract class ProviderFactory {
         if (availableMimeTypes.size() == 0) {
             return false;
         }
-        boolean injected = false;
         if (m.get(ACTIVE_JAXRS_PROVIDER_KEY) != 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);
     }
         
     /**
@@ -730,16 +724,10 @@ public abstract class ProviderFactory {
         if (availableMimeTypes.size() == 0) {
             return false;
         }
-        boolean injected = false;
         if (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/fcb2f15a/systests/jaxrs/pom.xml
----------------------------------------------------------------------
diff --git a/systests/jaxrs/pom.xml b/systests/jaxrs/pom.xml
index b9fe39c..4e1aa5f 100644
--- a/systests/jaxrs/pom.xml
+++ b/systests/jaxrs/pom.xml
@@ -398,7 +398,7 @@
         <dependency>
             <groupId>com.fasterxml.jackson.jaxrs</groupId>
             <artifactId>jackson-jaxrs-json-provider</artifactId>
-            <version>2.2.1</version>
+            <version>2.4.1</version>
         </dependency>
         <dependency>
             <groupId>org.apache.httpcomponents</groupId>

http://git-wip-us.apache.org/repos/asf/cxf/blob/fcb2f15a/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 2c24733..8dac5bf 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.GenericType;
 import javax.ws.rs.core.MediaType;
@@ -34,6 +36,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.jaxrs.provider.JAXBElementProvider;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
@@ -80,6 +83,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/fcb2f15a/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 2662507..9832202 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
@@ -554,6 +554,49 @@ public class JAXRSMultipartTest extends AbstractBusClientServerTestBase
{
         assertTrue(Arrays.equals(image1, image2));
     }
     
+    @Test
+    public void testAddBookJsonImageStream() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/books/jsonimagestream";
+        WebClient client = WebClient.create(address);
+        WebClient.getConfig(client).getOutInterceptors().add(new LoggingOutInterceptor());
+        WebClient.getConfig(client).getInInterceptors().add(new LoggingInInterceptor());
+        client.type("multipart/mixed").accept("multipart/mixed");
+       
+        Book json = new Book("json", 1L);
+        InputStream is1 = 
+            getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg");
+        Map<String, Object> objects = new LinkedHashMap<String, Object>();
+
+        MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
+        
+        headers = new MetadataMap<String, String>();
+        headers.putSingle("Content-Type", "application/json");
+        headers.putSingle("Content-ID", "thejson");
+        headers.putSingle("Content-Transfer-Encoding", "customjson");
+        Attachment attJson = new Attachment(headers, json);
+        
+        headers = new MetadataMap<String, String>();
+        headers.putSingle("Content-Type", "application/octet-stream");
+        headers.putSingle("Content-ID", "theimage");
+        headers.putSingle("Content-Transfer-Encoding", "customstream");
+        Attachment attIs = new Attachment(headers, is1);
+        
+        objects.put(MediaType.APPLICATION_JSON, attJson);
+        objects.put(MediaType.APPLICATION_OCTET_STREAM, attIs);
+        
+        Collection<? extends Attachment> coll = client.postAndGetCollection(objects,
Attachment.class);
+        List<Attachment> result = new ArrayList<Attachment>(coll);
+        assertEquals(2, result.size());
+        Book json2 = readJSONBookFromInputStream(result.get(0).getDataHandler().getInputStream());
+        assertEquals("json", json2.getName());
+        assertEquals(1L, json2.getId());
+        InputStream is2 = result.get(1).getDataHandler().getInputStream();
+        byte[] image1 = IOUtils.readBytesFromStream(
+            getClass().getResourceAsStream("/org/apache/cxf/systest/jaxrs/resources/java.jpg"));
+        byte[] image2 = IOUtils.readBytesFromStream(is2);
+        assertTrue(Arrays.equals(image1, image2));
+    }
+    
     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/fcb2f15a/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 58c1609..9924810 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
@@ -246,6 +246,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/fcb2f15a/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 d2aecd2..bafb0e6 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
@@ -84,6 +84,16 @@ 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="jackson2" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider"/>
     <bean id="jaxb" class="org.apache.cxf.jaxrs.provider.JAXBElementProvider">
@@ -93,6 +103,7 @@ http://cxf.apache.org/schemas/jaxrs.xsd">
     
     <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