use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpReceiverOverHTTPTest method newExchange.
protected HttpExchange newExchange() {
HttpRequest request = (HttpRequest) client.newRequest("http://localhost");
FutureResponseListener listener = new FutureResponseListener(request);
HttpExchange exchange = new HttpExchange(destination, request, Collections.<Response.ResponseListener>singletonList(listener));
boolean associated = connection.getHttpChannel().associate(exchange);
Assert.assertTrue(associated);
exchange.requestComplete(null);
exchange.terminateRequest();
return exchange;
}
use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpReceiverOverHTTPTest method test_Receive_ResponseContent_EarlyEOF.
@Test
public void test_Receive_ResponseContent_EarlyEOF() throws Exception {
String content1 = "0123456789";
String content2 = "ABCDEF";
endPoint.addInput("" + "HTTP/1.1 200 OK\r\n" + "Content-length: " + (content1.length() + content2.length()) + "\r\n" + "\r\n" + content1);
HttpExchange exchange = newExchange();
FutureResponseListener listener = (FutureResponseListener) exchange.getResponseListeners().get(0);
connection.getHttpChannel().receive();
endPoint.addInputEOF();
connection.getHttpChannel().receive();
try {
listener.get(5, TimeUnit.SECONDS);
Assert.fail();
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof EOFException);
}
}
use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpReceiverOverHTTPTest method test_Receive_ResponseContent.
@Test
public void test_Receive_ResponseContent() throws Exception {
String content = "0123456789ABCDEF";
endPoint.addInput("" + "HTTP/1.1 200 OK\r\n" + "Content-length: " + content.length() + "\r\n" + "\r\n" + content);
HttpExchange exchange = newExchange();
FutureResponseListener listener = (FutureResponseListener) exchange.getResponseListeners().get(0);
connection.getHttpChannel().receive();
Response response = listener.get(5, TimeUnit.SECONDS);
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals("OK", response.getReason());
Assert.assertSame(HttpVersion.HTTP_1_1, response.getVersion());
HttpFields headers = response.getHeaders();
Assert.assertNotNull(headers);
Assert.assertEquals(1, headers.size());
Assert.assertEquals(String.valueOf(content.length()), headers.get(HttpHeader.CONTENT_LENGTH));
String received = listener.getContentAsString(StandardCharsets.UTF_8);
Assert.assertEquals(content, received);
}
use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpReceiverOverHTTPTest method test_Receive_ResponseContent_IdleTimeout.
@Test
public void test_Receive_ResponseContent_IdleTimeout() throws Exception {
endPoint.addInput("" + "HTTP/1.1 200 OK\r\n" + "Content-length: 1\r\n" + "\r\n");
HttpExchange exchange = newExchange();
FutureResponseListener listener = (FutureResponseListener) exchange.getResponseListeners().get(0);
connection.getHttpChannel().receive();
// ByteArrayEndPoint has an idle timeout of 0 by default,
// so to simulate an idle timeout is enough to wait a bit.
Thread.sleep(100);
connection.onIdleExpired();
try {
listener.get(5, TimeUnit.SECONDS);
Assert.fail();
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof TimeoutException);
}
}
use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpChannelOverFCGI method send.
@Override
public void send() {
HttpExchange exchange = getHttpExchange();
if (exchange != null) {
version = exchange.getRequest().getVersion();
idle.onOpen();
sender.send(exchange);
}
}
Aggregations