cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1133016 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/features/clustering/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/ systests/un...
Date Tue, 07 Jun 2011 14:02:32 GMT
Author: sergeyb
Date: Tue Jun  7 14:02:31 2011
New Revision: 1133016

URL: http://svn.apache.org/viewvc?rev=1133016&view=rev
Log:
[CXF-3561] Adding a test with custom conduit selector overriding Message.ENDPOINT_ADDRESS
without failover

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/features/clustering/FailoverFeature.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java
    cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/LoadDistributorAddressOverrideTest.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=1133016&r1=1133015&r2=1133016&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
Tue Jun  7 14:02:31 2011
@@ -488,9 +488,12 @@ public abstract class AbstractClient imp
     
     protected URI calculateNewRequestURI(Map<String, Object> reqContext) {
         URI newBaseURI = URI.create(reqContext.get(Message.ENDPOINT_ADDRESS).toString());
-        String baseURIPath = newBaseURI.getRawPath();
-        
         URI requestURI = URI.create(reqContext.get(Message.REQUEST_URI).toString());
+        return calculateNewRequestURI(newBaseURI, requestURI);
+    }
+    
+    private URI calculateNewRequestURI(URI newBaseURI, URI requestURI) {
+        String baseURIPath = newBaseURI.getRawPath();
         String reqURIPath = requestURI.getRawPath();
         
         UriBuilder builder = UriBuilder.fromUri(newBaseURI);
@@ -515,7 +518,11 @@ public abstract class AbstractClient imp
                 (MultivaluedMap<String, String>)reqContext.get(Message.PROTOCOL_HEADERS);
                         
             URI newRequestURI = calculateNewRequestURI(reqContext);
-            
+            // TODO: if failover conduit selector fails to find a failover target
+            // then it will revert to the previous endpoint; that is not very likely
+            // but possible - thus ideally we need to resert base and current URI only
+            // if we get the same ConduitInitiatior endpoint instance before and after
+            // retryInvoke.
             Object response = retryInvoke(newRequestURI, headers, body, exchange, context);
             exchange.put(List.class, getContentsList(response));
             return new Object[]{response};
@@ -664,14 +671,23 @@ public abstract class AbstractClient imp
         cfg = config;
     }
     
-    protected void prepareConduitSelector(Message message) {
+    protected void prepareConduitSelector(Message message, URI currentURI) {
         try {
             cfg.prepareConduitSelector(message);
+            
         } catch (Fault ex) {
             LOG.warning("Failure to prepare a message from conduit selector");
         }
         message.getExchange().put(ConduitSelector.class, cfg.getConduitSelector());
         message.getExchange().put(Service.class, cfg.getConduitSelector().getEndpoint().getService());
+        
+        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);
+            message.put(Message.ENDPOINT_ADDRESS, currentURI.toString());
+            message.put(Message.REQUEST_URI, currentURI.toString());
+        }
     }
     
     protected static PhaseInterceptorChain setupOutInterceptorChain(ClientConfiguration cfg)
{ 
@@ -732,7 +748,7 @@ public abstract class AbstractClient imp
         setContexts(m, exchange, invocationContext);
         
         //setup conduit selector
-        prepareConduitSelector(m);
+        prepareConduitSelector(m, currentURI);
         
         return m;
     }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/features/clustering/FailoverFeature.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/features/clustering/FailoverFeature.java?rev=1133016&r1=1133015&r2=1133016&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/features/clustering/FailoverFeature.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/features/clustering/FailoverFeature.java
Tue Jun  7 14:02:31 2011
@@ -56,6 +56,10 @@ public class FailoverFeature extends org
         }
     }
     
