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:24:15 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes 95fc31adf -> f27ee049a


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

Branch: refs/heads/2.7.x-fixes
Commit: f27ee049a8ec6941650955ab4ebe3525ea59522a
Parents: 95fc31a
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:24:02 2014 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/provider/ProviderFactory.java     | 16 +-------
 systests/jaxrs/pom.xml                          |  6 +--
 ...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, 97 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/f27ee049/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 090bec6..7ddad14 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
@@ -985,16 +985,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);
     }
         
     /**
@@ -1046,17 +1040,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/f27ee049/systests/jaxrs/pom.xml
----------------------------------------------------------------------
diff --git a/systests/jaxrs/pom.xml b/systests/jaxrs/pom.xml
index eddd5c9..79799da 100644
--- a/systests/jaxrs/pom.xml
+++ b/systests/jaxrs/pom.xml
@@ -342,9 +342,9 @@
             <scope>test</scope>
         </dependency>
         <dependency>
-          <groupId>com.fasterxml.jackson.jaxrs</groupId>
-          <artifactId>jackson-jaxrs-json-provider</artifactId>
-          <version>2.2.1</version>
+            <groupId>com.fasterxml.jackson.jaxrs</groupId>
+            <artifactId>jackson-jaxrs-json-provider</artifactId>
+            <version>2.4.1</version>
         </dependency>
         <dependency>
          <groupId>org.apache.httpcomponents</groupId>

http://git-wip-us.apache.org/repos/asf/cxf/blob/f27ee049/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 248da7a..b19d968 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.testutil.common.AbstractBusClientServerTestBase;
 
@@ -79,6 +82,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/f27ee049/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 473ae5c..fd7e2ef 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
@@ -552,6 +552,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/f27ee049/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 39e580f..51a6d0d 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
@@ -244,6 +244,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/f27ee049/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 365b7c1..c78e342 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
@@ -73,10 +73,21 @@ 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="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