cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1172707 - in /cxf/branches/2.4.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/
Date Mon, 19 Sep 2011 17:04:19 GMT
Author: sergeyb
Date: Mon Sep 19 17:04:19 2011
New Revision: 1172707

URL: http://svn.apache.org/viewvc?rev=1172707&view=rev
Log:
Merged revisions 1172700 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1172700 | sergeyb | 2011-09-19 17:52:35 +0100 (Mon, 19 Sep 2011) | 1 line
  
  [CXF-3808] Fixing the issue with the same proxy instance miscalculating the request URI
in combination with the failover feature
........

Modified:
    cxf/branches/2.4.x-fixes/   (props changed)
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java

Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Sep 19 17:04:19 2011
@@ -1 +1 @@
-/cxf/trunk:1172522
+/cxf/trunk:1172522,1172700

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

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1172707&r1=1172706&r2=1172707&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Mon Sep 19 17:04:19 2011
@@ -67,6 +67,7 @@ import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageContentsList;
+import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.phase.PhaseChainCache;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 import org.apache.cxf.phase.PhaseManager;
@@ -84,6 +85,7 @@ public abstract class AbstractClient imp
     protected static final String RESPONSE_CONTEXT = "ResponseContext";
     protected static final String KEEP_CONDUIT_ALIVE = "KeepConduitAlive";
     
+    private static final String PROXY_PROPERTY = "jaxrs.proxy";
     private static final Logger LOG = LogUtils.getL7dLogger(AbstractClient.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(AbstractClient.class);
     
@@ -488,10 +490,11 @@ public abstract class AbstractClient imp
     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());
-        return calculateNewRequestURI(newBaseURI, requestURI);
+        return calculateNewRequestURI(newBaseURI, requestURI,
+                MessageUtils.isTrue(reqContext.get(PROXY_PROPERTY)));
     }
     
