Search in sources :

Example 1 with HttpExchange

use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.

the class HttpReceiverOverHTTP method messageComplete.

@Override
public boolean messageComplete() {
    HttpExchange exchange = getHttpExchange();
    if (exchange == null)
        return false;
    boolean proceed = responseSuccess(exchange);
    if (!proceed)
        return true;
    int status = exchange.getResponse().getStatus();
    if (status == HttpStatus.SWITCHING_PROTOCOLS_101)
        return true;
    if (HttpMethod.CONNECT.is(exchange.getRequest().getMethod()) && status == HttpStatus.OK_200)
        return true;
    return false;
}
Also used : HttpExchange(org.eclipse.jetty.client.HttpExchange) EndPoint(org.eclipse.jetty.io.EndPoint)

Example 2 with HttpExchange

use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.

the class HttpReceiverOverHTTP method startResponse.

@Override
public boolean startResponse(HttpVersion version, int status, String reason) {
    HttpExchange exchange = getHttpExchange();
    if (exchange == null)
        return false;
    String method = exchange.getRequest().getMethod();
    parser.setHeadResponse(HttpMethod.HEAD.is(method) || (HttpMethod.CONNECT.is(method) && status == HttpStatus.OK_200));
    exchange.getResponse().version(version).status(status).reason(reason);
    return !responseBegin(exchange);
}
Also used : HttpExchange(org.eclipse.jetty.client.HttpExchange)

Example 3 with HttpExchange

use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.

the class HttpReceiverOverHTTP method badMessage.

@Override
public void badMessage(int status, String reason) {
    HttpExchange exchange = getHttpExchange();
    if (exchange != null) {
        HttpResponse response = exchange.getResponse();
        response.status(status).reason(reason);
        failAndClose(new HttpResponseException("HTTP protocol violation: bad response on " + getHttpConnection(), response));
    }
}
Also used : HttpExchange(org.eclipse.jetty.client.HttpExchange) HttpResponse(org.eclipse.jetty.client.HttpResponse) HttpResponseException(org.eclipse.jetty.client.HttpResponseException)

Example 4 with HttpExchange

use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.

the class HttpReceiverOverHTTP method content.

@Override
public boolean content(ByteBuffer buffer) {
    HttpExchange exchange = getHttpExchange();
    if (exchange == null)
        return false;
    CompletableCallback callback = new CompletableCallback() {

        @Override
        public void resume() {
            if (LOG.isDebugEnabled())
                LOG.debug("Content consumed asynchronously, resuming processing");
            process();
        }

        public void abort(Throwable x) {
            failAndClose(x);
        }
    };
    // Do not short circuit these calls.
    boolean proceed = responseContent(exchange, buffer, callback);
    boolean async = callback.tryComplete();
    return !proceed || async;
}
Also used : CompletableCallback(org.eclipse.jetty.util.CompletableCallback) HttpExchange(org.eclipse.jetty.client.HttpExchange)

Example 5 with HttpExchange

use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.

the class HttpReceiverOverHTTPTest method newExchange.

protected HttpExchange newExchange() {
    HttpRequest request = (HttpRequest) client.newRequest("http://localhost");
    FutureResponseListener listener = new FutureResponseListener(request);
    HttpExchange exchange = new HttpExchange(destination, request, Collections.<Response.ResponseListener>singletonList(listener));
    boolean associated = connection.getHttpChannel().associate(exchange);
    Assert.assertTrue(associated);
    exchange.requestComplete(null);
    exchange.terminateRequest();
    return exchange;
}
Also used : HttpRequest(org.eclipse.jetty.client.HttpRequest) Response(org.eclipse.jetty.client.api.Response) HttpExchange(org.eclipse.jetty.client.HttpExchange) FutureResponseListener(org.eclipse.jetty.client.util.FutureResponseListener)

Aggregations

HttpExchange (org.eclipse.jetty.client.HttpExchange)25 FutureResponseListener (org.eclipse.jetty.client.util.FutureResponseListener)7 Response (org.eclipse.jetty.client.api.Response)6 Test (org.junit.Test)6 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)3 HttpRequest (org.eclipse.jetty.client.HttpRequest)3 HttpResponse (org.eclipse.jetty.client.HttpResponse)3 HttpFields (org.eclipse.jetty.http.HttpFields)3 EOFException (java.io.EOFException)2 HttpResponseException (org.eclipse.jetty.client.HttpResponseException)2 MetaData (org.eclipse.jetty.http.MetaData)2 Request (io.airlift.http.client.Request)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ByteBuffer (java.nio.ByteBuffer)1 TimeoutException (java.util.concurrent.TimeoutException)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1