Search in sources :

Example 16 with DefaultHttpResponse

use of org.jboss.netty.handler.codec.http.DefaultHttpResponse in project databus by linkedin.

the class DatabusRequestExecutionHandler method generateEmptyResponse.

private HttpResponse generateEmptyResponse() {
    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
    // response.setContent(ChannelBuffers.wrappedBuffer(responseBody));
    response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
    response.setHeader("Access-Control-Allow-Origin", "*");
    setTrackingInfo(response);
    // Encode the cookie.
    String cookieString = _httpRequest.getHeader(COOKIE);
    if (cookieString != null) {
        CookieDecoder cookieDecoder = new CookieDecoder();
        Set<Cookie> cookies = cookieDecoder.decode(cookieString);
        if (!cookies.isEmpty()) {
            // Reset the cookies if necessary.
            CookieEncoder cookieEncoder = new CookieEncoder(true);
            for (Cookie cookie : cookies) {
                cookieEncoder.addCookie(cookie);
            }
            response.addHeader(SET_COOKIE, cookieEncoder.encode());
        }
    }
    return response;
}
Also used : Cookie(org.jboss.netty.handler.codec.http.Cookie) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) CookieEncoder(org.jboss.netty.handler.codec.http.CookieEncoder) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) CookieDecoder(org.jboss.netty.handler.codec.http.CookieDecoder)

Example 17 with DefaultHttpResponse

use of org.jboss.netty.handler.codec.http.DefaultHttpResponse in project databus by linkedin.

the class DummyHttpRequestHandler method messageReceived.

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    // HttpRequest request = (HttpRequest) e.getMessage();
    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
    response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
    ChunkedBodyWritableByteChannel writeChannel = new ChunkedBodyWritableByteChannel(e.getChannel(), response);
    for (String key : _headers.keySet()) {
        writeChannel.setMetadata(key, _headers.get(key));
    }
    for (byte[] chunk : _responseChunks) {
        writeChannel.write(ByteBuffer.wrap(chunk));
    }
    writeChannel.setResponseCode(_responseCode);
    for (String key : _footers.keySet()) {
        writeChannel.setMetadata(key, _footers.get(key));
    }
    writeChannel.close();
}
Also used : DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) ChunkedBodyWritableByteChannel(com.linkedin.databus2.core.container.netty.ChunkedBodyWritableByteChannel) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse)

Example 18 with DefaultHttpResponse

use of org.jboss.netty.handler.codec.http.DefaultHttpResponse in project databus by linkedin.

the class TestResponseProcessors method testSourceExceptionAfterStartCase3.

@Test
public void testSourceExceptionAfterStartCase3() throws Exception {
    TestAbstractQueue queue = new TestAbstractQueue();
    TestConnectionStateMessage stateMsg = new TestConnectionStateMessage();
    HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    SourcesHttpResponseProcessor<DatabusRelayConnectionStateMessage> processor = new SourcesHttpResponseProcessor<DatabusRelayConnectionStateMessage>(null, queue, stateMsg, null);
    ChannelBuffer buf = getSourcesResponse();
    HttpChunk httpChunk = new DefaultHttpChunk(buf);
    HttpChunkTrailer httpChunkTrailer = new DefaultHttpChunkTrailer();
    processor.startResponse(httpResponse);
    processor.addChunk(httpChunk);
    processor.addTrailer(httpChunkTrailer);
    processor.channelException(new Exception("dummy exception"));
    processor.finishResponse();
    Assert.assertEquals("Error Handled", true, processor._errorHandled);
    Assert.assertEquals("Processor Response State", AbstractHttpResponseProcessorDecorator.ResponseStatus.CHUNKS_FINISHED, processor._responseStatus);
    Assert.assertEquals("Actor Queue Size", 1, queue.getMessages().size());
    Assert.assertEquals("Expected ConnectionStateMessage", "TestConnectionStateMessage", queue.getMessages().get(0).getClass().getSimpleName());
    TestConnectionStateMessage gotMsg = (TestConnectionStateMessage) (queue.getMessages().get(0));
    Assert.assertEquals("Expected ConnectionStateMessage State", TestConnectionStateMessage.State.SOURCES_RESPONSE_ERROR, gotMsg._state);
    Assert.assertEquals("No More CHunks", true, (null == stateMsg._sourcesResponse));
}
Also used : DatabusRelayConnectionStateMessage(com.linkedin.databus.client.DatabusRelayConnectionStateMessage) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) HttpChunkTrailer(org.jboss.netty.handler.codec.http.HttpChunkTrailer) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) HttpChunk(org.jboss.netty.handler.codec.http.HttpChunk) Test(org.testng.annotations.Test)

Example 19 with DefaultHttpResponse

use of org.jboss.netty.handler.codec.http.DefaultHttpResponse in project databus by linkedin.

the class TestResponseProcessors method testSourceExceptionAfterFinishResponse.

