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;
}
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);
}
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());
}
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());
}
}
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());
}
Aggregations