Search in sources :

Example 16 with RequestLine

use of org.apache.http.RequestLine in project elasticsearch by elastic.

the class FailureTrackingResponseListenerTests method mockResponse.

private static Response mockResponse() {
    ProtocolVersion protocolVersion = new ProtocolVersion("HTTP", 1, 1);
    RequestLine requestLine = new BasicRequestLine("GET", "/", protocolVersion);
    StatusLine statusLine = new BasicStatusLine(protocolVersion, 200, "OK");
    HttpResponse httpResponse = new BasicHttpResponse(statusLine);
    return new Response(requestLine, new HttpHost("localhost", 9200), httpResponse);
}
Also used : BasicStatusLine(org.apache.http.message.BasicStatusLine) StatusLine(org.apache.http.StatusLine) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) BasicRequestLine(org.apache.http.message.BasicRequestLine) RequestLine(org.apache.http.RequestLine) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) BasicRequestLine(org.apache.http.message.BasicRequestLine) HttpHost(org.apache.http.HttpHost) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) ProtocolVersion(org.apache.http.ProtocolVersion) BasicStatusLine(org.apache.http.message.BasicStatusLine)

Example 17 with RequestLine

use of org.apache.http.RequestLine in project okhttp by square.

the class OkApacheClient method transformRequest.

private static Request transformRequest(HttpRequest request) {
    Request.Builder builder = new Request.Builder();
    RequestLine requestLine = request.getRequestLine();
    String method = requestLine.getMethod();
    builder.url(requestLine.getUri());
    String contentType = null;
    for (Header header : request.getAllHeaders()) {
        String name = header.getName();
        if ("Content-Type".equalsIgnoreCase(name)) {
            contentType = header.getValue();
        } else {
            builder.header(name, header.getValue());
        }
    }
    RequestBody body = null;
    if (request instanceof HttpEntityEnclosingRequest) {
        HttpEntity entity = ((HttpEntityEnclosingRequest) request).getEntity();
        if (entity != null) {
            // Wrap the entity in a custom Body which takes care of the content, length, and type.
            body = new HttpEntityBody(entity, contentType);
            Header encoding = entity.getContentEncoding();
            if (encoding != null) {
                builder.header(encoding.getName(), encoding.getValue());
            }
        } else {
            body = Util.EMPTY_REQUEST;
        }
    }
    builder.method(method, body);
    return builder.build();
}
Also used : RequestLine(org.apache.http.RequestLine) Header(org.apache.http.Header) HttpEntity(org.apache.http.HttpEntity) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) Request(okhttp3.Request) HttpRequest(org.apache.http.HttpRequest) RequestBody(okhttp3.RequestBody)

Example 18 with RequestLine

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

the class HttpRequestParser method parseHead.

protected HttpMessage parseHead(final SessionInputBuffer sessionBuffer) throws IOException, HttpException, ParseException {
    this.lineBuf.clear();
    int i = sessionBuffer.readLine(this.lineBuf);
    if (i == -1) {
        throw new ConnectionClosedException("Client closed connection");
    }
    ParserCursor cursor = new ParserCursor(0, this.lineBuf.length());
    RequestLine requestline = this.lineParser.parseRequestLine(this.lineBuf, cursor);
    return this.requestFactory.newHttpRequest(requestline);
}
Also used : ParserCursor(org.apache.http.message.ParserCursor) RequestLine(org.apache.http.RequestLine) ConnectionClosedException(org.apache.http.ConnectionClosedException)

Example 19 with RequestLine

use of org.apache.http.RequestLine in project incubator-skywalking by apache.

the class HttpClientExecuteInterceptorTest method setUp.

