cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1398881 - in /cxf/branches/2.5.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Tue, 16 Oct 2012 16:46:58 GMT
Author: sergeyb
Date: Tue Oct 16 16:46:57 2012
New Revision: 1398881

URL: http://svn.apache.org/viewvc?rev=1398881&view=rev
Log:
Merged revisions 1398878 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes

................
  r1398878 | sergeyb | 2012-10-16 17:38:02 +0100 (Tue, 16 Oct 2012) | 9 lines
  
  Merged revisions 1398302 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1398302 | sergeyb | 2012-10-15 15:27:07 +0100 (Mon, 15 Oct 2012) | 1 line
    
    [CXF-4563] Fixing the way empty responses are read on the client side
  ........
................

Modified:
    cxf/branches/2.5.x-fixes/   (props changed)
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Nullable.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
    cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Propchange: cxf/branches/2.5.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1398302
  Merged /cxf/branches/2.6.x-fixes:r1398878

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

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Nullable.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Nullable.java?rev=1398881&r1=1398880&r2=1398881&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Nullable.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/Nullable.java
Tue Oct 16 16:46:57 2012
@@ -32,7 +32,7 @@ import java.lang.annotation.Target;
  * injected instead  
  * 
  */
-@Target(ElementType.PARAMETER)
+@Target({ElementType.PARAMETER, ElementType.METHOD })
 @Retention(RetentionPolicy.RUNTIME)
 public @interface Nullable {
 }

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java?rev=1398881&r1=1398880&r2=1398881&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractConfigurableProvider.java
Tue Oct 16 16:46:57 2012
@@ -22,6 +22,7 @@ package org.apache.cxf.jaxrs.provider;
 import java.util.List;
 
 import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MultivaluedMap;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
@@ -148,16 +149,25 @@ public abstract class AbstractConfigurab
     
     protected boolean isPayloadEmpty(HttpHeaders headers) {
         if (headers != null) {
-            List<String> values = headers.getRequestHeader(HttpHeaders.CONTENT_LENGTH);
-            if (values.size() == 1) {
+            return isPayloadEmpty(headers.getRequestHeaders());
+        } else {
+            return false;
+        }
+    }
+    
+    protected boolean isPayloadEmpty(MultivaluedMap<String, String> headers) {
+        if (headers != null) {
+            String value = headers.getFirst(HttpHeaders.CONTENT_LENGTH);
+            if (value != null) {
                 try {
-                    Long len = Long.valueOf(values.get(0));
+                    Long len = Long.valueOf(value);
                     return len <= 0;
                 } catch (NumberFormatException ex) {
                     // ignore
                 }
             }
         }
+        
         return false;
     }
 }

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1398881&r1=1398880&r2=1398881&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
Tue Oct 16 16:46:57 2012
@@ -195,10 +195,6 @@ public abstract class AbstractJAXBProvid
         jaxbElementClassMap = map;
     }
     
-    protected boolean isPayloadEmpty() {
-        return mc != null ? isPayloadEmpty(mc.getHttpHeaders()) : false;     
-    }
-    
     protected void reportEmptyContentLength() {
         String message = new org.apache.cxf.common.i18n.Message("EMPTY_BODY", BUNDLE).toString();
         LOG.warning(message);

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=1398881&r1=1398880&r2=1398881&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
Tue Oct 16 16:46:57 2012
@@ -148,7 +148,7 @@ public class JAXBElementProvider extends
     public Object readFrom(Class<Object> type, Type genericType, Annotation[] anns,
MediaType mt, 
         MultivaluedMap<String, String> headers, InputStream is) 
         throws IOException {
-        if (isPayloadEmpty()) {
+        if (isPayloadEmpty(headers)) {
             if (AnnotationUtils.getAnnotation(anns, Nullable.class) != null) {
                 return null;
             } else {

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java?rev=1398881&r1=1398880&r2=1398881&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JSONProvider.java
Tue Oct 16 16:46:57 2012
@@ -201,7 +201,7 @@ public class JSONProvider extends Abstra
         MultivaluedMap<String, String> headers, InputStream is) 
         throws IOException {
         
-        if (isPayloadEmpty()) {
+        if (isPayloadEmpty(headers)) {
             if (AnnotationUtils.getAnnotation(anns, Nullable.class) != null) {
                 return null;
             } else {

Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1398881&r1=1398880&r2=1398881&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Tue Oct 16 16:46:57 2012
@@ -169,13 +169,14 @@ public final class ProviderFactory {
         Message responseMessage = isRequestor ? m.getExchange().getInMessage() 
                                               : m.getExchange().getOutMessage();
         if (responseMessage != null) {
-            if (!responseMessage.containsKey(Message.CONTENT_TYPE)) {
+            Object ctProperty = responseMessage.get(Message.CONTENT_TYPE);
+            if (ctProperty == null) {
                 List<MediaType> accepts = requestHeaders.getAcceptableMediaTypes();
                 if (accepts.size() > 0) {
                     mt = accepts.get(0);
                 }
             } else {
-                mt = MediaType.valueOf(responseMessage.get(Message.CONTENT_TYPE).toString());
+                mt = MediaType.valueOf(ctProperty.toString());
             }
         } else {
             mt = requestHeaders.getMediaType();

Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1398881&r1=1398880&r2=1398881&view=diff
==============================================================================
--- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Tue Oct 16 16:46:57 2012
@@ -1028,6 +1028,37 @@ public class JAXRSClientServerBookTest e
         assertEquals(444L, book.getId());
     }
     
+    @Test(expected = ClientException.class)
+    public void testEmptyJSON() {
+        doTestEmptyResponse("application/json");
+    }
+    
+    @Test(expected = ClientException.class)
+    public void testEmptyJAXB() {
+        doTestEmptyResponse("application/xml");
+    }
+    
+    private void doTestEmptyResponse(String mt) {
+        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/emptybook");
+        WebClient.getConfig(wc).getInInterceptors().add(new ReplaceStatusInterceptor());
+        wc.accept(mt);
+        wc.get(Book.class);
+    }
+    
+    @Test(expected = ClientException.class)
+    public void testEmptyResponseProxy() {
+        BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
+        WebClient.getConfig(store).getInInterceptors().add(new ReplaceStatusInterceptor());
+        store.getEmptyBook();
+    }
+    
+    @Test
+    public void testEmptyResponseProxyNullable() {
+        BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
+        WebClient.getConfig(store).getInInterceptors().add(new ReplaceStatusInterceptor());
+        assertNull(store.getEmptyBookNullable());
+    }
+    
     @Test
     public void testFormattedJSON() {
         WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/books/123");
@@ -1854,4 +1885,14 @@ public class JAXRSClientServerBookTest e
         }
     }
 
+    public static class ReplaceStatusInterceptor extends AbstractPhaseInterceptor<Message>
{
+        public ReplaceStatusInterceptor() {
+            super(Phase.READ);
+        }
+
+        public void handleMessage(Message message) throws Fault {
+            message.getExchange().put(Message.RESPONSE_CODE, 200);
+        }
+    }
+    
 }



Mime
View raw message