@Test
public void testSourceExceptionAfterFinishResponse() throws Exception {
    TestAbstractQueue queue = new TestAbstractQueue();
    TestConnectionStateMessage stateMsg = new TestConnectionStateMessage();
    HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    SourcesHttpResponseProcessor<DatabusRelayConnectionStateMessage> processor = new SourcesHttpResponseProcessor<DatabusRelayConnectionStateMessage>(null, queue, stateMsg, null);
    ChannelBuffer buf = getSourcesResponse();
    HttpChunk httpChunk = new DefaultHttpChunk(buf);
    HttpChunkTrailer httpChunkTrailer = new DefaultHttpChunkTrailer();
    processor.startResponse(httpResponse);
    processor.addChunk(httpChunk);
    processor.addTrailer(httpChunkTrailer);
    processor.finishResponse();
    processor.channelException(new Exception("dummy exception"));
    Assert.assertEquals("Error Handled", true, processor._errorHandled);
    Assert.assertEquals("Processor Response State", AbstractHttpResponseProcessorDecorator.ResponseStatus.CHUNKS_EXCEPTION, processor._responseStatus);
    Assert.assertEquals("Actor Queue Size", 1, queue.getMessages().size());
    Assert.assertEquals("Expected ConnectionStateMessage", "TestConnectionStateMessage", queue.getMessages().get(0).getClass().getSimpleName());
    TestConnectionStateMessage gotMsg = (TestConnectionStateMessage) (queue.getMessages().get(0));
    Assert.assertEquals("Expected ConnectionStateMessage State", TestConnectionStateMessage.State.SOURCES_SUCCESS, gotMsg._state);
    Assert.assertEquals("Register Response Id Check", 1, stateMsg._sourcesResponse.size());
    Assert.assertEquals("Register Response Id Check", new Long(301), stateMsg._sourcesResponse.get(0).getId());
}
Also used : DatabusRelayConnectionStateMessage(com.linkedin.databus.client.DatabusRelayConnectionStateMessage) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) HttpChunkTrailer(org.jboss.netty.handler.codec.http.HttpChunkTrailer) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) HttpChunk(org.jboss.netty.handler.codec.http.HttpChunk) Test(org.testng.annotations.Test)

Example 20 with DefaultHttpResponse

use of org.jboss.netty.handler.codec.http.DefaultHttpResponse in project databus by linkedin.

the class TestResponseProcessors method testStartSCNOtherException.

@Test
public void testStartSCNOtherException() throws Exception {
    TestAbstractQueue queue = new TestAbstractQueue();
    TestConnectionStateMessage stateMsg = new TestConnectionStateMessage();
    DefaultHttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    httpResponse.setHeader(DatabusHttpHeaders.DATABUS_ERROR_CAUSE_CLASS_HEADER, "Other Dummy Error");
    TestRemoteExceptionHandler remoteExHandler = new TestRemoteExceptionHandler();
    remoteExHandler._exType = ExceptionType.OTHER_EXCEPTION;
    Checkpoint cp = new Checkpoint();
    cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_SNAPSHOT);
    BootstrapStartScnHttpResponseProcessor processor = new BootstrapStartScnHttpResponseProcessor(null, queue, stateMsg, cp, remoteExHandler, null);
    ChannelBuffer buf = getScnResponse();
    HttpChunk httpChunk = new DefaultHttpChunk(buf);
    HttpChunkTrailer httpChunkTrailer = new DefaultHttpChunkTrailer();
    processor.startResponse(httpResponse);
    processor.addChunk(httpChunk);
    processor.addTrailer(httpChunkTrailer);
    processor.finishResponse();
    Assert.assertEquals("Error Handled", false, processor._errorHandled);
    Assert.assertEquals("Processor Response State", AbstractHttpResponseProcessorDecorator.ResponseStatus.CHUNKS_FINISHED, processor._responseStatus);
    Assert.assertEquals("Actor Queue Size", 1, queue.getMessages().size());
    Assert.assertEquals("Expected ConnectionStateMessage", "TestConnectionStateMessage", queue.getMessages().get(0).getClass().getSimpleName());
    TestConnectionStateMessage gotMsg = (TestConnectionStateMessage) (queue.getMessages().get(0));
    Assert.assertEquals("Expected ConnectionStateMessage State", TestConnectionStateMessage.State.STARTSCN_RESPONSE_ERROR, gotMsg._state);
    Assert.assertEquals("No response", true, (null == stateMsg._cp));
}
Also used : Checkpoint(com.linkedin.databus.core.Checkpoint) DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) HttpChunkTrailer(org.jboss.netty.handler.codec.http.HttpChunkTrailer) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) DefaultHttpChunk(org.jboss.netty.handler.codec.http.DefaultHttpChunk) HttpChunk(org.jboss.netty.handler.codec.http.HttpChunk) Test(org.testng.annotations.Test)

Aggregations

DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)146 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)113 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)67 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)58 Test (org.testng.annotations.Test)54 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)51 DefaultHttpChunkTrailer (org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer)38 HttpChunkTrailer (org.jboss.netty.handler.codec.http.HttpChunkTrailer)34 ChannelFuture (org.jboss.netty.channel.ChannelFuture)33 Test (org.junit.Test)32 Checkpoint (com.linkedin.databus.core.Checkpoint)25 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)25 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)23 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)23 Channel (org.jboss.netty.channel.Channel)21 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)18 InetSocketAddress (java.net.InetSocketAddress)17 SocketAddress (java.net.SocketAddress)17 Logger (org.apache.log4j.Logger)15 SucceededChannelFuture (org.jboss.netty.channel.SucceededChannelFuture)10