Search in sources :

Example 36 with HttpChunkTrailer

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

the class TestResponseProcessors method testTargetSCNExceptionAfterStartCase3.

@Test
public void testTargetSCNExceptionAfterStartCase3() throws Exception {
    TestAbstractQueue queue = new TestAbstractQueue();
    TestConnectionStateMessage stateMsg = new TestConnectionStateMessage();
    HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    TestRemoteExceptionHandler remoteExHandler = new TestRemoteExceptionHandler();
    Checkpoint cp = new Checkpoint();
    cp.setConsumptionMode(DbusClientMode.BOOTSTRAP_CATCHUP);
    BootstrapTargetScnHttpResponseProcessor processor = new BootstrapTargetScnHttpResponseProcessor(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.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.TARGETSCN_RESPONSE_ERROR, gotMsg._state);
    Assert.assertEquals("No response", true, (null == stateMsg._cp));
}
Also used : 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) Checkpoint(com.linkedin.databus.core.Checkpoint) 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 37 with HttpChunkTrailer

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

the class TestResponseProcessors method testRegisterExceptionAfterStartCase2.

@Test
public void testRegisterExceptionAfterStartCase2() throws Exception {
    TestAbstractQueue queue = new TestAbstractQueue();
    TestConnectionStateMessage stateMsg = new TestConnectionStateMessage();
    HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    RegisterHttpResponseProcessor processor = new RegisterHttpResponseProcessor(null, queue, stateMsg, null);
    ChannelBuffer buf = getRegisterResponse();
    HttpChunk httpChunk = new DefaultHttpChunk(buf);
    HttpChunkTrailer httpChunkTrailer = new DefaultHttpChunkTrailer();
    processor.startResponse(httpResponse);
    processor.addChunk(httpChunk);
    processor.channelException(new Exception("dummy exception"));
    processor.addTrailer(httpChunkTrailer);
    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.REGISTER_RESPONSE_ERROR, gotMsg._state);
    Assert.assertEquals("No More CHunks", true, (null == stateMsg._registerResponse));
}
Also used : 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) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) DefaultHttpChunkTrailer(org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer) BootstrapDatabaseTooOldException(com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException) 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)

Example 38 with HttpChunkTrailer

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

the class HttpRequestHandler method messageReceived.

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    /*NettyStats nettyStats = _configManager.getNettyStats();
      CallCompletion callCompletion = nettyStats.isEnabled() ?
          nettyStats.getRequestHandler_messageRecieved().startCall() :
          null;*/
    try {
        if (!readingChunks) {
            request = (HttpRequest) e.getMessage();
            ctx.sendUpstream(e);
            QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri());
            String queryPath = queryStringDecoder.getPath();
            int slashPos = queryPath.indexOf('/', 1);
            if (slashPos < 0) {
                slashPos = queryPath.length();
            }
            String cmdName = queryPath.substring(1, slashPos);
            ServerContainer.RuntimeConfig config = _serverContainer.getContainerRuntimeConfigMgr().getReadOnlyConfig();
            if (LOG.isDebugEnabled()) {
                LOG.debug("Got command: " + cmdName);
            }
            dbusRequest = new DatabusRequest(cmdName, request.getMethod(), e.getRemoteAddress(), config);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Starting processing command [" + dbusRequest.getId() + "] " + dbusRequest.getName());
            }
            Properties requestProps = dbusRequest.getParams();
            if (slashPos < queryPath.length()) {
                requestProps.put(DatabusRequest.PATH_PARAM_NAME, queryPath.substring(slashPos + 1));
            }
            for (Map.Entry<String, String> h : request.getHeaders()) {
                handleHttpHeader(h);
            }
            Map<String, List<String>> params = queryStringDecoder.getParameters();
            if (!params.isEmpty()) {
                for (Entry<String, List<String>> p : params.entrySet()) {
                    String key = p.getKey();
                    List<String> vals = p.getValue();
                    if (vals.size() == 1) {
                        requestProps.put(key, vals.get(0));
                    } else {
                        requestProps.put(key, vals);
                    }
                    for (String val : vals) {
                        LOG.trace("PARAM: " + key + " = " + val);
                    }
                }
            }
            if (request.isChunked()) {
                if (null != _readTimeoutHandler) {
                    readingChunks = true;
                    _readTimeoutHandler.start(ctx.getPipeline().getContext(_readTimeoutHandler));
                }
            } else {
                ChannelBuffer content = request.getContent();
                handleRequestContentChunk(content);
                writeResponse(ctx, e);
            }
        } else if (e.getMessage() instanceof HttpChunk) {
            HttpChunk chunk = (HttpChunk) e.getMessage();
            if (chunk.isLast()) {
                readingChunks = false;
                LOG.trace("END OF CONTENT");
                HttpChunkTrailer trailer = (HttpChunkTrailer) chunk;
                for (Map.Entry<String, String> h : trailer.getHeaders()) {
                    handleHttpHeader(h);
                }
                writeResponse(ctx, e);
            } else {
                ChannelBuffer content = chunk.getContent();
                handleRequestContentChunk(content);
            }
        }
        ctx.sendUpstream(e);
    // FIXME   DDS-305: Rework the netty stats collector to use event-based stats aggregation
    /*if (null != callCompletion)
        {
          callCompletion.endCall();
        }*/
    } catch (Exception ex) {
        LOG.error("HttpRequestHandler.messageReceived error", ex);
    // FIXME   DDS-305: Rework the netty stats collector to use event-based stats aggregation
    /*if (null != callCompletion)
        {
          callCompletion.endCallWithError(ex);
        }*/
    }
}
Also used : Properties(java.util.Properties) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) QueryStringDecoder(org.jboss.netty.handler.codec.http.QueryStringDecoder) DatabusRequest(com.linkedin.databus2.core.container.request.DatabusRequest) Entry(java.util.Map.Entry) HttpChunkTrailer(org.jboss.netty.handler.codec.http.HttpChunkTrailer) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) HttpChunk(org.jboss.netty.handler.codec.http.HttpChunk)

Aggregations

HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)38 HttpChunkTrailer (org.jboss.netty.handler.codec.http.HttpChunkTrailer)38 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)37 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)35 DefaultHttpChunkTrailer (org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer)34 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)34 Test (org.testng.annotations.Test)34 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)28 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)25 Checkpoint (com.linkedin.databus.core.Checkpoint)16 DatabusRelayConnectionStateMessage (com.linkedin.databus.client.DatabusRelayConnectionStateMessage)6 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 DatabusRequest (com.linkedin.databus2.core.container.request.DatabusRequest)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ClosedChannelException (java.nio.channels.ClosedChannelException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1