Search in sources :

Example 1 with LoadDistributorFeature

use of org.apache.cxf.clustering.LoadDistributorFeature in project camel by apache.

the class LoadDistributorFeatureTest method startRoute.

private void startRoute(DefaultCamelContext ctx, final String proxy, final String real) throws Exception {
    ctx.addRoutes(new RouteBuilder() {

        public void configure() {
            List<String> serviceList = new ArrayList<String>();
            serviceList.add(SERVICE_ADDRESS_1);
            serviceList.add(SERVICE_ADDRESS_2);
            SequentialStrategy strategy = new SequentialStrategy();
            strategy.setAlternateAddresses(serviceList);
            LoadDistributorFeature ldf = new LoadDistributorFeature();
            ldf.setStrategy(strategy);
            CxfEndpoint endpoint = (CxfEndpoint) (endpoint(real));
            endpoint.getFeatures().add(ldf);
            from(proxy).to(endpoint);
        }
    });
    ctx.start();
}
Also used : SequentialStrategy(org.apache.cxf.clustering.SequentialStrategy) RouteBuilder(org.apache.camel.builder.RouteBuilder) LoadDistributorFeature(org.apache.cxf.clustering.LoadDistributorFeature) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with LoadDistributorFeature

use of org.apache.cxf.clustering.LoadDistributorFeature in project cxf by apache.

the class LoadDistributorWebClientTest method testLoadDistributor.

@Test
public void testLoadDistributor() throws Exception {
    URL busFile = LoadDistributorWebClientTest.class.getResource("cxf-client.xml");
    String address = "http://localhost:" + PORT1 + "/bookstore";
    LoadDistributorFeature feature = new LoadDistributorFeature();
    SequentialStrategy strategy = new SequentialStrategy();
    List<String> addresses = new ArrayList<>();
    addresses.add(address);
    addresses.add("http://localhost:" + PORT2 + "/bookstore");
    strategy.setAlternateAddresses(addresses);
    feature.setStrategy(strategy);
    WebClient webClient = WebClient.create(address, null, Collections.singletonList(feature), busFile.toString()).accept("application/xml");
    Book b = webClient.get(Book.class);
    assertEquals(124L, b.getId());
    assertEquals("root", b.getName());
    b = webClient.get(Book.class);
    assertEquals(124L, b.getId());
    assertEquals("root", b.getName());
}
Also used : SequentialStrategy(org.apache.cxf.clustering.SequentialStrategy) Book(org.apache.cxf.systest.jaxrs.Book) LoadDistributorFeature(org.apache.cxf.clustering.LoadDistributorFeature) ArrayList(java.util.ArrayList) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL) Test(org.junit.Test)

Example 3 with LoadDistributorFeature

use of org.apache.cxf.clustering.LoadDistributorFeature in project testcases by coheigea.

the class LoadBalancerTest method testLoadBalancerFeature.

@org.junit.Test
public void testLoadBalancerFeature() throws Exception {
    URL busFile = LoadBalancerTest.class.getResource("cxf-client.xml");
    LoadDistributorFeature feature = new LoadDistributorFeature();
    SequentialStrategy strategy = new SequentialStrategy();
    List<String> addresses = new ArrayList<>();
    addresses.add("http://localhost:" + PORT1 + "/doubleit/services");
    addresses.add("http://localhost:" + PORT2 + "/doubleit/services");
    strategy.setAlternateAddresses(addresses);
    feature.setStrategy(strategy);
    String address = "http://localhost:" + PORT1 + "/doubleit/services";
    WebClient client = WebClient.create(address, null, Collections.singletonList(feature), busFile.toString());
    client = client.type("application/xml");
    Number numberToDouble = new Number();
    numberToDouble.setDescription("This is the number to double");
    numberToDouble.setNumber(25);
    // First call is successful to PORT1
    Response response = client.post(numberToDouble);
    assertEquals(response.getStatus(), 200);
    assertEquals(response.readEntity(Number.class).getNumber(), 50);
    // Second call is successful to PORT2
    response = client.post(numberToDouble);
    assertEquals(response.getStatus(), 200);
    assertEquals(response.readEntity(Number.class).getNumber(), 50);
}
Also used : Response(javax.ws.rs.core.Response) SequentialStrategy(org.apache.cxf.clustering.SequentialStrategy) Number(org.apache.coheigea.cxf.failover.common.Number) LoadDistributorFeature(org.apache.cxf.clustering.LoadDistributorFeature) ArrayList(java.util.ArrayList) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 4 with LoadDistributorFeature

use of org.apache.cxf.clustering.LoadDistributorFeature in project cxf by apache.

the class LoadDistributorTest method testSingleAltAddress.

@Test
public void testSingleAltAddress() throws Exception {
    LoadDistributorFeature feature = new LoadDistributorFeature();
    List<String> alternateAddresses = new ArrayList<>();
    alternateAddresses.add(Server.ADDRESS2);
    SequentialStrategy strategy = new SequentialStrategy();
    strategy.setAlternateAddresses(alternateAddresses);
    feature.setStrategy(strategy);
    BookStore bookStore = getBookStore(Server.ADDRESS1, feature);
    Book book = bookStore.getBook("123");
    assertEquals("unexpected id", 123L, book.getId());
    book = bookStore.getBook("123");
    assertEquals("unexpected id", 123L, book.getId());
}
Also used : BookStore(org.apache.cxf.systest.jaxrs.BookStore) SequentialStrategy(org.apache.cxf.clustering.SequentialStrategy) Book(org.apache.cxf.systest.jaxrs.Book) LoadDistributorFeature(org.apache.cxf.clustering.LoadDistributorFeature) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)4 LoadDistributorFeature (org.apache.cxf.clustering.LoadDistributorFeature)4 SequentialStrategy (org.apache.cxf.clustering.SequentialStrategy)4 URL (java.net.URL)2 WebClient (org.apache.cxf.jaxrs.client.WebClient)2 Book (org.apache.cxf.systest.jaxrs.Book)2 Test (org.junit.Test)2 List (java.util.List)1 Response (javax.ws.rs.core.Response)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 Number (org.apache.coheigea.cxf.failover.common.Number)1 BookStore (org.apache.cxf.systest.jaxrs.BookStore)1