Search in sources :

Example 36 with Request

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

the class HttpSender method queuedToBegin.

protected boolean queuedToBegin(HttpExchange exchange) {
    if (!updateRequestState(RequestState.QUEUED, RequestState.TRANSIENT))
        return false;
    Request request = exchange.getRequest();
    if (LOG.isDebugEnabled())
        LOG.debug("Request begin {}", request);
    RequestNotifier notifier = getHttpChannel().getHttpDestination().getRequestNotifier();
    notifier.notifyBegin(request);
    if (updateRequestState(RequestState.TRANSIENT, RequestState.BEGIN))
        return true;
    terminateRequest(exchange);
    return false;
}
Also used : Request(org.eclipse.jetty.client.api.Request)

Example 37 with Request

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

the class HttpSender method send.

public void send(HttpExchange exchange) {
    if (!queuedToBegin(exchange))
        return;
    Request request = exchange.getRequest();
    ContentProvider contentProvider = request.getContent();
    HttpContent content = this.content = new HttpContent(contentProvider);
    SenderState newSenderState = SenderState.SENDING;
    if (expects100Continue(request))
        newSenderState = content.hasContent() ? SenderState.EXPECTING_WITH_CONTENT : SenderState.EXPECTING;
    out: while (true) {
        SenderState current = senderState.get();
        switch(current) {
            case IDLE:
            case COMPLETED:
                {
                    if (updateSenderState(current, newSenderState))
                        break out;
                    break;
                }
            default:
                {
                    illegalSenderState(current);
                    return;
                }
        }
    }
    // threads so we must set it only after the sender state has been updated
    if (contentProvider instanceof AsyncContentProvider)
        ((AsyncContentProvider) contentProvider).setListener(this);
    if (!beginToHeaders(exchange))
        return;
    sendHeaders(exchange, content, commitCallback);
}
Also used : ContentProvider(org.eclipse.jetty.client.api.ContentProvider) Request(org.eclipse.jetty.client.api.Request)

Example 38 with Request

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

the class RedirectProtocolHandler method onComplete.

@Override
public void onComplete(Result result) {
    Request request = result.getRequest();
    Response response = result.getResponse();
    if (result.isSucceeded())
        redirector.redirect(request, response, null);
    else
        redirector.fail(request, response, result.getFailure());
}
Also used : Response(org.eclipse.jetty.client.api.Response) Request(org.eclipse.jetty.client.api.Request)

Example 39 with Request

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

the class HttpClientExplicitConnectionTest method testExplicitConnection.

@Test
public void testExplicitConnection() throws Exception {
    start(new EmptyServerHandler());
    Destination destination = client.getDestination(scheme, "localhost", connector.getLocalPort());
    FuturePromise<Connection> futureConnection = new FuturePromise<>();
    destination.newConnection(futureConnection);
    try (Connection connection = futureConnection.get(5, TimeUnit.SECONDS)) {
        Request request = client.newRequest(destination.getHost(), destination.getPort()).scheme(scheme);
        FutureResponseListener listener = new FutureResponseListener(request);
        connection.send(request, listener);
        ContentResponse response = listener.get(5, TimeUnit.SECONDS);
        Assert.assertNotNull(response);
        Assert.assertEquals(200, response.getStatus());
        HttpDestinationOverHTTP httpDestination = (HttpDestinationOverHTTP) destination;
        DuplexConnectionPool connectionPool = (DuplexConnectionPool) httpDestination.getConnectionPool();
        Assert.assertTrue(connectionPool.getActiveConnections().isEmpty());
        Assert.assertTrue(connectionPool.getIdleConnections().isEmpty());
    }
}
Also used : Destination(org.eclipse.jetty.client.api.Destination) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) FuturePromise(org.eclipse.jetty.util.FuturePromise) Connection(org.eclipse.jetty.client.api.Connection) Request(org.eclipse.jetty.client.api.Request) HttpDestinationOverHTTP(org.eclipse.jetty.client.http.HttpDestinationOverHTTP) FutureResponseListener(org.eclipse.jetty.client.util.FutureResponseListener) Test(org.junit.Test)

Example 40 with Request

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

the class HttpClientExplicitConnectionTest method testExplicitConnectionIsClosedOnRemoteClose.

@Test
public void testExplicitConnectionIsClosedOnRemoteClose() throws Exception {
    start(new EmptyServerHandler());
    Destination destination = client.getDestination(scheme, "localhost", connector.getLocalPort());
    FuturePromise<Connection> futureConnection = new FuturePromise<>();
    destination.newConnection(futureConnection);
    Connection connection = futureConnection.get(5, TimeUnit.SECONDS);
    Request request = client.newRequest(destination.getHost(), destination.getPort()).scheme(scheme);
    FutureResponseListener listener = new FutureResponseListener(request);
    connection.send(request, listener);
    ContentResponse response = listener.get(5, TimeUnit.SECONDS);
    Assert.assertEquals(200, response.getStatus());
    // Wait some time to have the client is an idle state.
    TimeUnit.SECONDS.sleep(1);
    connector.stop();
    // Give the connection some time to process the remote close.
    TimeUnit.SECONDS.sleep(1);
    HttpConnectionOverHTTP httpConnection = (HttpConnectionOverHTTP) connection;
    Assert.assertFalse(httpConnection.getEndPoint().isOpen());
    HttpDestinationOverHTTP httpDestination = (HttpDestinationOverHTTP) destination;
    DuplexConnectionPool connectionPool = (DuplexConnectionPool) httpDestination.getConnectionPool();
    Assert.assertTrue(connectionPool.getActiveConnections().isEmpty());
    Assert.assertTrue(connectionPool.getIdleConnections().isEmpty());
}
Also used : Destination(org.eclipse.jetty.client.api.Destination) ContentResponse(org.eclipse.jetty.client.api.ContentResponse) FuturePromise(org.eclipse.jetty.util.FuturePromise) Connection(org.eclipse.jetty.client.api.Connection) Request(org.eclipse.jetty.client.api.Request) HttpDestinationOverHTTP(org.eclipse.jetty.client.http.HttpDestinationOverHTTP) HttpConnectionOverHTTP(org.eclipse.jetty.client.http.HttpConnectionOverHTTP) FutureResponseListener(org.eclipse.jetty.client.util.FutureResponseListener) Test(org.junit.Test)

Aggregations

Request (org.eclipse.jetty.client.api.Request)259 Test (org.junit.Test)145 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)132 HttpServletRequest (javax.servlet.http.HttpServletRequest)123 IOException (java.io.IOException)71 HttpServletResponse (javax.servlet.http.HttpServletResponse)65 CountDownLatch (java.util.concurrent.CountDownLatch)58 HttpClient (org.eclipse.jetty.client.HttpClient)58 ServletException (javax.servlet.ServletException)55 Response (org.eclipse.jetty.client.api.Response)45 InputStream (java.io.InputStream)39 Result (org.eclipse.jetty.client.api.Result)38 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)35 URI (java.net.URI)34 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)30 ExecutionException (java.util.concurrent.ExecutionException)28 FutureResponseListener (org.eclipse.jetty.client.util.FutureResponseListener)28 ByteBuffer (java.nio.ByteBuffer)27 SalesforceException (org.apache.camel.component.salesforce.api.SalesforceException)26 Connection (org.eclipse.jetty.client.api.Connection)26