cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r790868 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/ systests/src/test/java/org/apache/...
Date Fri, 03 Jul 2009 11:43:38 GMT
Author: sergeyb
Date: Fri Jul  3 11:43:37 2009
New Revision: 790868

URL: http://svn.apache.org/viewvc?rev=790868&view=rev
Log:
JAX-RS : adding WebClient.path() which can deal with templates, updating AbstractClient.readBody
to return null only if Content-Length is 0 or absent, fixing HTTPHeadersImpl NPE issue

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=790868&r1=790867&r2=790868&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Fri Jul  3 11:43:37 2009
@@ -73,7 +73,7 @@
  * Common proxy and http-centric client implementation
  *
  */
-public class AbstractClient implements Client, InvocationHandlerAware {
+public class AbstractClient implements Client {
     private static final Logger LOG = LogUtils.getL7dLogger(AbstractClient.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(AbstractClient.class);
 
@@ -369,13 +369,20 @@
     }
     
     @SuppressWarnings("unchecked")
-    protected Object readBody(Response r, HttpURLConnection conn, Message inMessage, 
-                              Class<?> cls, Type type, Annotation[] anns) {
+    protected Object readBody(Response r, HttpURLConnection conn, Message inMessage, Class<?>
cls, 
+                              Type type, Annotation[] anns) {
 
+        InputStream inputStream = (InputStream)r.getEntity();
+        if (inputStream == null) {
+            return cls == Response.class ? cls : null;
+        }
         try {
             int status = conn.getResponseCode();
             if (status < 200 || status == 204 || status > 300) {
-                return null;
+                Object length = r.getMetadata().getFirst(HttpHeaders.CONTENT_LENGTH);
+                if (length == null || Integer.parseInt(length.toString()) == 0) {
+                    return cls == Response.class ? cls : null;
+                }
             }
         } catch (IOException ex) {
             // won't happen at this stage
@@ -392,8 +399,7 @@
         if (mbr != null) {
             try {
                 return mbr.readFrom(cls, type, anns, contentType, 
-                       new MetadataMap<String, Object>(r.getMetadata(), true, true),

-                       (InputStream)r.getEntity());
+                       new MetadataMap<String, Object>(r.getMetadata(), true, true),
inputStream);
             } catch (Exception ex) {
                 throw new WebApplicationException();
             }
@@ -569,9 +575,7 @@
         
     }
 
-    public Object getInvocationHandler() {
-        return this;
-    }
+    
 
 
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=790868&r1=790867&r2=790868&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Fri Jul  3 11:43:37 2009
@@ -62,7 +62,7 @@
  * Proxy-based client implementation
  *
  */
-public class ClientProxyImpl extends AbstractClient implements InvocationHandler {
+public class ClientProxyImpl extends AbstractClient implements InvocationHandlerAware, InvocationHandler
{
 
     private static final Logger LOG = LogUtils.getL7dLogger(ClientProxyImpl.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(ClientProxyImpl.class);
@@ -407,6 +407,10 @@
                         method.getGenericReturnType(), method.getDeclaredAnnotations());
     }
 
+    public Object getInvocationHandler() {
+        return this;
+    }
+    
     protected static void reportInvalidResourceMethod(Method m, String name) {
         org.apache.cxf.common.i18n.Message errorMsg = 
             new org.apache.cxf.common.i18n.Message(name, 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=790868&r1=790867&r2=790868&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Fri
Jul  3 11:43:37 2009
@@ -36,6 +36,7 @@
 import javax.ws.rs.core.PathSegment;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.UriBuilder;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.spring.SpringBusFactory;
@@ -304,6 +305,17 @@
     }
     
     /**
+     * Updates the current URI path with path segment which may contain template variables
+     * @param path new relative path segment
+     * @param values template variable values
+     * @return updated WebClient
+     */
+    public WebClient path(String path, Object... values) {
+        URI u = UriBuilder.fromUri(URI.create("http://tempuri")).path(path).buildFromEncoded(values);
+        return path(u.getRawPath());
+    }
+    
+    /**
      * Updates the current URI query parameters
      * @param name query name
      * @param values query values

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java?rev=790868&r1=790867&r2=790868&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
Fri Jul  3 11:43:37 2009
@@ -123,7 +123,7 @@
 
     private List<String> getListValues(String headerName) {
         List<String> values = headers.get(headerName);
-        if (values == null || values.isEmpty()) {
+        if (values == null || values.isEmpty() || values.get(0) == null) {
             return Collections.emptyList();
         }
         if (HttpUtils.isDateRelatedHeader(headerName)) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java?rev=790868&r1=790867&r2=790868&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
Fri Jul  3 11:43:37 2009
@@ -133,4 +133,14 @@
         assertEquals(URI.create("http://foo"), wc.getCurrentURI());
     }
     
+    @Test
+    public void testPathWithTemplates() {
+        WebClient wc = WebClient.create(URI.create("http://foo"));
+        assertEquals(URI.create("http://foo"), wc.getBaseURI());
+        assertEquals(URI.create("http://foo"), wc.getCurrentURI());
+        
+        wc.path("{bar}/{foo}", 1, 2);
+        assertEquals(URI.create("http://foo"), wc.getBaseURI());
+        assertEquals(URI.create("http://foo/1/2"), wc.getCurrentURI());
+    }
 }

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=790868&r1=790867&r2=790868&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java Fri
Jul  3 11:43:37 2009
@@ -476,7 +476,7 @@
     }
     
     @Ignore
-    private class TestFeature extends AbstractFeature {
+    public class TestFeature extends AbstractFeature {
         private TestInterceptor testInterceptor;
 
         @Override
@@ -491,7 +491,7 @@
     }
  
     @Ignore
-    private class TestInterceptor extends AbstractPhaseInterceptor<Message> {
+    public class TestInterceptor extends AbstractPhaseInterceptor<Message> {
         private boolean handleMessageCalled;
         public TestInterceptor() {
             this(Phase.PRE_STREAM);



Mime
View raw message