cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1477528 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ systests/jaxrs/src/test/java/org...
Date Tue, 30 Apr 2013 10:13:44 GMT
Author: sergeyb
Date: Tue Apr 30 10:13:43 2013
New Revision: 1477528

URL: http://svn.apache.org/r1477528
Log:
[CXF-4992] Fixing subresource proxies invoking on non-HTTP endpoints

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSJmsTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JMSBookStore.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=1477528&r1=1477527&r2=1477528&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
Tue Apr 30 10:13:43 2013
@@ -123,7 +123,8 @@ public class JAXRSInInterceptor extends 
         if (JAXRSUtils.runContainerRequestFilters(providerFactory, message, true, null, false))
{
             return;
         }
-        String httpMethod = HttpUtils.getProtocolHeader(message, Message.HTTP_REQUEST_METHOD,
"POST");
+        String httpMethod = HttpUtils.getProtocolHeader(message, Message.HTTP_REQUEST_METHOD,

+                                                        HttpMethod.POST, true);
         
         String requestContentType = (String)message.get(Message.CONTENT_TYPE);
         if (requestContentType == null) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java?rev=1477528&r1=1477527&r2=1477528&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java Tue
Apr 30 10:13:43 2013
@@ -328,9 +328,16 @@ public final class HttpUtils {
     }
     
     public static String getProtocolHeader(Message m, String name, String defaultValue) {
+        return getProtocolHeader(m, name, defaultValue, false);
+    }
+    
+    public static String getProtocolHeader(Message m, String name, String defaultValue, boolean
setOnMessage) {
         String value = (String)m.get(name);
         if (value == null) {
             value = new HttpHeadersImpl(m).getRequestHeaders().getFirst(name);
+            if (value != null && setOnMessage) {
+                m.put(name, value);
+            }
         }
         return value == null ? defaultValue : value;
     }

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java?rev=1477528&r1=1477527&r2=1477528&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
(original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
Tue Apr 30 10:13:43 2013
@@ -54,6 +54,11 @@ public class LocalClientState implements
         }
     }
     
+    public LocalClientState(URI baseURI, URI currentURI) {
+        this.baseURI = baseURI;
+        this.currentBuilder = UriBuilder.fromUri(currentURI);
+    }
+    
     public LocalClientState(LocalClientState cs) {
         this.requestHeaders = new MetadataMap<String, String>(cs.requestHeaders);
         this.templates = cs.templates == null ? null : new MetadataMap<String, String>(cs.templates);
@@ -118,10 +123,15 @@ public class LocalClientState implements
         templates = null;
     }
     
