cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1352850 - in /cxf/branches/2.6.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/transports/local/src/main/java/org/apache/cxf/transport/local/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Fri, 22 Jun 2012 11:38:04 GMT
Author: sergeyb
Date: Fri Jun 22 11:38:03 2012
New Revision: 1352850

URL: http://svn.apache.org/viewvc?rev=1352850&view=rev
Log:
Merged revisions 1352214,1352623,1352848 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1352214 | sergeyb | 2012-06-20 18:19:51 +0100 (Wed, 20 Jun 2012) | 1 line
  
  [CXF-4390] Initial support for Local transport in the JAX-RS client runtime
........
  r1352623 | sergeyb | 2012-06-21 18:12:24 +0100 (Thu, 21 Jun 2012) | 1 line
  
  [CXF-4390] Few more updates for supporting piped Local transport calls
........
  r1352848 | sergeyb | 2012-06-22 12:27:36 +0100 (Fri, 22 Jun 2012) | 1 line
  
  [CXF-4390] Removing disabled GET piped test given that a pipe gets activated via a write,
making client headers case-sensitive for a GZIP test to pass
........

Added:
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
      - copied, changed from r1352214, cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
    cxf/branches/2.6.x-fixes/rt/transports/local/src/main/java/org/apache/cxf/transport/local/LocalTransportFactory.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
    svn:mergeinfo = /cxf/trunk:1352214,1352623,1352848

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

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1352850&r1=1352849&r2=1352850&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Fri Jun 22 11:38:03 2012
@@ -233,7 +233,7 @@ public abstract class AbstractClient imp
      * {@inheritDoc}
      */
     public MultivaluedMap<String, String> getHeaders() {
-        MultivaluedMap<String, String> map = new MetadataMap<String, String>();
+        MultivaluedMap<String, String> map = new MetadataMap<String, String>(false,
true);
         map.putAll(state.getRequestHeaders());
         return map;
     }
@@ -318,9 +318,7 @@ public abstract class AbstractClient imp
     }
     
     protected ResponseBuilder setResponseBuilder(Message outMessage, Exchange exchange) throws
Exception {
-        checkClientException(exchange.getOutMessage(), exchange.getOutMessage().getContent(Exception.class));
-        
-        int status = (Integer)exchange.get(Message.RESPONSE_CODE);
+        Integer status = getResponseCode(exchange);
         ResponseBuilder currentResponseBuilder = Response.status(status);
         
         Message responseMessage = exchange.getInMessage() != null 
@@ -478,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));
         
@@ -493,18 +487,42 @@ public abstract class AbstractClient imp
         return result != null ? result.toArray() : null;
     }
     
-    protected void checkClientException(Message message, Exception ex) throws Exception {
-        if (message.getExchange().get(Message.RESPONSE_CODE) == null) {
+    protected void checkClientException(Message outMessage, Exception ex) throws Exception
{
+        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());
@@ -750,7 +768,7 @@ public abstract class AbstractClient imp
         
         m.put(Message.HTTP_REQUEST_METHOD, httpMethod);
         m.put(Message.PROTOCOL_HEADERS, headers);
-        if (currentURI.isAbsolute()) {
+        if (currentURI.isAbsolute() && currentURI.getScheme().startsWith(HTTP_SCHEME))
{
             m.put(Message.ENDPOINT_ADDRESS, currentURI.toString());
         } else {
             m.put(Message.ENDPOINT_ADDRESS, state.getBaseURI().toString());

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java?rev=1352850&r1=1352849&r2=1352850&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java
Fri Jun 22 11:38:03 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/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java?rev=1352850&r1=1352849&r2=1352850&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
Fri Jun 22 11:38:03 2012
@@ -59,6 +59,9 @@ class ClientMessageObserver implements M
             if (origLoader != null) {
                 origLoader.reset();
             }
+            synchronized (message.getExchange()) {
+                message.getExchange().notifyAll();
+            }
         }
     }
     

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java?rev=1352850&r1=1352849&r2=1352850&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
Fri Jun 22 11:38:03 2012
@@ -34,7 +34,7 @@ import org.apache.cxf.jaxrs.impl.Metadat
 public class LocalClientState implements ClientState {
     private static final String HTTP_SCHEME = "http";
     
-    private MultivaluedMap<String, String> requestHeaders = new MetadataMap<String,
String>();
+    private MultivaluedMap<String, String> requestHeaders = new MetadataMap<String,
String>(false, true);
     private MultivaluedMap<String, String> templates;
     private ResponseBuilder responseBuilder;
     private URI baseURI;

Modified: cxf/branches/2.6.x-fixes/rt/transports/local/src/main/java/org/apache/cxf/transport/local/LocalTransportFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/transports/local/src/main/java/org/apache/cxf/transport/local/LocalTransportFactory.java?rev=1352850&r1=1352849&r2=1352850&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/transports/local/src/main/java/org/apache/cxf/transport/local/LocalTransportFactory.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/transports/local/src/main/java/org/apache/cxf/transport/local/LocalTransportFactory.java
Fri Jun 22 11:38:03 2012
@@ -94,6 +94,8 @@ public class LocalTransportFactory exten
         messageIncludeProperties.add(Message.CONTENT_TYPE);
         messageIncludeProperties.add(Message.ACCEPT_CONTENT_TYPE);
         messageIncludeProperties.add(Message.RESPONSE_CODE);
+        messageIncludeProperties.add(Message.REQUEST_URI);
+        messageIncludeProperties.add(Message.HTTP_REQUEST_METHOD);
         
         bus = b;
         register();

Copied: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
(from r1352214, cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java)
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java?p2=cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java&p1=cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java&r1=1352214&r2=1352850&rev=1352850&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
(original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
Fri Jun 22 11:38:03 2012
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import javax.ws.rs.core.Response;
+
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
@@ -39,9 +41,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 +59,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 +68,64 @@ public class JAXRSLocalTransportTest ext
         Book book = localProxy.getBook("123");
         assertEquals(123L, book.getId());
     }
+    
+    @Test
+    public void testProxyDirectDispatchPostWithGzip() throws Exception {
+        BookStore localProxy = 
+            JAXRSClientFactory.create("local://books", BookStore.class);
+        
+        WebClient.getConfig(localProxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH,
Boolean.TRUE);
+        
+        Response response = localProxy.addBook(new Book("New", 124L));
+        assertEquals(200, response.getStatus());
+    }
+    
+    @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
+    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 testWebClientDirectDispatch() 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 testWebClientPipedDispatch() throws Exception {
+        WebClient localClient = WebClient.create("local://books");
+        localClient.path("bookstore/books");
+        Book book = localClient.post(new Book("New", 124L), Book.class);
+        assertEquals(124L, 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