Search in sources :

Example 1 with RandomStrategy

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());
}
Also used : RandomStrategy(org.apache.cxf.clustering.RandomStrategy) Greeter(org.apache.cxf.greeter_control.Greeter) ArrayList(java.util.ArrayList) FailoverFeature(org.apache.cxf.clustering.FailoverFeature) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) GreetMeResponse(org.apache.cxf.greeter_control.types.GreetMeResponse) Test(org.junit.Test)

Example 2 with RandomStrategy

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;
}
Also used : SequentialStrategy(org.apache.cxf.clustering.SequentialStrategy) RandomStrategy(org.apache.cxf.clustering.RandomStrategy) ArrayList(java.util.ArrayList)

Example 3 with RandomStrategy

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;
}
Also used : SequentialStrategy(org.apache.cxf.clustering.SequentialStrategy) RandomStrategy(org.apache.cxf.clustering.RandomStrategy) FailoverFeature(org.apache.cxf.clustering.FailoverFeature) ArrayList(java.util.ArrayList) FailoverTargetSelector(org.apache.cxf.clustering.FailoverTargetSelector)

Example 4 with RandomStrategy

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();
}
Also used : RouteBuilder(org.apache.camel.builder.RouteBuilder) RandomStrategy(org.apache.cxf.clustering.RandomStrategy) FailoverFeature(org.apache.cxf.clustering.FailoverFeature) List(java.util.List) ArrayList(java.util.ArrayList)

Example 5 with RandomStrategy

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"));
}
Also used : RandomStrategy(org.apache.cxf.clustering.RandomStrategy) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) FailoverFeature(org.apache.cxf.clustering.FailoverFeature) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) Service(javax.xml.ws.Service) URL(java.net.URL) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Aggregations

ArrayList (java.util.ArrayList)5 RandomStrategy (org.apache.cxf.clustering.RandomStrategy)5 FailoverFeature (org.apache.cxf.clustering.FailoverFeature)4 SequentialStrategy (org.apache.cxf.clustering.SequentialStrategy)2 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)2 Test (org.junit.Test)2 URL (java.net.URL)1 List (java.util.List)1 QName (javax.xml.namespace.QName)1 Service (javax.xml.ws.Service)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 FailoverTargetSelector (org.apache.cxf.clustering.FailoverTargetSelector)1 Greeter (org.apache.cxf.greeter_control.Greeter)1 GreetMeResponse (org.apache.cxf.greeter_control.types.GreetMeResponse)1 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)1 JBossWSTest (org.jboss.wsf.test.JBossWSTest)1