Search in sources :

Example 36 with HttpRequest

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

the class HttpRequestLoggingHandler method messageReceived.

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
    if (e.getMessage() instanceof HttpRequest) {
        // HttpRequest is for a relay from client/bootstrap, hence it is an inbound request
        // ( outbound = false )
        HttpRequest req = (HttpRequest) e.getMessage();
        startHttpRequest(false, req);
    } else if (e.getMessage() instanceof HttpResponse) {
        // HttpResponse is from a relay to a client/bootstrap, hence it is an outbound request
        // ( outbound = true )
        HttpResponse resp = (HttpResponse) e.getMessage();
        startHttpResponse(true, resp);
    } else if (e.getMessage() instanceof HttpChunk) {
        HttpChunk chunk = (HttpChunk) e.getMessage();
        processHttpChunk(true, chunk);
        if (State.OUTBOUND_RESPONSE_END == _state) {
            endHttpResponse(true);
        }
    }
    super.messageReceived(ctx, e);
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) HttpChunk(org.jboss.netty.handler.codec.http.HttpChunk)

Example 37 with HttpRequest

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

the class BootstrapStartScnHttpResponseProcessor method onTargetScnConnectSuccess.

void onTargetScnConnectSuccess() {
    _curState = State.TARGET_SCN_REQUEST_WRITE;
    ChannelPipeline channelPipeline = _channel.getPipeline();
    _readTimeOutHandler = (ExtendedReadTimeoutHandler) channelPipeline.get(GenericHttpClientPipelineFactory.READ_TIMEOUT_HANDLER_NAME);
    _readTimeOutHandler.start(channelPipeline.getContext(_readTimeOutHandler));
    BootstrapTargetScnHttpResponseProcessor targetResponseProcessor = new BootstrapTargetScnHttpResponseProcessor(this, _callback, _callbackStateReuse, _checkpoint, _remoteExceptionHandler, _readTimeOutHandler);
    final String url = createTargetScnRequestUrl();
    LOG.info("Sending " + url);
    // Prepare the HTTP request.
    HttpRequest request = createEmptyRequest(url);
    sendRequest(request, new TargetScnRequestResultListener(), targetResponseProcessor);
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 38 with HttpRequest

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

the class StreamHttpResponseProcessor method onStreamConnectSuccess.

void onStreamConnectSuccess() {
    boolean debugEnabled = LOG.isDebugEnabled();
    _curState = State.STREAM_REQUEST_WRITE;
    ChannelPipeline channelPipeline = _channel.getPipeline();
    _readTimeOutHandler = (ExtendedReadTimeoutHandler) channelPipeline.get(GenericHttpClientPipelineFactory.READ_TIMEOUT_HANDLER_NAME);
    _readTimeOutHandler.start(channelPipeline.getContext(_readTimeOutHandler));
    StreamHttpResponseProcessor streamResponseProcessor = new StreamHttpResponseProcessor(this, _callback, _callbackStateReuse, _readTimeOutHandler);
    StringBuilder uriString = new StringBuilder(1024);
    boolean error = populateStreamRequestUrl(uriString);
    if (error) {
        return;
    }
    final String url = uriString.toString();
    if (debugEnabled)
        LOG.debug("Sending " + url);
    // Prepare the HTTP request.
    HttpRequest request = createEmptyRequest(url);
    sendRequest(request, new StreamRequestResultListener(), streamResponseProcessor);
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 39 with HttpRequest

use of org.jboss.netty.handler.codec.http.HttpRequest in project voldemort by voldemort.

the class AbstractRestRequestHandler method messageReceived.

@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent messageEvent) throws Exception {
    RestRequestValidator requestValidator;
    if (!readingChunks) {
        // Construct the Request from messageEvent
        HttpRequest request = this.request = (HttpRequest) messageEvent.getMessage();
        String requestURI = this.request.getUri();
        if (logger.isDebugEnabled()) {
            logger.debug("Request URI: " + requestURI);
        }
        if (request.isChunked()) {
            readingChunks = true;
        } else {
            // Instantiate the appropriate error handler
            HttpMethod httpMethod = request.getMethod();
            if (httpMethod.equals(HttpMethod.GET)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Received a Http GET request at " + System.currentTimeMillis() + " ms");
                }
                requestValidator = new RestGetRequestValidator(request, messageEvent);
            } else if (httpMethod.equals(HttpMethod.POST)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Received a Http POST request at " + System.currentTimeMillis() + " ms");
                }
                requestValidator = new RestPutRequestValidator(request, messageEvent, this.isVectorClockOptional);
            } else if (httpMethod.equals(HttpMethod.DELETE)) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Received a Http DELETE request at " + System.currentTimeMillis() + " ms");
                }
                requestValidator = new RestDeleteRequestValidator(request, messageEvent, this.isVectorClockOptional);
            } else {
                String errorMessage = "Illegal Http request received at " + System.currentTimeMillis() + " ms";
                logger.error(errorMessage);
                RestErrorHandler.writeErrorResponse(messageEvent, BAD_REQUEST, errorMessage);
                return;
            }
            registerRequest(requestValidator, ctx, messageEvent);
        }
    } else {
        HttpChunk chunk = (HttpChunk) messageEvent.getMessage();
        if (chunk.isLast()) {
            readingChunks = false;
        }
    }
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) HttpMethod(org.jboss.netty.handler.codec.http.HttpMethod) HttpChunk(org.jboss.netty.handler.codec.http.HttpChunk)

Example 40 with HttpRequest

use of org.jboss.netty.handler.codec.http.HttpRequest in project opentsdb by OpenTSDB.

the class TestHttpQuery method getContentBadEncoding.

@Test
public void getContentBadEncoding() {
    final Channel channelMock = NettyMocks.fakeChannel();
    final HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
    final ChannelBuffer buf = ChannelBuffers.copiedBuffer("S\u00ED Se\u00F1or", CharsetUtil.ISO_8859_1);
    req.setContent(buf);
    final HttpQuery query = new HttpQuery(tsdb, req, channelMock);
    assertThat("S\u00ED Se\u00F1or", not(equalTo(query.getContent())));
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) DefaultHttpRequest(org.jboss.netty.handler.codec.http.DefaultHttpRequest) Channel(org.jboss.netty.channel.Channel) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)136 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)69 Channel (org.jboss.netty.channel.Channel)47 Test (org.junit.Test)47 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)46 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)43 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)31 ChannelFuture (org.jboss.netty.channel.ChannelFuture)26 List (java.util.List)19 ArrayList (java.util.ArrayList)17 Map (java.util.Map)17 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)17 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)17 InetSocketAddress (java.net.InetSocketAddress)14 ChannelHandlerContext (org.jboss.netty.channel.ChannelHandlerContext)13 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)13 SimpleHttpResponseHandler (com.linkedin.databus.core.test.netty.SimpleHttpResponseHandler)12 SimpleTestHttpClient (com.linkedin.databus.core.test.netty.SimpleTestHttpClient)12 Configuration (org.apache.hadoop.conf.Configuration)12 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)12