Search in sources :

Example 11 with HttpClient

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

the class HelpLinkExistenceTest method doit.

@Test
public void doit() throws Exception {
    Set<Class<?>> classes = getElementClasses();
    Assert.assertNotEquals(0, classes.size());
    HttpClient hc = new HttpClient();
    for (Class<?> clazz : classes) {
        if (Interceptor.class.isAssignableFrom(clazz)) {
            Interceptor i = (Interceptor) clazz.newInstance();
            String helpId = i.getHelpId();
            String url = "http://membrane-soa.org/service-proxy-doc/" + getVersion() + "/configuration/reference/" + helpId + ".htm";
            Response r = hc.call(new Request.Builder().get(url).buildExchange()).getResponse();
            try {
                Assert.assertEquals(200, r.getStatusCode());
            } catch (Throwable e) {
                throw new RuntimeException(url, e);
            }
        }
    }
}
Also used : Response(com.predic8.membrane.core.http.Response) HttpClient(com.predic8.membrane.core.transport.http.HttpClient) Interceptor(com.predic8.membrane.core.interceptor.Interceptor) Test(org.junit.Test)

Example 12 with HttpClient

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

the class LoadBalancingInterceptorTest method testRoundRobinDispachingStrategy.

@Test
public void testRoundRobinDispachingStrategy() throws Exception {
    balancingInterceptor.setDispatchingStrategy(roundRobinStrategy);
    HttpClient client = new HttpClient();
    client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    PostMethod vari = getPostMethod();
    int status = client.executeMethod(vari);
    // System.out.println(new String(vari.getResponseBody()));
    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 13 with HttpClient

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

the class HttpKeepAliveTest method testConnectionClose.

@Test
public void testConnectionClose() throws Exception {
    HttpClient client = createHttpClient(500);
    sp1.getInterceptors().add(0, new AbstractInterceptor() {

        @Override
        public Outcome handleResponse(Exchange exc) throws Exception {
            exc.getResponse().getHeader().add(Header.KEEP_ALIVE, "max=2");
            return Outcome.CONTINUE;
        }
    });
    // opens connection 1
    assertEquals(200, issueRequest(client));
    assertEquals(1, set.size());
    assertEquals(1, client.getConnectionManager().getNumberInPool());
    // connection closer did not yet run
    Thread.sleep(600);
    // connection 1 is now dead, but still in pool
    assertEquals(1, client.getConnectionManager().getNumberInPool());
    // opens connection 2
    assertEquals(200, issueRequest(client));
    assertEquals(2, set.size());
    // connection closer runs and closes both
    Thread.sleep(600);
    assertEquals(0, client.getConnectionManager().getNumberInPool());
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Outcome(com.predic8.membrane.core.interceptor.Outcome) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Test(org.junit.Test)

Example 14 with HttpClient

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

the class HttpKeepAliveTest method issueRequest.

private int issueRequest(HttpClient client) throws IOException, Exception {
    Exchange exchange = createExchange();
    Response response = client.call(exchange).getResponse();
    response.readBody();
    return response.getStatusCode();
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Response(com.predic8.membrane.core.http.Response)

Example 15 with HttpClient

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

the class HttpKeepAliveTest method testTimeoutDefault.

@Test
public void testTimeoutDefault() throws Exception {
    HttpClient client = createHttpClient(1000);
    sp1.getInterceptors().add(0, new AbstractInterceptor() {

        @Override
        public Outcome handleResponse(Exchange exc) throws Exception {
            exc.getResponse().getHeader().add(Header.KEEP_ALIVE, "max=2");
            return Outcome.CONTINUE;
        }
    });
    assertEquals(200, issueRequest(client));
    assertEquals(1, set.size());
    Thread.sleep(1500);
    assertEquals(200, issueRequest(client));
    assertEquals(2, set.size());
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Outcome(com.predic8.membrane.core.interceptor.Outcome) AbstractInterceptor(com.predic8.membrane.core.interceptor.AbstractInterceptor) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Test(org.junit.Test)

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