Search in sources :

Example 6 with HttpRequestHandler

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

the class HttpProducerContentTypeTest method setUp.

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

        @Override
        public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
            String contentType = request.getFirstHeader(Exchange.CONTENT_TYPE).getValue();
            assertEquals(CONTENT_TYPE, contentType);
            response.setEntity(new StringEntity(contentType, "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)

Example 7 with HttpRequestHandler

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

the class HttpNoCamelHeaderTest method setUp.

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

        @Override
        public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
            response.setStatusCode(HttpStatus.SC_OK);
            Object header = request.getFirstHeader(Exchange.FILE_NAME);
            assertNull("There should be no Camel header", header);
            for (Header h : request.getAllHeaders()) {
                if (h.getName().startsWith("Camel") || h.getName().startsWith("org.apache.camel")) {
                    assertNull("There should be no Camel header", h);
                }
            }
            // set ar regular and Camel header
            response.setHeader("MyApp", "dude");
            response.setHeader(Exchange.TO_ENDPOINT, "foo");
        }
    }).create();
    localServer.start();
    super.setUp();
}
Also used : HttpRequest(org.apache.http.HttpRequest) 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)

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