use of org.apache.cxf.clustering.RandomStrategy in project cxf by apache.
the class JaxwsAsyncFailOverTest method testUseFailOverOnClient.
@Test
public void testUseFailOverOnClient() throws Exception {
List<String> serviceList = new ArrayList<>();
serviceList.add("http://localhost:" + PORT + "/SoapContext/GreeterPort");
RandomStrategy strategy = new RandomStrategy();
strategy.setAlternateAddresses(serviceList);
FailoverFeature ff = new FailoverFeature();
ff.setStrategy(strategy);
// setup the feature by using JAXWS front-end API
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
// set a fake address to kick off the failover feature
factory.setAddress("http://localhost:" + PORT2 + "/SoapContext/GreeterPort");
factory.getFeatures().add(ff);
factory.setServiceClass(Greeter.class);
Greeter proxy = factory.create(Greeter.class);
Response<GreetMeResponse> response = proxy.greetMeAsync("cxf");
int waitCount = 0;
while (!response.isDone() && waitCount < 15) {
Thread.sleep(1000);
waitCount++;
}
assertTrue("Response still not received.", response.isDone());
}
use of org.apache.cxf.clustering.RandomStrategy in project cxf by apache.
the class CircuitBreakerFailoverTest method customizeFeature.
private FailoverFeature customizeFeature(CircuitBreakerFailoverFeature feature, boolean random, String... address) {
List<String> alternateAddresses = new ArrayList<>();
for (String s : address) {
alternateAddresses.add(s);
}
if (!random) {
SequentialStrategy strategy = new SequentialStrategy();
strategy.setAlternateAddresses(alternateAddresses);
feature.setStrategy(strategy);
} else {
RandomStrategy strategy = new RandomStrategy();
strategy.setAlternateAddresses(alternateAddresses);
feature.setStrategy(strategy);
}
return feature;
}
use of org.apache.cxf.clustering.RandomStrategy in project cxf by apache.
the class FailoverTest method getCustomFeature.
private FailoverFeature getCustomFeature(boolean custom, boolean random, String... address) {
FailoverFeature feature = new FailoverFeature();
List<String> alternateAddresses = new ArrayList<>();
for (String s : address) {
alternateAddresses.add(s);
}
if (!random) {
SequentialStrategy strategy = new SequentialStrategy();
strategy.setAlternateAddresses(alternateAddresses);
feature.setStrategy(strategy);
} else {
RandomStrategy strategy = new RandomStrategy();
strategy.setAlternateAddresses(alternateAddresses);
feature.setStrategy(strategy);
}
if (custom) {
FailoverTargetSelector selector = new ReplaceInitialAddressSelector();
feature.setTargetSelector(selector);
}
return feature;
}
use of org.apache.cxf.clustering.RandomStrategy in project camel by apache.
the class FailOverFeatureTest method startRoute.
private void startRoute(DefaultCamelContext ctx, final String proxy, final String real) throws Exception {
ctx.addRoutes(new RouteBuilder() {
public void configure() {
String alt = SERVICE_ADDRESS;
List<String> serviceList = new ArrayList<String>();
serviceList.add(alt);
RandomStrategy strategy = new RandomStrategy();
strategy.setAlternateAddresses(serviceList);
FailoverFeature ff = new FailoverFeature();
ff.setStrategy(strategy);
CxfEndpoint endpoint = (CxfEndpoint) (endpoint(real));
endpoint.getFeatures().add(ff);
from(proxy).to(endpoint);
}
});
ctx.start();
}
use of org.apache.cxf.clustering.RandomStrategy in project jbossws-cxf by jbossws.
the class CXFClientClusterTestCase method testCluster.
@Test
@RunAsClient
public void testCluster() throws Exception {
List<String> serviceList = new ArrayList<String>();
serviceList.add(baseURL.toExternalForm() + "/ClusetrService");
RandomStrategy strategy = new RandomStrategy();
strategy.setAlternateAddresses(serviceList);
FailoverFeature ff = new FailoverFeature();
ff.setStrategy(strategy);
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setAddress("http://localhost:8080/notExist/NotExistPort");
factory.getFeatures().add(ff);
factory.setServiceClass(Endpoint.class);
Endpoint proxy = factory.create(Endpoint.class);
assertEquals("Unexpected resposne", "cluster", proxy.echo("cluster"));
URL wsdlURL = new URL(baseURL.toExternalForm() + "/ClusetrService?wsdl");
QName qname = new QName("http://org.jboss.ws/jaxws/cxf/endpoint", "EndpointService");
Service service = Service.create(wsdlURL, qname);
Endpoint endpoint = service.getPort(Endpoint.class, ff);
((BindingProvider) endpoint).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:8080/notExist/NotExistPort");
assertEquals("Unexpected resposne", "cluster", endpoint.echo("cluster"));
}
Aggregations