cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1503302 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
Date Mon, 15 Jul 2013 15:34:47 GMT
Author: sergeyb
Date: Mon Jul 15 15:34:47 2013
New Revision: 1503302

URL: http://svn.apache.org/r1503302
Log:
Merged revisions 1503291 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1503291 | sergeyb | 2013-07-15 16:20:15 +0100 (Mon, 15 Jul 2013) | 1 line
  
  [CXF-5130] Adding simple WebClient SyncInvoker link
........

Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1503291

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

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1503302&r1=1503301&r2=1503302&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
Mon Jul 15 15:34:47 2013
@@ -31,11 +31,13 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.Future;
 
+import javax.ws.rs.HttpMethod;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.client.AsyncInvoker;
 import javax.ws.rs.client.ClientException;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.client.InvocationCallback;
+import javax.ws.rs.client.SyncInvoker;
 import javax.ws.rs.core.Cookie;
 import javax.ws.rs.core.EntityTag;
 import javax.ws.rs.core.GenericEntity;
@@ -1211,11 +1213,16 @@ public class WebClient extends AbstractC
         }
     }
 
-    // Async related code, consider pushing most of it to AbstractClient
+    // Link to JAX-RS 2.0 AsyncInvoker
     public AsyncInvoker async() {
         return new AsyncInvokerImpl();
     }
     
+    // Link to JAX-RS 2.0 SyncInvoker
+    public SyncInvoker sync() {
+        return new SyncInvokerImpl();
+    }
+
     class ClientAsyncResponseInterceptor extends AbstractPhaseInterceptor<Message>
{
         public ClientAsyncResponseInterceptor() {
             super(Phase.UNMARSHAL);
@@ -1238,6 +1245,16 @@ public class WebClient extends AbstractC
         }
 
     }
+
+    private void setEntityHeaders(Entity<?> entity) {
+        type(entity.getMediaType());
+        if (entity.getLanguage() != null) {
+            language(entity.getLanguage().toString());
+        }
+        if (entity.getEncoding() != null) {
+            encoding(entity.getEncoding());
+        }
+    }
     
     class AsyncInvokerImpl implements AsyncInvoker {
 
@@ -1399,34 +1416,154 @@ public class WebClient extends AbstractC
 
         @Override
         public <T> Future<T> method(String name, Entity<?> entity, Class<T>
responseType) {
-            setEntityHeaders(entity);
+            WebClient.this.setEntityHeaders(entity);
             return doInvokeAsync(name, entity.getEntity(), entity.getEntity().getClass(),
null, 
                                  responseType, responseType, null);
         }
 
         @Override
         public <T> Future<T> method(String name, Entity<?> entity, GenericType<T>
responseType) {
-            setEntityHeaders(entity);
+            WebClient.this.setEntityHeaders(entity);
             return doInvokeAsync(name, entity.getEntity(), entity.getEntity().getClass(),
null, 
                                  responseType.getRawType(), responseType.getType(), null);
         }
 
         @Override
         public <T> Future<T> method(String name, Entity<?> entity, InvocationCallback<T>
callback) {
-            setEntityHeaders(entity);
+            WebClient.this.setEntityHeaders(entity);
             return doInvokeAsyncCallback(name, entity.getEntity(), entity.getEntity().getClass(),
null, 
                 callback);
         }
-
-        private void setEntityHeaders(Entity<?> entity) {
-            WebClient.this.type(entity.getMediaType());
-            if (entity.getLanguage() != null) {
-                WebClient.this.language(entity.getLanguage().toString());
-            }
-            if (entity.getEncoding() != null) {
-                WebClient.this.encoding(entity.getEncoding());
-            }
-        }       
     }
+
+    class SyncInvokerImpl implements SyncInvoker {
+
+        @Override
+        public Response delete() {
+            return method(HttpMethod.DELETE);
+        }
+
+        @Override
+        public <T> T delete(Class<T> cls) {
+            return method(HttpMethod.DELETE, cls);
+        }
+
+        @Override
+        public <T> T delete(GenericType<T> genericType) {
+            return method(HttpMethod.DELETE, genericType);
+        }
+
+        @Override
+        public Response get() {
+            return method(HttpMethod.GET);
+        }
+
+        @Override
+        public <T> T get(Class<T> cls) {
+            return method(HttpMethod.GET, cls);
+        }
+
+        @Override
+        public <T> T get(GenericType<T> genericType) {
+            return method(HttpMethod.GET, genericType);
+        }
+
+        @Override
+        public Response head() {
+            return method(HttpMethod.HEAD);
+        }
+
+        @Override
+        public Response options() {
+            return method(HttpMethod.OPTIONS);
+        }
+
+        @Override
+        public <T> T options(Class<T> cls) {
+            return method(HttpMethod.OPTIONS, cls);
+        }
+
+        @Override
+        public <T> T options(GenericType<T> genericType) {
+            return method(HttpMethod.OPTIONS, genericType);
+        }
+
+        @Override
+        public Response post(Entity<?> entity) {
+            return method(HttpMethod.POST, entity);
+        }
+
+        @Override
+        public <T> T post(Entity<?> entity, Class<T> cls) {
+            return method(HttpMethod.POST, entity, cls);
+        }
+
+        @Override
+        public <T> T post(Entity<?> entity, GenericType<T> genericType)
{
+            return method(HttpMethod.POST, genericType);
+        }
+
+        @Override
+        public Response put(Entity<?> entity) {
+            return method(HttpMethod.PUT, entity);
+        }
+
+        @Override
+        public <T> T put(Entity<?> entity, Class<T> cls) {
+            return method(HttpMethod.PUT, entity, cls);
+        }
+
+        @Override
+        public <T> T put(Entity<?> entity, GenericType<T> genericType)
{
+            return method(HttpMethod.PUT, entity, genericType);
+        }
+
+        @Override
+        public Response trace() {
+            return method("TRACE");
+        }
+
+        @Override
+        public <T> T trace(Class<T> cls) {
+            return method("TRACE", cls);
+        }
+
+        @Override
+        public <T> T trace(GenericType<T> genericType) {
+            return method("TRACE", genericType);
+        }
+        
+        @Override
+        public Response method(String method) {
+            return method(method, Response.class);
+        }
+
+        @Override
+        public <T> T method(String method, Class<T> cls) {
+            return invoke(method, null, cls);
+        }
+
+        @Override
+        public <T> T method(String method, GenericType<T> genericType) {
+            return invoke(method, null, genericType);
+        }
+
+        @Override
+        public Response method(String method, Entity<?> entity) {
+            return method(method, entity, Response.class);
+        }
+
+        @Override
+        public <T> T method(String method, Entity<?> entity, Class<T> cls)
{
+            WebClient.this.setEntityHeaders(entity);
+            return invoke(method, entity.getEntity(), cls);
+        }
+
+        @Override
+        public <T> T method(String method, Entity<?> entity, GenericType<T>
genericType) {
+            WebClient.this.setEntityHeaders(entity);
+            return invoke(method, entity.getEntity(), genericType);
+        }
+    } 
     
 }

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java?rev=1503302&r1=1503301&r2=1503302&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
Mon Jul 15 15:34:47 2013
@@ -95,6 +95,15 @@ public class JAXRS20ClientServerBookTest
     }
     
     @Test
+    public void testGetBookSyncLink() {
+        String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple";
+        WebClient wc = createWebClient(address);
+        Book book = wc.sync().get(Book.class);
+        assertEquals(124L, book.getId());
+        validateResponse(wc);
+    }
+    
+    @Test
     public void testGetBookSyncWithAsync() {
         String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple";
         doTestGetBook(address, true);



Mime
View raw message