-    public ClientState newState(URI newBaseURI, 
+    public ClientState newState(URI currentURI, 
                                 MultivaluedMap<String, String> headers,
                                 MultivaluedMap<String, String> templatesMap) {
-        ClientState state = new LocalClientState(newBaseURI);
+        ClientState state = null;
+        if (!StringUtils.isEmpty(currentURI.getScheme()) && currentURI.getScheme().startsWith(HTTP_SCHEME))
{
+            state = new LocalClientState(currentURI);
+        } else {
+            state = new LocalClientState(baseURI, currentURI);
+        }
         if (headers != null) {
             state.setRequestHeaders(headers);
         }

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java?rev=1477528&r1=1477527&r2=1477528&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java
(original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java
Tue Apr 30 10:13:43 2013
@@ -28,13 +28,15 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 
+import org.apache.cxf.common.util.StringUtils;
+
 /**
  * Keeps the client state such as the baseURI, currentURI, requestHeaders, current response
  * in a thread local storage
  *
  */
 public class ThreadLocalClientState implements ClientState {
-    
+    private static final String HTTP_SCHEME = "http";
     private Map<Thread, LocalClientState> state = 
         Collections.synchronizedMap(new WeakHashMap<Thread, LocalClientState>());
     
@@ -101,10 +103,15 @@ public class ThreadLocalClientState impl
         removeThreadLocalState(Thread.currentThread());
     }
     
-    public ClientState newState(URI baseURI, 
+    public ClientState newState(URI currentURI, 
                                 MultivaluedMap<String, String> headers,
                                 MultivaluedMap<String, String> templates) {
-        LocalClientState ls = new LocalClientState(baseURI);
+        LocalClientState ls = null;
+        if (!StringUtils.isEmpty(currentURI.getScheme()) && currentURI.getScheme().startsWith(HTTP_SCHEME))
{
+            ls = new LocalClientState(currentURI);
+        } else {
+            ls = new LocalClientState(initialState.getBaseURI(), currentURI);
+        }
         ls.setRequestHeaders(headers);
         ls.setTemplates(templates);
         return new ThreadLocalClientState(ls, timeToKeepState);

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSJmsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSJmsTest.java?rev=1477528&r1=1477527&r2=1477528&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSJmsTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSJmsTest.java
Tue Apr 30 10:13:43 2013
@@ -70,7 +70,7 @@ public class JAXRSJmsTest extends Abstra
         assertTrue("server did not launch correctly", 
                    launchServer(EmbeddedJMSBrokerLauncher.class, props, null));
         assertTrue("server did not launch correctly",
-                   launchServer(JMSServer.class));
+                   launchServer(JMSServer.class, true));
         serversStarted = true;
     }
     
@@ -125,6 +125,22 @@ public class JAXRSJmsTest extends Abstra
     }
     
     @Test
+    public void testGetBookFromSubresourceProxyClient() throws Exception {
+        // setup the the client
+        String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text"
+             + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory"
+             + "&replyToName=dynamicQueues/test.jmstransport.response"
+             + "&jndiURL=tcp://localhost:" + JMS_PORT
+             + "&jndiConnectionFactoryName=ConnectionFactory";
+               
+        JMSBookStore client = JAXRSClientFactory.create(endpointAddressUrlEncoded, JMSBookStore.class);
+        Book bookProxy = client.getBookSubResource("123");
+        Book book = bookProxy.retrieveState();
+        assertEquals("Get a wrong response code.", 200, WebClient.client(bookProxy).getResponse().getStatus());
+        assertEquals("Get a wrong book id.", 123, book.getId());
+    }
+    
+    @Test
     public void testGetBookFromProxyClientWithQuery() throws Exception {
         // setup the the client
         String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text"

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=1477528&r1=1477527&r2=1477528&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
Tue Apr 30 10:13:43 2013
@@ -70,6 +70,18 @@ public class JAXRSLocalTransportTest ext
     }
     
     @Test
+    public void testSubresourceProxyDirectDispatchGet() throws Exception {
+        BookStore localProxy = 
+            JAXRSClientFactory.create("local://books", BookStore.class);
+        
+        WebClient.getConfig(localProxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH,
Boolean.TRUE);
+        
+        Book bookSubProxy = localProxy.getBookSubResource("123");
+        Book book = bookSubProxy.retrieveState();
+        assertEquals(123L, book.getId());
+    }
+    
+    @Test
     public void testProxyDirectDispatchPostWithGzip() throws Exception {
         BookStore localProxy = 
             JAXRSClientFactory.create("local://books", BookStore.class);

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JMSBookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JMSBookStore.java?rev=1477528&r1=1477527&r2=1477528&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JMSBookStore.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JMSBookStore.java
Tue Apr 30 10:13:43 2013
@@ -84,6 +84,11 @@ public class JMSBookStore {
         return doGetBook(id);
     }
     
+    @Path("/booksubresource/{bookId}/")
+    public Book getBookSubResource(@PathParam("bookId") String id) throws BookNotFoundFault
{
+        return doGetBook(id);
+    }
+    
     private Book doGetBook(String id) throws BookNotFoundFault {
         Book book = books.get(Long.parseLong(id));
         if (book != null) {



Mime
View raw message