Search in sources :

Example 1 with HttpRequestHandler

use of org.apache.http.protocol.HttpRequestHandler in project camel by apache.

the class Http4EndpointTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    localServer = new HttpTestServer(null, null);
    localServer.register("/", new HttpRequestHandler() {

        public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
            response.setStatusCode(HttpStatus.SC_OK);
            response.setEntity(new StringEntity("OK", Consts.ISO_8859_1));
        }
    });
    localServer.start();
}
Also used : HttpRequest(org.apache.http.HttpRequest) StringEntity(org.apache.http.entity.StringEntity) HttpRequestHandler(org.apache.http.protocol.HttpRequestHandler) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) HttpException(org.apache.http.HttpException) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 2 with HttpRequestHandler

use of org.apache.http.protocol.HttpRequestHandler in project camel by apache.

the class Http4MaxConnectionPerHostTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    localServer = new HttpTestServer(null, null);
    localServer.register("/", new HttpRequestHandler() {

        public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
            response.setStatusCode(HttpStatus.SC_OK);
            response.setEntity(new StringEntity("OK", Consts.ISO_8859_1));
        }
    });
    localServer.start();
}
Also used : HttpRequest(org.apache.http.HttpRequest) StringEntity(org.apache.http.entity.StringEntity) HttpRequestHandler(org.apache.http.protocol.HttpRequestHandler) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) HttpException(org.apache.http.HttpException) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 3 with HttpRequestHandler

use of org.apache.http.protocol.HttpRequestHandler in project camel by apache.

the class HttpConcurrentTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    localServer = ServerBootstrap.bootstrap().setHttpProcessor(getBasicHttpProcessor()).setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory()).setExpectationVerifier(getHttpExpectationVerifier()).setSslContext(getSSLContext()).registerHandler("/", new HttpRequestHandler() {

        public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            // ignore
            }
            response.setStatusCode(HttpStatus.SC_OK);
            response.setEntity(new StringEntity("" + counter.incrementAndGet()));
        }
    }).create();
    localServer.start();
    super.setUp();
}
Also used : HttpRequest(org.apache.http.HttpRequest) StringEntity(org.apache.http.entity.StringEntity) HttpRequestHandler(org.apache.http.protocol.HttpRequestHandler) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) HttpException(org.apache.http.HttpException) IOException(java.io.IOException) Before(org.junit.Before)

Example 4 with HttpRequestHandler

use of org.apache.http.protocol.HttpRequestHandler in project camel by apache.

the class HttpProducerTwoHeadersWithSameKeyTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    localServer = ServerBootstrap.bootstrap().setHttpProcessor(getBasicHttpProcessor()).setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory()).setExpectationVerifier(getHttpExpectationVerifier()).setSslContext(getSSLContext()).registerHandler("/myapp", new HttpRequestHandler() {

        @Override
        public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
            Header[] from = request.getHeaders("from");
            assertEquals("me", from[0].getValue());
            Header[] to = request.getHeaders("to");
            assertEquals("[foo, bar]", to[0].getValue());
            response.setHeader("bar", "yes");
            response.addHeader("foo", "123");
            response.addHeader("foo", "456");
            response.setEntity(new StringEntity("OK", "ASCII"));
            response.setStatusCode(HttpStatus.SC_OK);
        }
    }).registerHandler("/myapp", new HttpRequestHandler() {

        @Override
        public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
            Header[] from = request.getHeaders("from");
            assertEquals("me", from[0].getValue());
            Header[] to = request.getHeaders("to");
            assertEquals("[foo, bar]", to[0].getValue());
            response.setHeader("bar", "yes");
            response.addHeader("foo", "123");
            response.addHeader("foo", "456");
            response.setEntity(new StringEntity("OK", "ASCII"));
            response.setStatusCode(HttpStatus.SC_OK);
        }
    }).create();
    localServer.start();
    super.setUp();
}
Also used : HttpRequest(org.apache.http.HttpRequest) StringEntity(org.apache.http.entity.StringEntity) Header(org.apache.http.Header) HttpRequestHandler(org.apache.http.protocol.HttpRequestHandler) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) HttpException(org.apache.http.HttpException) IOException(java.io.IOException) Before(org.junit.Before)

Example 5 with HttpRequestHandler

use of org.apache.http.protocol.HttpRequestHandler in project camel by apache.

the class HttpProducerTwoParametersWithSameKeyTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    localServer = ServerBootstrap.bootstrap().setHttpProcessor(getBasicHttpProcessor()).setConnectionReuseStrategy(getConnectionReuseStrategy()).setResponseFactory(getHttpResponseFactory()).setExpectationVerifier(getHttpExpectationVerifier()).setSslContext(getSSLContext()).registerHandler("/myapp", new HttpRequestHandler() {

        @Override
        public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
            String uri = request.getRequestLine().getUri();
            assertEquals("/myapp?from=me&to=foo&to=bar", uri);
            response.setHeader("bar", "yes");
            response.addHeader("foo", "123");
            response.addHeader("foo", "456");
            response.setEntity(new StringEntity("OK", "ASCII"));
            response.setStatusCode(HttpStatus.SC_OK);
        }
    }).create();
    localServer.start();
    super.setUp();
}
Also used : HttpRequest(org.apache.http.HttpRequest) StringEntity(org.apache.http.entity.StringEntity) HttpRequestHandler(org.apache.http.protocol.HttpRequestHandler) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) HttpException(org.apache.http.HttpException) IOException(java.io.IOException) Before(org.junit.Before)

Aggregations

IOException (java.io.IOException)7 HttpException (org.apache.http.HttpException)7 HttpRequest (org.apache.http.HttpRequest)7 HttpResponse (org.apache.http.HttpResponse)7 HttpContext (org.apache.http.protocol.HttpContext)7 HttpRequestHandler (org.apache.http.protocol.HttpRequestHandler)7 StringEntity (org.apache.http.entity.StringEntity)6 Before (org.junit.Before)5 Header (org.apache.http.Header)2 BeforeClass (org.junit.BeforeClass)2