Search in sources :

Example 6 with BasicRequestLine

use of org.apache.http.message.BasicRequestLine 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 7 with BasicRequestLine

use of org.apache.http.message.BasicRequestLine in project XobotOS by xamarin.

the class HttpRequestBase method getRequestLine.

public RequestLine getRequestLine() {
    String method = getMethod();
    ProtocolVersion ver = getProtocolVersion();
    URI uri = getURI();
    String uritext = null;
    if (uri != null) {
        uritext = uri.toASCIIString();
    }
    if (uritext == null || uritext.length() == 0) {
        uritext = "/";
    }
    return new BasicRequestLine(method, uritext, ver);
}
Also used : BasicRequestLine(org.apache.http.message.BasicRequestLine) ProtocolVersion(org.apache.http.ProtocolVersion) URI(java.net.URI)

Example 8 with BasicRequestLine

use of org.apache.http.message.BasicRequestLine in project robovm by robovm.

the class HttpRequestBase method getRequestLine.

public RequestLine getRequestLine() {
    String method = getMethod();
    ProtocolVersion ver = getProtocolVersion();
    URI uri = getURI();
    String uritext = null;
    if (uri != null) {
        uritext = uri.toASCIIString();
    }
    if (uritext == null || uritext.length() == 0) {
        uritext = "/";
    }
    return new BasicRequestLine(method, uritext, ver);
}
Also used : BasicRequestLine(org.apache.http.message.BasicRequestLine) ProtocolVersion(org.apache.http.ProtocolVersion) URI(java.net.URI)

Example 9 with BasicRequestLine

use of org.apache.http.message.BasicRequestLine in project LogHub by fbacchella.

the class AbstractHttpSender method doRequest.

protected HttpResponse doRequest(HttpRequest therequest) {
    CloseableHttpResponse response = null;
    HttpClientContext context = HttpClientContext.create();
    if (credsProvider != null) {
        context.setCredentialsProvider(credsProvider);
    }
    HttpHost host;
    RequestLine requestLine = new BasicRequestLine(therequest.verb, therequest.url.getPath(), therequest.httpVersion);
    BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(requestLine);
    if (therequest.content != null) {
        request.setEntity(therequest.content);
    }
    therequest.headers.forEach((i, j) -> request.addHeader(i, j));
    host = new HttpHost(therequest.url.getHost(), therequest.url.getPort(), therequest.url.getProtocol());
    try {
        response = client.execute(host, request, context);
    } catch (ConnectionPoolTimeoutException e) {
        logger.error("Connection to {} timed out", host);
        return new HttpResponse(host, null, e, null);
    } catch (HttpHostConnectException e) {
        String message = "";
        try {
            throw e.getCause();
        } catch (ConnectException e1) {
            message = String.format("Connection to %s refused", host);
        } catch (SocketTimeoutException e1) {
            message = String.format("Slow response from %s", host);
        } catch (Throwable e1) {
            message = String.format("Connection to %s failed: %s", host, e1.getMessage());
            logger.catching(Level.DEBUG, e1);
        }
        logger.error(message);
        logger.catching(Level.DEBUG, e.getCause());
        return new HttpResponse(host, null, e, null);
    } catch (IOException e) {
        Throwable rootCause = e;
        while (rootCause.getCause() != null) {
            rootCause = rootCause.getCause();
        }
        ;
        // A TLS exception, will not help to retry
        if (rootCause instanceof GeneralSecurityException) {
            logger.error("Secure comunication with {} failed: {}", host, rootCause.getMessage());
            logger.catching(Level.DEBUG, rootCause);
            return new HttpResponse(host, null, null, (GeneralSecurityException) rootCause);
        } else {
            logger.error("Comunication with {} failed: {}", host, e.getMessage());
            logger.catching(Level.DEBUG, e);
            return new HttpResponse(host, null, e, null);
        }
    }
    if (response == null) {
        logger.error("give up trying to connect to " + getPublishName());
        return null;
    }
    ;
    return new HttpResponse(host, response, null, null);
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ConnectionPoolTimeoutException(org.apache.http.conn.ConnectionPoolTimeoutException) RequestLine(org.apache.http.RequestLine) BasicRequestLine(org.apache.http.message.BasicRequestLine) SocketTimeoutException(java.net.SocketTimeoutException) HttpHost(org.apache.http.HttpHost) BasicRequestLine(org.apache.http.message.BasicRequestLine) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) BasicHttpEntityEnclosingRequest(org.apache.http.message.BasicHttpEntityEnclosingRequest) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) ConnectException(java.net.ConnectException)

Example 10 with BasicRequestLine

use of org.apache.http.message.BasicRequestLine in project platform_external_apache-http by android.

the class RequestWrapper method getRequestLine.

public RequestLine getRequestLine() {
    String method = getMethod();
    ProtocolVersion ver = getProtocolVersion();
    String uritext = null;
    if (uri != null) {
        uritext = uri.toASCIIString();
    }
    if (uritext == null || uritext.length() == 0) {
        uritext = "/";
    }
    return new BasicRequestLine(method, uritext, ver);
}
Also used : BasicRequestLine(org.apache.http.message.BasicRequestLine) ProtocolVersion(org.apache.http.ProtocolVersion)

Aggregations

BasicRequestLine (org.apache.http.message.BasicRequestLine)11 ProtocolVersion (org.apache.http.ProtocolVersion)9 HttpHost (org.apache.http.HttpHost)5 RequestLine (org.apache.http.RequestLine)5 URI (java.net.URI)3 HttpResponse (org.apache.http.HttpResponse)3 StatusLine (org.apache.http.StatusLine)3 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)3 BasicStatusLine (org.apache.http.message.BasicStatusLine)3 HttpEntity (org.apache.http.HttpEntity)2 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)2 BasicHttpEntityEnclosingRequest (org.apache.http.message.BasicHttpEntityEnclosingRequest)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 ConnectException (java.net.ConnectException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 ConnectionPoolTimeoutException (org.apache.http.conn.ConnectionPoolTimeoutException)1