Search in sources :

Example 86 with HttpRequest

use of org.apache.http.HttpRequest in project XobotOS by xamarin.

the class AbstractHttpServerConnection method receiveRequestHeader.

public HttpRequest receiveRequestHeader() throws HttpException, IOException {
    assertOpen();
    HttpRequest request = (HttpRequest) this.requestParser.parse();
    this.metrics.incrementRequestCount();
    return request;
}
Also used : HttpRequest(org.apache.http.HttpRequest)

Example 87 with HttpRequest

use of org.apache.http.HttpRequest 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 88 with HttpRequest

use of org.apache.http.HttpRequest 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)

Example 89 with HttpRequest

use of org.apache.http.HttpRequest 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 90 with HttpRequest

use of org.apache.http.HttpRequest 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

HttpRequest (org.apache.http.HttpRequest)155 HttpResponse (org.apache.http.HttpResponse)57 HttpContext (org.apache.http.protocol.HttpContext)56 HttpHost (org.apache.http.HttpHost)52 Test (org.junit.Test)40 IOException (java.io.IOException)36 Header (org.apache.http.Header)33 HttpException (org.apache.http.HttpException)33 HttpEntity (org.apache.http.HttpEntity)27 HttpEntityEnclosingRequest (org.apache.http.HttpEntityEnclosingRequest)25 BasicHttpRequest (org.apache.http.message.BasicHttpRequest)22 HttpGet (org.apache.http.client.methods.HttpGet)21 HttpPost (org.apache.http.client.methods.HttpPost)21 URI (java.net.URI)19 ProtocolException (org.apache.http.ProtocolException)18 AbortableHttpRequest (org.apache.http.client.methods.AbortableHttpRequest)16 StringEntity (org.apache.http.entity.StringEntity)16 ArrayList (java.util.ArrayList)14 NameValuePair (org.apache.http.NameValuePair)14 CredentialsProvider (org.apache.http.client.CredentialsProvider)14