Search in sources :

Example 1 with HttpClient

use of com.predic8.membrane.core.transport.http.HttpClient in project service-proxy by membrane.

the class LargeBodyTest method largeChunked.

@Test
public void largeChunked() throws Exception {
    setup();
    long len = Integer.MAX_VALUE + 1l;
    Exchange e = new Request.Builder().post("http://localhost:3041/foo").body(len, new ConstantInputStream(len)).header(TRANSFER_ENCODING, CHUNKED).buildExchange();
    new HttpClient(hcc).call(e);
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) HttpClient(com.predic8.membrane.core.transport.http.HttpClient) Test(org.junit.Test)

Example 2 with HttpClient

use of com.predic8.membrane.core.transport.http.HttpClient in project service-proxy by membrane.

the class LoadBalancingInterceptorTest method testFailOverOnConnectionRefused.

@Test
public void testFailOverOnConnectionRefused() throws Exception {
    balancingInterceptor.setDispatchingStrategy(roundRobinStrategy);
    HttpClient client = new HttpClient();
    client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    assertEquals(200, client.executeMethod(getPostMethod()));
    assertEquals(1, mockInterceptor1.getCount());
    assertEquals(0, mockInterceptor2.getCount());
    assertEquals(200, client.executeMethod(getPostMethod()));
    assertEquals(1, mockInterceptor1.getCount());
    assertEquals(1, mockInterceptor2.getCount());
    service1.shutdown();
    Thread.sleep(1000);
    assertEquals(200, client.executeMethod(getPostMethod()));
    assertEquals(1, mockInterceptor1.getCount());
    assertEquals(2, mockInterceptor2.getCount());
    assertEquals(200, client.executeMethod(getPostMethod()));
    assertEquals(3, mockInterceptor2.getCount());
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) Test(org.junit.Test) Http11Test(com.predic8.membrane.integration.Http11Test)

Example 3 with HttpClient

use of com.predic8.membrane.core.transport.http.HttpClient in project service-proxy by membrane.

the class LoadBalancingInterceptorTest method testFailOverOnStatus500.

@Test
public void testFailOverOnStatus500() throws Exception {
    balancingInterceptor.setDispatchingStrategy(roundRobinStrategy);
    HttpClient client = new HttpClient();
    client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    assertEquals(200, client.executeMethod(getPostMethod()));
    assertEquals(1, mockInterceptor1.getCount());
    assertEquals(0, mockInterceptor2.getCount());
    assertEquals(200, client.executeMethod(getPostMethod()));
    assertEquals(1, mockInterceptor1.getCount());
    assertEquals(1, mockInterceptor2.getCount());
    ((ServiceProxy) service1.getRuleManager().getRules().get(0)).getInterceptors().add(0, new AbstractInterceptor() {

        @Override
        public Outcome handleRequest(Exchange exc) throws Exception {
            exc.setResponse(Response.internalServerError().build());
            return Outcome.ABORT;
        }
    });
    assertEquals(200, client.executeMethod(getPostMethod()));
    assertEquals(1, mockInterceptor1.getCount());
    assertEquals(2, mockInterceptor2.getCount());
    assertEquals(200, client.executeMethod(getPostMethod()));
    assertEquals(3, mockInterceptor2.getCount());
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Outcome(com.predic8.membrane.core.interceptor.Outcome) HttpClient(org.apache.commons.httpclient.HttpClient) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) Test(org.junit.Test) Http11Test(com.predic8.membrane.integration.Http11Test)

Example 4 with HttpClient

use of com.predic8.membrane.core.transport.http.HttpClient in project service-proxy by membrane.

the class LoadBalancingInterceptorTest method testExpect100Continue.

@Test
public void testExpect100Continue() throws Exception {
    balancingInterceptor.setDispatchingStrategy(roundRobinStrategy);
    HttpClient client = new HttpClient();
    Http11Test.initExpect100ContinueWithFastFail(client);
    PostMethod vari = getPostMethod();
    int status = client.executeMethod(vari);
    assertEquals(200, status);
    assertEquals(1, mockInterceptor1.getCount());
    assertEquals(0, mockInterceptor2.getCount());
    assertEquals(200, client.executeMethod(getPostMethod()));
    assertEquals(1, mockInterceptor1.getCount());
    assertEquals(1, mockInterceptor2.getCount());
    assertEquals(200, client.executeMethod(getPostMethod()));
    assertEquals(2, mockInterceptor1.getCount());
    assertEquals(1, mockInterceptor2.getCount());
    assertEquals(200, client.executeMethod(getPostMethod()));
    assertEquals(2, mockInterceptor1.getCount());
    assertEquals(2, mockInterceptor2.getCount());
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) Test(org.junit.Test) Http11Test(com.predic8.membrane.integration.Http11Test)

Example 5 with HttpClient

use of com.predic8.membrane.core.transport.http.HttpClient in project service-proxy by membrane.

the class LBNotificationClient method notifiyClusterManager.

private Response notifiyClusterManager() throws Exception {
    HttpClient client = new HttpClient();
    Exchange exc = new Exchange(null);
    Request r = MessageUtil.getPostRequest(getRequestURL());
    r.setBodyContent(new byte[0]);
    exc.setRequest(r);
    exc.getDestinations().add(getRequestURL());
    Response res = client.call(exc).getResponse();
    return res;
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Response(com.predic8.membrane.core.http.Response) HttpClient(com.predic8.membrane.core.transport.http.HttpClient) Request(com.predic8.membrane.core.http.Request)

Aggregations

Test (org.junit.Test)15 Exchange (com.predic8.membrane.core.exchange.Exchange)13 HttpClient (com.predic8.membrane.core.transport.http.HttpClient)9 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)6 Outcome (com.predic8.membrane.core.interceptor.Outcome)6 Response (com.predic8.membrane.core.http.Response)5 IOException (java.io.IOException)5 URISyntaxException (java.net.URISyntaxException)5 HttpClient (org.apache.commons.httpclient.HttpClient)5 Http11Test (com.predic8.membrane.integration.Http11Test)4 Request (com.predic8.membrane.core.http.Request)3 HttpClientConfiguration (com.predic8.membrane.core.transport.http.client.HttpClientConfiguration)2 URIFactory (com.predic8.membrane.core.util.URIFactory)2 PostMethod (org.apache.commons.httpclient.methods.PostMethod)2 HttpRouter (com.predic8.membrane.core.HttpRouter)1 Router (com.predic8.membrane.core.Router)1 KeyStore (com.predic8.membrane.core.config.security.KeyStore)1 SSLParser (com.predic8.membrane.core.config.security.SSLParser)1 TrustStore (com.predic8.membrane.core.config.security.TrustStore)1 CountInterceptor (com.predic8.membrane.core.interceptor.CountInterceptor)1