use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpReceiverOverHTTPTest method test_Receive_NoResponseContent.
@Test
public void test_Receive_NoResponseContent() throws Exception {
endPoint.addInput("" + "HTTP/1.1 200 OK\r\n" + "Content-length: 0\r\n" + "\r\n");
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("0", headers.get(HttpHeader.CONTENT_LENGTH));
}
use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpReceiverOverHTTPTest method test_FillInterested_RacingWith_BufferRelease.
@Test
public void test_FillInterested_RacingWith_BufferRelease() throws Exception {
connection = new HttpConnectionOverHTTP(endPoint, destination, new Promise.Adapter<>()) {
@Override
protected HttpChannelOverHTTP newHttpChannel() {
return new HttpChannelOverHTTP(this) {
@Override
protected HttpReceiverOverHTTP newHttpReceiver() {
return new HttpReceiverOverHTTP(this) {
@Override
protected void fillInterested() {
// Verify that the buffer has been released
// before fillInterested() is called.
Assert.assertNull(getResponseBuffer());
// Fill the endpoint so receive is called again.
endPoint.addInput("X");
super.fillInterested();
}
};
}
};
}
};
endPoint.setConnection(connection);
// Partial response to trigger the call to fillInterested().
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();
Response response = listener.get(5, TimeUnit.SECONDS);
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
}
use of org.eclipse.jetty.client.HttpExchange in project jetty.project by eclipse.
the class HttpReceiverOverHTTPTest method test_Receive_BadResponse.
@Test
public void test_Receive_BadResponse() throws Exception {
endPoint.addInput("" + "HTTP/1.1 200 OK\r\n" + "Content-length: A\r\n" + "\r\n");
HttpExchange exchange = newExchange();
FutureResponseListener listener = (FutureResponseListener) exchange.getResponseListeners().get(0);
connection.getHttpChannel().receive();
try {
listener.get(5, TimeUnit.SECONDS);
Assert.fail();
} catch (ExecutionException e) {
Assert.assertTrue(e.getCause() instanceof HttpResponseException);
}
}
use of org.eclipse.jetty.client.HttpExchange in project openhab1-addons by openhab.
the class FritzahaWebInterface method asyncGet.
/**
* Sends an HTTP GET request using the asynchronous client
*
* @param Path
* Path of the requested resource
* @param Args
* Arguments for the request
* @param Callback
* Callback to handle the response with
*/
public HttpExchange asyncGet(String path, String args, FritzahaCallback callback) {
if (!isAuthenticated()) {
authenticate();
}
HttpExchange getExchange = new FritzahaContentExchange(callback);
getExchange.setMethod("GET");
getExchange.setURL(getURL(path, addSID(args)));
try {
asyncclient.send(getExchange);
} catch (IOException e) {
logger.error("An I/O error occurred while sending the GET request " + getURL(path, addSID(args)));
return null;
}
logger.debug("GETting URL " + getURL(path, addSID(args)));
return getExchange;
}
Aggregations