+    public void setTargetSelector(FailoverTargetSelector selector) {
+        customSelector = selector;
+    }
+    
     @Override
     public FailoverStrategy getStrategy()  {
         FailoverStrategy strategy = super.getStrategy();

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java?rev=1133016&r1=1133015&r2=1133016&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/failover/FailoverTest.java
Tue Jun  7 14:02:31 2011
@@ -34,6 +34,9 @@ import org.apache.cxf.jaxrs.client.JAXRS
 import org.apache.cxf.jaxrs.client.ServerWebApplicationException;
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.features.clustering.FailoverFeature;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.systest.jaxrs.Book;
 import org.apache.cxf.systest.jaxrs.BookStore;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
@@ -78,46 +81,60 @@ public class FailoverTest extends Abstra
     @Test    
     public void testSequentialStrategy() throws Exception {
         FailoverFeature feature = 
-            getFeature(false, Server.ADDRESS2, Server.ADDRESS3); 
+            getFeature(false, false, Server.ADDRESS2, Server.ADDRESS3); 
         strategyTest(Server.ADDRESS1, feature, Server.ADDRESS2, null, 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);
+    }
+    
     @Test
     public void testSequentialStrategyWebClient() throws Exception {
         FailoverFeature feature = 
-            getFeature(false, Server.ADDRESS3, Server.ADDRESS2); 
-        strategyTestWebClient(Server.ADDRESS1, feature, Server.ADDRESS3, null, false, false);
+            getFeature(false, false, Server.ADDRESS2, Server.ADDRESS3); 
+        strategyTestWebClient(Server.ADDRESS1, feature, Server.ADDRESS2, null, false, false);
+    }
+    
+    @Test
+    public void testRandomStrategyWebClient() throws Exception {
+        FailoverFeature feature = 
+            getFeature(false, true, Server.ADDRESS3, Server.ADDRESS2); 
+        strategyTestWebClient(Server.ADDRESS1, feature, Server.ADDRESS3, Server.ADDRESS2,
false, true);
     }
     
     @Test    
     public void testRandomStrategy() throws Exception {
         FailoverFeature feature = 
-            getFeature(true, Server.ADDRESS2, Server.ADDRESS3); 
+            getFeature(false, true, Server.ADDRESS2, Server.ADDRESS3); 
         strategyTest(Server.ADDRESS1, feature, Server.ADDRESS2, Server.ADDRESS3, false, true);
     }
     
     @Test    
     public void testSequentialStrategyWithDiffBaseAddresses() throws Exception {
         FailoverFeature feature = 
-            getFeature(false, Server.ADDRESS3, null); 
+            getFeature(false, false, Server.ADDRESS3, null); 
         strategyTest(Server.ADDRESS1, feature, Server.ADDRESS3, Server.ADDRESS2, false, false);
     }
     
     @Test(expected = ServerWebApplicationException.class)
     public void testSequentialStrategyWithServerException() throws Exception {
         FailoverFeature feature = 
-            getFeature(false, Server.ADDRESS2, Server.ADDRESS3); 
+            getFeature(false, false, Server.ADDRESS2, Server.ADDRESS3); 
         strategyTest(Server.ADDRESS1, feature, Server.ADDRESS2, Server.ADDRESS3, true, false);
     }
     
     @Test(expected = ClientWebApplicationException.class)    
     public void testSequentialStrategyFailure() throws Exception {
         FailoverFeature feature = 
-            getFeature(false, "http://localhost:8080/non-existent"); 
+            getFeature(false, false, "http://localhost:8080/non-existent"); 
         strategyTest(Server.ADDRESS1, feature, null, null, false, false);
     }
 
-    private FailoverFeature getFeature(boolean random, String ...address) {
+    private FailoverFeature getFeature(boolean custom, boolean random, String ...address)
{
         FailoverFeature feature = new FailoverFeature();
         List<String> alternateAddresses = new ArrayList<String>();
         for (String s : address) {
@@ -132,6 +149,11 @@ public class FailoverTest extends Abstra
             strategy.setAlternateAddresses(alternateAddresses);
             feature.setStrategy(strategy);
         }
+        if (custom) {
+            FailoverTargetSelector selector = new ReplaceInitialAddressSelector(); 
+            feature.setTargetSelector(selector);
+        }
+        
         return feature;
     }
     
@@ -275,4 +297,18 @@ public class FailoverTest extends Abstra
         }
     }
     
+    private static class ReplaceInitialAddressSelector extends FailoverTargetSelector {
+        @Override
+        public synchronized void prepare(Message message) {
+            EndpointInfo ei = getEndpoint().getEndpointInfo();
+            ei.setAddress(Server.ADDRESS3); 
+            message.put(Message.ENDPOINT_ADDRESS, Server.ADDRESS3);
+            super.prepare(message);
+        }
+        
+        @Override
+        protected boolean requiresFailover(Exchange exchange) {
+            return false;
+        }
+    }
 }

Modified: cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/LoadDistributorAddressOverrideTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/LoadDistributorAddressOverrideTest.java?rev=1133016&r1=1133015&r2=1133016&view=diff
==============================================================================
--- cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/LoadDistributorAddressOverrideTest.java
(original)
+++ cxf/trunk/systests/uncategorized/src/test/java/org/apache/cxf/systest/clustering/LoadDistributorAddressOverrideTest.java
Tue Jun  7 14:02:31 2011
@@ -125,6 +125,7 @@ public class LoadDistributorAddressOverr
         for (int i = 0; i < 12; ++i) {
             try {
                 String response = greeter.greetMe("fred");
+                System.out.println(getCurrentEndpoint(greeter));
                 assertNotNull("expected non-null response", response);
                 incrementResponseCount(responseCounts, response);
             } catch (WebServiceException ex) {



Mime
View raw message