-    private URI calculateNewRequestURI(URI newBaseURI, URI requestURI) {
+    private URI calculateNewRequestURI(URI newBaseURI, URI requestURI, boolean proxy) {
         String baseURIPath = newBaseURI.getRawPath();
         String reqURIPath = requestURI.getRawPath();
         
@@ -501,7 +504,8 @@ public abstract class AbstractClient imp
         URI newRequestURI = builder.replaceQuery(requestURI.getRawQuery()).build();
         
         resetBaseAddress(newBaseURI);
-        resetCurrentBuilder(newRequestURI);
+        URI current = proxy ? newBaseURI : newRequestURI; 
+        resetCurrentBuilder(current);
         
         return newRequestURI;
     }
@@ -675,7 +679,7 @@ public abstract class AbstractClient imp
     // invocation thus it is also important to have baseURI and currentURI 
     // synched up with the latest endpoint address, after a successful proxy 
     // or web client invocation has returned
-    protected void prepareConduitSelector(Message message, URI currentURI) {
+    protected void prepareConduitSelector(Message message, URI currentURI, boolean proxy)
{
         try {
             cfg.prepareConduitSelector(message);
             
@@ -688,7 +692,8 @@ public abstract class AbstractClient imp
         String address = (String)message.get(Message.ENDPOINT_ADDRESS);
         // custom conduits may override the initial/current address
         if (!address.equals(currentURI.toString())) {
-            currentURI = calculateNewRequestURI(URI.create(address), currentURI);
+            URI baseAddress = URI.create(address);
+            currentURI = calculateNewRequestURI(baseAddress, currentURI, proxy);
             message.put(Message.ENDPOINT_ADDRESS, currentURI.toString());
             message.put(Message.REQUEST_URI, currentURI.toString());
         }
@@ -717,7 +722,8 @@ public abstract class AbstractClient imp
                                     MultivaluedMap<String, String> headers,
                                     URI currentURI,
                                     Exchange exchange,
-                                    Map<String, Object> invocationContext) {
+                                    Map<String, Object> invocationContext,
+                                    boolean proxy) {
         Message m = cfg.getConduitSelector().getEndpoint().getBinding().createMessage();
         m.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
         m.put(Message.INBOUND_MESSAGE, Boolean.FALSE);
@@ -744,10 +750,11 @@ public abstract class AbstractClient imp
         exchange.put(Retryable.class, this);
         
         // context
-        setContexts(m, exchange, invocationContext);
+        setContexts(m, exchange, invocationContext, proxy);
         
         //setup conduit selector
-        prepareConduitSelector(m, currentURI);
+        prepareConduitSelector(m, currentURI, proxy);
+        
         return m;
     }
     
@@ -775,7 +782,7 @@ public abstract class AbstractClient imp
     }
     
     protected void setContexts(Message message, Exchange exchange, 
-                               Map<String, Object> context) {
+                               Map<String, Object> context, boolean proxy) {
         Map<String, Object> reqContext = null;
         Map<String, Object> resContext = null;
         if (context == null) {
@@ -790,6 +797,7 @@ public abstract class AbstractClient imp
         reqContext.put(Message.PROTOCOL_HEADERS, message.get(Message.PROTOCOL_HEADERS));
         reqContext.put(Message.REQUEST_URI, message.get(Message.REQUEST_URI));
         reqContext.put(Message.ENDPOINT_ADDRESS, message.get(Message.ENDPOINT_ADDRESS));
+        reqContext.put(PROXY_PROPERTY, proxy);
         
         if (resContext == null) {
             resContext = new HashMap<String, Object>();

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=1172707&r1=1172706&r2=1172707&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Mon Sep 19 17:04:19 2011
@@ -452,7 +452,7 @@ public class ClientProxyImpl extends Abs
                                        Map<String, Object> invocationContext) throws
Throwable {
         
         Message outMessage = createMessage(body, ori.getHttpMethod(), headers, uri, 
-                                           exchange, invocationContext);
+                                           exchange, invocationContext, true);
         
         outMessage.getExchange().setOneWay(ori.isOneway());
         outMessage.setContent(OperationResourceInfo.class, ori);

Modified: cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1172707&r1=1172706&r2=1172707&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
(original)
+++ cxf/branches/2.4.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
Mon Sep 19 17:04:19 2011
@@ -708,7 +708,8 @@ public class WebClient extends AbstractC
                                            Map<String, Object> invContext) {
     //CHECKSTYLE:ON    
         URI uri = getCurrentURI();
-        Message m = createMessage(body, httpMethod, headers, uri, exchange, invContext);
+        Message m = createMessage(body, httpMethod, headers, uri, exchange, 
+                invContext, false);
         
         Map<String, Object> reqContext = getRequestContext(m);
         reqContext.put(Message.HTTP_REQUEST_METHOD, httpMethod);

Modified: cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java?rev=1172707&r1=1172706&r2=1172707&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java
(original)
+++ cxf/branches/2.4.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java
Mon Sep 19 17:04:19 2011
@@ -82,14 +82,21 @@ public class FailoverTest extends Abstra
     public void testSequentialStrategy() throws Exception {
         FailoverFeature feature = 
             getFeature(false, false, Server.ADDRESS2, Server.ADDRESS3); 
-        strategyTest(Server.ADDRESS1, feature, Server.ADDRESS2, null, false, false);
+        strategyTest(Server.ADDRESS1, feature, Server.ADDRESS2, null, false, false, false);
     }
     
     @Test    
     public void testSequentialStrategyWithCustomTargetSelector() throws Exception {
         FailoverFeature feature = 
             getFeature(true, false, Server.ADDRESS2, Server.ADDRESS3); 
-        strategyTest("resolver://info", feature, Server.ADDRESS3, null, false, false);
+        strategyTest("resolver://info", feature, Server.ADDRESS3, null, false, false, false);
+    }
+    
+    @Test    
+    public void testSequentialStrategyWithCustomTargetSelector2() throws Exception {
+        FailoverFeature feature = 
+            getFeature(true, false, Server.ADDRESS2, Server.ADDRESS3); 
+        strategyTest("resolver://info", feature, Server.ADDRESS3, null, false, false, true);
     }
     
     @Test
@@ -110,28 +117,41 @@ public class FailoverTest extends Abstra
     public void testRandomStrategy() throws Exception {
         FailoverFeature feature = 
             getFeature(false, true, Server.ADDRESS2, Server.ADDRESS3); 
-        strategyTest(Server.ADDRESS1, feature, Server.ADDRESS2, Server.ADDRESS3, false, true);
+        strategyTest(Server.ADDRESS1, feature, Server.ADDRESS2, Server.ADDRESS3, false, true,
true);
+    }
+    
+    @Test    
+    public void testRandomStrategy2() throws Exception {
+        FailoverFeature feature = 
+            getFeature(false, true, Server.ADDRESS2, Server.ADDRESS3); 
+        strategyTest(Server.ADDRESS1, feature, Server.ADDRESS2, Server.ADDRESS3, false, true,
false);
     }
     
     @Test    
     public void testSequentialStrategyWithDiffBaseAddresses() throws Exception {
         FailoverFeature feature = 
             getFeature(false, false, Server.ADDRESS3, null); 
-        strategyTest(Server.ADDRESS1, feature, Server.ADDRESS3, Server.ADDRESS2, false, false);
+        strategyTest(Server.ADDRESS1, feature, Server.ADDRESS3, Server.ADDRESS2, false, false,
false);
+    }
+    
+    public void testSequentialStrategyWithDiffBaseAddresses2() throws Exception {
+        FailoverFeature feature = 
+            getFeature(false, false, Server.ADDRESS3, null); 
+        strategyTest(Server.ADDRESS1, feature, Server.ADDRESS3, Server.ADDRESS2, false, false,
true);
     }
     
     @Test(expected = ServerWebApplicationException.class)
     public void testSequentialStrategyWithServerException() throws Exception {
         FailoverFeature feature = 
             getFeature(false, false, Server.ADDRESS2, Server.ADDRESS3); 
-        strategyTest(Server.ADDRESS1, feature, Server.ADDRESS2, Server.ADDRESS3, true, false);
+        strategyTest(Server.ADDRESS1, feature, Server.ADDRESS2, Server.ADDRESS3, true, false,
false);
     }
     
     @Test(expected = ClientWebApplicationException.class)    
     public void testSequentialStrategyFailure() throws Exception {
         FailoverFeature feature = 
             getFeature(false, false, "http://localhost:8080/non-existent"); 
-        strategyTest(Server.ADDRESS1, feature, null, null, false, false);
+        strategyTest(Server.ADDRESS1, feature, null, null, false, false, false);
     }
 
     private FailoverFeature getFeature(boolean custom, boolean random, String ...address)
{
@@ -187,11 +207,20 @@ public class FailoverTest extends Abstra
                                 String activeReplica1,
                                 String activeReplica2,
                                 boolean expectServerException,
-                                boolean expectRandom) throws Exception {
+                                boolean expectRandom,
+                                boolean singleProxy) throws Exception {
         boolean randomized = false;
         String prevEndpoint = null;
+        BookStore bookStore = null;
+        
+        if (singleProxy) {
+            bookStore = getBookStore(inactiveReplica, feature);
+        } 
+        
         for (int i = 0; i < 20; i++) {
-            BookStore bookStore = getBookStore(inactiveReplica, feature);
+            if (!singleProxy) {
+                bookStore = getBookStore(inactiveReplica, feature);
+            }
             verifyStrategy(bookStore, expectRandom 
                               ? RandomStrategy.class
                               : SequentialStrategy.class);
@@ -226,9 +255,11 @@ public class FailoverTest extends Abstra
             }
             prevEndpoint = currEndpoint;
         }
-        assertEquals("unexpected random/sequential distribution of failovers",
-                     expectRandom,
-                     randomized);
+        if (!singleProxy) {
+            assertEquals("unexpected random/sequential distribution of failovers",
+                         expectRandom,
+                         randomized);
+        }
     }
     
     protected void strategyTestWebClient(String inactiveReplica,



Mime
View raw message