Search in sources :

Example 66 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 67 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 68 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 69 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 70 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)223 Test (org.junit.Test)137 HttpServletRequest (javax.servlet.http.HttpServletRequest)121 ContentResponse (org.eclipse.jetty.client.api.ContentResponse)118 HttpServletResponse (javax.servlet.http.HttpServletResponse)63 IOException (java.io.IOException)62 CountDownLatch (java.util.concurrent.CountDownLatch)58 ServletException (javax.servlet.ServletException)53 HttpClient (org.eclipse.jetty.client.HttpClient)48 Response (org.eclipse.jetty.client.api.Response)37 Result (org.eclipse.jetty.client.api.Result)37 InputStream (java.io.InputStream)36 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)35 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)30 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 BytesContentProvider (org.eclipse.jetty.client.util.BytesContentProvider)25 URI (java.net.URI)24