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