cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1352623 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Thu, 21 Jun 2012 17:12:26 GMT
Author: sergeyb
Date: Thu Jun 21 17:12:24 2012
New Revision: 1352623

URL: http://svn.apache.org/viewvc?rev=1352623&view=rev
Log:
[CXF-4390] Few more updates for supporting piped Local transport calls

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/ClientConfiguration.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.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=1352623&r1=1352622&r2=1352623&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
Thu Jun 21 17:12:24 2012
@@ -318,12 +318,7 @@ public abstract class AbstractClient imp
     }
     
     protected ResponseBuilder setResponseBuilder(Message outMessage, Exchange exchange) throws
Exception {
-        checkClientException(exchange.getOutMessage(), exchange.getOutMessage().getContent(Exception.class));
-        
-        Integer status = (Integer)exchange.get(Message.RESPONSE_CODE);
-        if (status == null) {
-            status = (Integer)exchange.getInMessage().get(Message.RESPONSE_CODE);
-        }
+        Integer status = getResponseCode(exchange);
         ResponseBuilder currentResponseBuilder = Response.status(status);
         
         Message responseMessage = exchange.getInMessage() != null 
@@ -481,14 +476,10 @@ public abstract class AbstractClient imp
         
         Exchange exchange = message.getExchange(); 
       
-        Exception ex = null;
-        // Check to see if there is a Fault from the outgoing chain if it's an out Message
-        if (!message.get(Message.INBOUND_MESSAGE).equals(Boolean.TRUE)) {
-            ex = message.getContent(Exception.class);
-        }
+        Exception ex = message.getContent(Exception.class);
         if (ex != null) {
             getConfiguration().getConduitSelector().complete(exchange);
-            checkClientException(message, message.getContent(Exception.class));
+            checkClientException(message, ex);
         }
         checkClientException(message, message.getExchange().get(Exception.class));
         
@@ -497,21 +488,41 @@ public abstract class AbstractClient imp
     }
     
     protected void checkClientException(Message outMessage, Exception ex) throws Exception
{
-        if (outMessage.getExchange().get(Message.RESPONSE_CODE) == null) {
-            Message inMessage = outMessage.getExchange().getInMessage();
-            if (inMessage != null && inMessage.get(Message.RESPONSE_CODE) != null)
{
-                return;
-            }
+        Integer responseCode = getResponseCode(outMessage.getExchange());
+        if (responseCode == null) {
             if (ex instanceof ClientWebApplicationException) {
                 throw ex;
             } else if (ex != null) {
                 throw new ClientWebApplicationException(ex);
-            } else {
-                throw new ClientWebApplicationException();
+            } else if (!outMessage.getExchange().isOneWay() || cfg.isResponseExpectedForOneway())
{
+                waitForResponseCode(outMessage.getExchange());
+            }
+        }
+    }
+    
+    protected void waitForResponseCode(Exchange exchange) {
+        synchronized (exchange) {
+            try {
+                exchange.wait(cfg.getSynchronousTimeout());
+            } catch (InterruptedException ex) {
+                // ignore
             }
         }
+        
+        if (getResponseCode(exchange) == null) {
+            throw new ClientWebApplicationException("Response timeout");
+        }
     }
     
+    private static Integer getResponseCode(Exchange exchange) {
+        Integer responseCode = (Integer)exchange.get(Message.RESPONSE_CODE);
+        if (responseCode == null && exchange.getInMessage() != null) {
+            responseCode = (Integer)exchange.getInMessage().get(Message.RESPONSE_CODE);
+        }
+        return responseCode;
+    }
+    
+    
     protected URI calculateNewRequestURI(Map<String, Object> reqContext) {
         URI newBaseURI = URI.create(reqContext.get(Message.ENDPOINT_ADDRESS).toString());
         URI requestURI = URI.create(reqContext.get(Message.REQUEST_URI).toString());

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java?rev=1352623&r1=1352622&r2=1352623&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java
Thu Jun 21 17:12:24 2012
@@ -59,7 +59,33 @@ public class ClientConfiguration impleme
     private Bus bus;
     private Map<String, Object> requestContext = new HashMap<String, Object>();
     private Map<String, Object> responseContext = new HashMap<String, Object>();
+    private long synchronousTimeout = 60000;
     
+    public long getSynchronousTimeout() {
+        Conduit conduit = getConduit();
+        if (conduit instanceof HTTPConduit) {
+            return ((HTTPConduit)conduit).getClient().getReceiveTimeout();
+        } else {
+            return synchronousTimeout;
+        }
+    }
+
+    /**
+     * Sets the synchronous timeout
+     * @param synchronousTimeout
+     */
+    public void setSynchronousTimeout(long synchronousTimeout) {
+        this.synchronousTimeout = synchronousTimeout;
+    }
+    
+    /**
+     * Indicates if Response may still be expected for oneway requests.
+     * For example, 202 in case of HTTP
+     * @return true if the response can be expected
+     */
+    public boolean isResponseExpectedForOneway() {
+        return getConduit() instanceof HTTPConduit ? true : false;
+    }
     
     /**
      * Sets the conduit selector 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java?rev=1352623&r1=1352622&r2=1352623&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
Thu Jun 21 17:12:24 2012
@@ -59,6 +59,9 @@ class ClientMessageObserver implements M
             if (origLoader != null) {
                 origLoader.reset();
             }
+            synchronized (message.getExchange()) {
+                message.getExchange().notifyAll();
+            }
         }
     }
     

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java?rev=1352623&r1=1352622&r2=1352623&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
Thu Jun 21 17:12:24 2012
@@ -30,6 +30,7 @@ import org.apache.cxf.transport.local.Lo
 
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class JAXRSLocalTransportTest extends AbstractBusClientServerTestBase {
@@ -39,9 +40,11 @@ public class JAXRSLocalTransportTest ext
     @Before
     public void setUp() {
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
-        sf.setResourceClasses(BookStore.class);
+        sf.setResourceClasses(BookStore.class, BookStoreSpring.class);
         sf.setResourceProvider(BookStore.class,
                                new SingletonResourceProvider(new BookStore(), true));
+        sf.setResourceProvider(BookStoreSpring.class,
+                               new SingletonResourceProvider(new BookStoreSpring(), true));
         sf.setTransportId(LocalTransportFactory.TRANSPORT_ID);
         sf.setAddress("local://books");
         localServer = sf.create();
@@ -55,7 +58,7 @@ public class JAXRSLocalTransportTest ext
     }
     
     @Test
-    public void testProxy() throws Exception {
+    public void testProxyDirectDispatchGet() throws Exception {
         BookStore localProxy = 
             JAXRSClientFactory.create("local://books", BookStore.class);
         
@@ -64,4 +67,55 @@ public class JAXRSLocalTransportTest ext
         Book book = localProxy.getBook("123");
         assertEquals(123L, book.getId());
     }
+    
+    @Test
+    public void testProxyDirectDispatchPost() throws Exception {
+        BookStoreSpring localProxy = 
+            JAXRSClientFactory.create("local://books", BookStoreSpring.class);
+        
+        WebClient.getConfig(localProxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH,
Boolean.TRUE);
+        
+        Book response = localProxy.convertBook(new Book2("New", 124L));
+        assertEquals(124L, response.getId());
+    }
+    
+    @Test
+    @Ignore
+    public void testProxyPipedDispatchGet() throws Exception {
+        BookStore localProxy = 
+            JAXRSClientFactory.create("local://books", BookStore.class);
+        
+        Book response = localProxy.getBook("123");
+        assertEquals(123L, response.getId());
+    }
+    
+    @Test
+    public void testProxyPipedDispatchPost() throws Exception {
+        BookStoreSpring localProxy = 
+            JAXRSClientFactory.create("local://books", BookStoreSpring.class);
+        
+        Book response = localProxy.convertBook(new Book2("New", 124L));
+        assertEquals(124L, response.getId());
+    }
+    
+    @Test
+    public void testWebClient() throws Exception {
+        WebClient localClient = WebClient.create("local://books");
+        
+        WebClient.getConfig(localClient).getRequestContext().put(LocalConduit.DIRECT_DISPATCH,
Boolean.TRUE);
+        localClient.path("bookstore/books/123");
+        Book book = localClient.get(Book.class);
+        assertEquals(123L, book.getId());
+    }
+    
+    @Test
+    public void testProxyWithQuery() throws Exception {
+        BookStore localProxy = 
+            JAXRSClientFactory.create("local://books", BookStore.class);
+        
+        WebClient.getConfig(localProxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH,
Boolean.TRUE);
+        
+        Book book = localProxy.getBookByURLQuery(new String[] {"1", "2", "3"});
+        assertEquals(123L, book.getId());
+    }
 }



Mime
View raw message