Search in sources :

Example 46 with Result

use of org.eclipse.jetty.client.api.Result in project jetty.project by eclipse.

the class ExternalSiteTest method testExternalSSLSite.

@Test
public void testExternalSSLSite() throws Exception {
    client.stop();
    client = new HttpClient(new SslContextFactory());
    client.start();
    String host = "api-3t.paypal.com";
    int port = 443;
    // Verify that we have connectivity
    assumeCanConnectTo(host, port);
    final CountDownLatch latch = new CountDownLatch(1);
    client.newRequest(host, port).scheme("https").path("/nvp").send(new Response.CompleteListener() {

        @Override
        public void onComplete(Result result) {
            if (result.isSucceeded() && result.getResponse().getStatus() == 200)
                latch.countDown();
        }
    });
    Assert.assertTrue(latch.await(5, TimeUnit.SECONDS));
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Response(org.eclipse.jetty.client.api.Response) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) CountDownLatch(java.util.concurrent.CountDownLatch) Result(org.eclipse.jetty.client.api.Result) Test(org.junit.Test)

Example 47 with Result

use of org.eclipse.jetty.client.api.Result in project jetty.project by eclipse.

the class ExternalSiteTest method testExternalSiteWrongProtocol.

@Test
public void testExternalSiteWrongProtocol() throws Exception {
    String host = "github.com";
    // SSH port
    int port = 22;
    // Verify that we have connectivity
    assumeCanConnectTo(host, port);
    for (int i = 0; i < 2; ++i) {
        final CountDownLatch latch = new CountDownLatch(3);
        client.newRequest(host, port).onResponseFailure(new Response.FailureListener() {

            @Override
            public void onFailure(Response response, Throwable failure) {
                latch.countDown();
            }
        }).send(new Response.Listener.Adapter() {

            @Override
            public void onFailure(Response response, Throwable failure) {
                latch.countDown();
            }

            @Override
            public void onComplete(Result result) {
                Assert.assertTrue(result.isFailed());
                latch.countDown();
            }
        });
        Assert.assertTrue(latch.await(10, TimeUnit.SECONDS));
    }
}
Also used : ContentResponse(org.eclipse.jetty.client.api.ContentResponse) Response(org.eclipse.jetty.client.api.Response) CountDownLatch(java.util.concurrent.CountDownLatch) Result(org.eclipse.jetty.client.api.Result) Test(org.junit.Test)

Example 48 with Result

use of org.eclipse.jetty.client.api.Result in project jetty.project by eclipse.

the class HttpReceiver method terminateResponse.

private void terminateResponse(HttpExchange exchange) {
    Result result = exchange.terminateResponse();
    terminateResponse(exchange, result);
}
Also used : Result(org.eclipse.jetty.client.api.Result)

Example 49 with Result

use of org.eclipse.jetty.client.api.Result in project jetty.project by eclipse.

the class HttpReceiver method abort.

public boolean abort(HttpExchange exchange, Throwable failure) {
    // Update the state to avoid more response processing.
    boolean terminate;
    out: while (true) {
        ResponseState current = responseState.get();
        switch(current) {
            case FAILURE:
                {
                    return false;
                }
            default:
                {
                    if (updateResponseState(current, ResponseState.FAILURE)) {
                        terminate = current != ResponseState.TRANSIENT;
                        break out;
                    }
                    break;
                }
        }
    }
    this.failure = failure;
    dispose();
    HttpResponse response = exchange.getResponse();
    if (LOG.isDebugEnabled())
        LOG.debug("Response failure {} {} on {}: {}", response, exchange, getHttpChannel(), failure);
    List<Response.ResponseListener> listeners = exchange.getConversation().getResponseListeners();
    ResponseNotifier notifier = getHttpDestination().getResponseNotifier();
    notifier.notifyFailure(listeners, response, failure);
    if (terminate) {
        // Mark atomically the response as terminated, with
        // respect to concurrency between request and response.
        Result result = exchange.terminateResponse();
        terminateResponse(exchange, result);
    } else {
        if (LOG.isDebugEnabled())
            LOG.debug("Concurrent failure: response termination skipped, performed by helpers");
    }
    return true;
}
Also used : Result(org.eclipse.jetty.client.api.Result)

Example 50 with Result

use of org.eclipse.jetty.client.api.Result in project jetty.project by eclipse.

the class HttpRedirector method fail.

protected void fail(Request request, Response response, Throwable failure) {
    HttpConversation conversation = ((HttpRequest) request).getConversation();
    conversation.updateResponseListeners(null);
    List<Response.ResponseListener> listeners = conversation.getResponseListeners();
    notifier.notifyFailure(listeners, response, failure);
    notifier.notifyComplete(listeners, new Result(request, response, failure));
}
Also used : BufferingResponseListener(org.eclipse.jetty.client.util.BufferingResponseListener) Result(org.eclipse.jetty.client.api.Result)

Aggregations

Result (org.eclipse.jetty.client.api.Result)100 Test (org.junit.Test)80 CountDownLatch (java.util.concurrent.CountDownLatch)79 HttpServletResponse (javax.servlet.http.HttpServletResponse)74 HttpServletRequest (javax.servlet.http.HttpServletRequest)66 Response (org.eclipse.jetty.client.api.Response)62 IOException (java.io.IOException)60 ServletException (javax.servlet.ServletException)56 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)44 BufferingResponseListener (org.eclipse.jetty.client.util.BufferingResponseListener)41 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)39 Request (org.eclipse.jetty.client.api.Request)31 ByteBuffer (java.nio.ByteBuffer)29 Request (org.eclipse.jetty.server.Request)27 DeferredContentProvider (org.eclipse.jetty.client.util.DeferredContentProvider)24 InterruptedIOException (java.io.InterruptedIOException)21 ServletOutputStream (javax.servlet.ServletOutputStream)20 Slow (org.eclipse.jetty.toolchain.test.annotation.Slow)18 ByteArrayOutputStream (java.io.ByteArrayOutputStream)16 BytesContentProvider (org.eclipse.jetty.client.util.BytesContentProvider)16