use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project databus by linkedin.
the class TestHttpResponseProcessor method testConnectFail.
@Test
public void testConnectFail() throws DatabusException {
Logger log = Logger.getLogger("GenericHttpResponseHandler.testConnectFail");
TestHttpResponseProcessor respProcessor = new TestHttpResponseProcessor(log);
TestConnectListener connectListener = new TestConnectListener(log);
TestSendRequestListener requestListener = new TestSendRequestListener(log);
TestCloseListener closeListener = new TestCloseListener(log);
//Need this call to set respProcessor without triggering erroneous check
final GenericHttpResponseHandler responseHandler = new GenericHttpResponseHandler(respProcessor, KeepAliveType.KEEP_ALIVE);
responseHandler.setRequestListener(requestListener);
responseHandler.setConnectionListener(connectListener);
responseHandler.setCloseListener(closeListener);
//use port 0 to generate connect fail
ChannelFuture channelFuture = createChannelFuture(responseHandler, 0);
Channel channel = channelFuture.getChannel();
try {
channel.write(new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/test"));
final List<String> respCallbacks = respProcessor.getCallbacks();
final List<String> connectCallbacks = connectListener.getCallbacks();
final List<String> requestCallbacks = requestListener.getCallbacks();
final List<String> closeChannelCallbacks = closeListener.getCallbacks();
TestUtil.assertWithBackoff(new ConditionCheck() {
@Override
public boolean check() {
return 1 == closeChannelCallbacks.size();
}
}, "waiting for close channel callback", 1000, null);
//make sure that no new callbacks have showed up
stateSanityCheck(connectCallbacks, requestCallbacks, respCallbacks, closeChannelCallbacks);
Assert.assertEquals(connectCallbacks.size(), 1);
Assert.assertEquals(connectCallbacks.get(0), "onConnectFailure");
Assert.assertEquals(closeChannelCallbacks.size(), 1);
Assert.assertEquals(closeChannelCallbacks.get(0), "onChannelClose");
} finally {
channel.close();
}
}
use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project graylog2-server by Graylog2.
the class HttpTransportHandlerTest method messageReceivedReturns404ForWrongPath.
@Test
public void messageReceivedReturns404ForWrongPath() throws Exception {
final HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
httpRequest.headers().add("Host", "localhost");
httpRequest.headers().add("Origin", "http://example.com");
httpRequest.headers().add("Connection", "close");
channel.offer(httpRequest);
channel.finish();
final HttpResponse httpResponse = channel.poll();
assertThat(httpResponse.getStatus()).isEqualTo(HttpResponseStatus.NOT_FOUND);
final HttpHeaders headers = httpResponse.headers();
assertThat(headers.get(HttpHeaders.Names.CONTENT_LENGTH)).isEqualTo("0");
assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("http://example.com");
assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_CREDENTIALS)).isEqualTo("true");
assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_HEADERS)).isEqualTo("Authorization, Content-Type");
}
use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project graylog2-server by Graylog2.
the class HttpTransportHandlerTest method messageReceivedReturns405ForInvalidMethod.
@Test
public void messageReceivedReturns405ForInvalidMethod() throws Exception {
final HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
httpRequest.headers().add("Host", "localhost");
httpRequest.headers().add("Origin", "http://example.com");
httpRequest.headers().add("Connection", "close");
channel.offer(httpRequest);
channel.finish();
final HttpResponse httpResponse = channel.poll();
assertThat(httpResponse.getStatus()).isEqualTo(HttpResponseStatus.METHOD_NOT_ALLOWED);
final HttpHeaders headers = httpResponse.headers();
assertThat(headers.get(HttpHeaders.Names.CONTENT_LENGTH)).isEqualTo("0");
assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("http://example.com");
assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_CREDENTIALS)).isEqualTo("true");
assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_HEADERS)).isEqualTo("Authorization, Content-Type");
}
use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project graylog2-server by Graylog2.
the class HttpTransportHandlerTest method messageReceivedSuccessfullyProcessesOPTIONSRequest.
@Test
public void messageReceivedSuccessfullyProcessesOPTIONSRequest() throws Exception {
final HttpRequest httpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.OPTIONS, "/gelf");
httpRequest.headers().add("Host", "localhost");
httpRequest.headers().add("Origin", "http://example.com");
httpRequest.headers().add("Connection", "close");
channel.offer(httpRequest);
channel.finish();
final HttpResponse httpResponse = channel.poll();
assertThat(httpResponse.getStatus()).isEqualTo(HttpResponseStatus.OK);
final HttpHeaders headers = httpResponse.headers();
assertThat(headers.get(HttpHeaders.Names.CONTENT_LENGTH)).isEqualTo("0");
assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN)).isEqualTo("http://example.com");
assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_CREDENTIALS)).isEqualTo("true");
assertThat(headers.get(HttpHeaders.Names.ACCESS_CONTROL_ALLOW_HEADERS)).isEqualTo("Authorization, Content-Type");
}
use of org.jboss.netty.handler.codec.http.DefaultHttpRequest in project opentsdb by OpenTSDB.
the class TestHttpQuery method getContentDefault.
@Test
public void getContentDefault() {
final Channel channelMock = NettyMocks.fakeChannel();
final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
final ChannelBuffer buf = ChannelBuffers.copiedBuffer("Sí Señor", CharsetUtil.UTF_8);
req.setContent(buf);
final HttpQuery query = new HttpQuery(tsdb, req, channelMock);
assertEquals("Sí Señor", query.getContent());
}
Aggregations