@Before
public void setUp() throws Exception {
    ServiceManager.INSTANCE.boot();
    httpClientExecuteInterceptor = new HttpClientExecuteInterceptor();
    PowerMockito.mock(HttpHost.class);
    when(statusLine.getStatusCode()).thenReturn(200);
    when(httpResponse.getStatusLine()).thenReturn(statusLine);
    when(httpHost.getHostName()).thenReturn("127.0.0.1");
    when(httpHost.getSchemeName()).thenReturn("http");
    when(request.getRequestLine()).thenReturn(new RequestLine() {

        @Override
        public String getMethod() {
            return "GET";
        }

        @Override
        public ProtocolVersion getProtocolVersion() {
            return new ProtocolVersion("http", 1, 1);
        }

        @Override
        public String getUri() {
            return "http://127.0.0.1:8080/test-web/test";
        }
    });
    when(httpHost.getPort()).thenReturn(8080);
    allArguments = new Object[] { httpHost, request };
    argumentsType = new Class[] { httpHost.getClass(), request.getClass() };
}
Also used : RequestLine(org.apache.http.RequestLine) Matchers.anyString(org.mockito.Matchers.anyString) ProtocolVersion(org.apache.http.ProtocolVersion) Before(org.junit.Before)

Example 20 with RequestLine

use of org.apache.http.RequestLine in project connect-sdk-java by Ingenico-ePayments.

the class DefaultConnection method logRequest.

// logging code
private void logRequest(final HttpRequest request, final String requestId, final CommunicatorLogger logger) {
    try {
        RequestLine requestLine = request.getRequestLine();
        String method = requestLine.getMethod();
        String uri = requestLine.getUri();
        final RequestLogMessageBuilder logMessageBuilder = new RequestLogMessageBuilder(requestId, method, uri);
        addHeaders(logMessageBuilder, request.getAllHeaders());
        if (request instanceof HttpEntityEnclosingRequest) {
            final HttpEntityEnclosingRequest entityEnclosingRequest = (HttpEntityEnclosingRequest) request;
            HttpEntity entity = entityEnclosingRequest.getEntity();
            if (entity != null && !entity.isRepeatable()) {
                entity = new BufferedHttpEntity(entity);
                entityEnclosingRequest.setEntity(entity);
            }
            setBody(logMessageBuilder, entity, request.getFirstHeader(HttpHeaders.CONTENT_TYPE));
        }
        logger.log(logMessageBuilder.getMessage());
    } catch (Exception e) {
        logger.log(String.format("An error occurred trying to log request '%s'", requestId), e);
        return;
    }
}
Also used : RequestLine(org.apache.http.RequestLine) HttpEntity(org.apache.http.HttpEntity) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) BufferedHttpEntity(org.apache.http.entity.BufferedHttpEntity) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) RequestLogMessageBuilder(com.ingenico.connect.gateway.sdk.java.logging.RequestLogMessageBuilder) CommunicationException(com.ingenico.connect.gateway.sdk.java.CommunicationException) HttpException(org.apache.http.HttpException) ClientProtocolException(org.apache.http.client.ClientProtocolException) IOException(java.io.IOException)

Aggregations

RequestLine (org.apache.http.RequestLine)29 IOException (java.io.IOException)9 HttpHost (org.apache.http.HttpHost)9 HttpEntity (org.apache.http.HttpEntity)7 ProtocolVersion (org.apache.http.ProtocolVersion)7 StatusLine (org.apache.http.StatusLine)6 BasicRequestLine (org.apache.http.message.BasicRequestLine)6 HttpRequest (org.apache.http.HttpRequest)5 HttpException (org.apache.http.HttpException)4 HttpResponse (org.apache.http.HttpResponse)4 ConnectionClosedException (org.apache.http.ConnectionClosedException)3 Header (org.apache.http.Header)3 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)3 BasicHttpEntityEnclosingRequest (org.apache.http.message.BasicHttpEntityEnclosingRequest)3 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)3 BasicStatusLine (org.apache.http.message.BasicStatusLine)3 Before (org.junit.Before)3 Matchers.anyString (org.mockito.Matchers.anyString)3 SocketTimeoutException (java.net.SocketTimeoutException)2 URL (java.net.URL)2