cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1503291 - in /cxf/trunk: rt/rs/client/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:20:15 GMT
Author: sergeyb
Date: Mon Jul 15 15:20:15 2013
New Revision: 1503291

URL: http://svn.apache.org/r1503291
Log:
[CXF-5130] Adding simple WebClient SyncInvoker link

Modified:
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1503291&r1=1503290&r2=1503291&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Mon Jul
15 15:20:15 2013
@@ -37,6 +37,7 @@ import javax.ws.rs.WebApplicationExcepti
 import javax.ws.rs.client.AsyncInvoker;
 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.Form;
@@ -1210,11 +1211,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 +1244,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 {
 
         @Override
@@ -1398,33 +1414,155 @@ 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/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java?rev=1503291&r1=1503290&r2=1503291&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
Mon Jul 15 15:20:15 2013
@@ -94,6 +94,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