Example usage for io.netty.handler.codec.http DefaultHttpRequest getUri

List of usage examples for io.netty.handler.codec.http DefaultHttpRequest getUri

Introduction

In this page you can find the example usage for io.netty.handler.codec.http DefaultHttpRequest getUri.

Prototype

@Override
    @Deprecated
    public String getUri() 

Source Link

Usage

From source file:com.difference.historybook.proxy.littleproxy.LittleProxyRequestTest.java

License:Apache License

@Test
public void testGetUri() {
    String url = "http://does.not.exist/file";
    DefaultHttpRequest request = mock(DefaultHttpRequest.class);
    when(request.getUri()).thenReturn(url);

    LittleProxyRequest lpr = new LittleProxyRequest(request);
    assertEquals(url, lpr.getUri());/*  w w w.j a va2 s .co  m*/
}

From source file:io.liveoak.container.analytics.AnalyticsBandwidthHandler.java

License:Open Source License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof ByteBuf) {
        bytesRead += ((ByteBuf) msg).readableBytes();
        startTime = startTime != 0 ? startTime : System.currentTimeMillis();

    } else if (msg instanceof DefaultHttpRequest) {
        DefaultHttpRequest req = (DefaultHttpRequest) msg;
        event = new AnalyticsEvent();

        startTime = startTime != 0 ? startTime : System.currentTimeMillis();
        event.setTimestamp(startTime);//from   w  w  w.j  a  va  2s.  c  o  m
        event.setMethod(req.getMethod().name());
        event.setUri(req.getUri());
        event.clientAddress(ctx.channel().remoteAddress());
        //event.uri(req.resourcePath().toString());
    } else if (msg instanceof ResourceRequest) {
        ResourceRequest req = (ResourceRequest) msg;
        event.setApplication(req.resourcePath().head().toString());
        event.setUserId(req.requestContext().securityContext().getSubject());
        event.setApiRequest(true);
    }
    super.channelRead(ctx, msg);
}

From source file:io.liveoak.container.protocols.http.HttpResourceRequestDecoder.java

License:Open Source License

@Override
protected void decode(ChannelHandlerContext ctx, DefaultHttpRequest msg, List<Object> out) throws Exception {

    URI uri = new URI(msg.getUri());
    String query = uri.getRawQuery();
    if (query == null) {
        query = "?";
    } else {//from   w w w .  ja  v a  2  s. c  o m
        query = "?" + query;
    }

    QueryStringDecoder decoder = new QueryStringDecoder(query);

    String path = uri.getPath();

    int lastDotLoc = path.lastIndexOf('.');

    String extension = null;

    if (lastDotLoc > 0) {
        extension = path.substring(lastDotLoc + 1);
    }

    String acceptHeader = msg.headers().get(HttpHeaders.Names.ACCEPT);
    if (acceptHeader == null) {
        acceptHeader = "application/json";
    }
    MediaTypeMatcher mediaTypeMatcher = new DefaultMediaTypeMatcher(acceptHeader, extension);

    ResourceParams params = DefaultResourceParams.instance(decoder.parameters());

    // for cases when content is preset, and bypasses HttpRequestBodyHandler
    ByteBuf content = null;
    if (msg instanceof DefaultFullHttpRequest) {
        content = ((DefaultFullHttpRequest) msg).content().retain();
    }

    if (msg.getMethod().equals(HttpMethod.POST)) {
        String contentTypeHeader = msg.headers().get(HttpHeaders.Names.CONTENT_TYPE);
        MediaType contentType = new MediaType(contentTypeHeader);
        out.add(new DefaultResourceRequest.Builder(RequestType.CREATE, new ResourcePath(path))
                .resourceParams(params).mediaTypeMatcher(mediaTypeMatcher)
                .requestAttribute(HttpHeaders.Names.AUTHORIZATION,
                        msg.headers().get(HttpHeaders.Names.AUTHORIZATION))
                .requestAttribute(HttpHeaders.Names.CONTENT_TYPE, contentType)
                .requestAttribute(HTTP_REQUEST, msg)
                .resourceState(new DefaultLazyResourceState(codecManager, contentType, content)).build());
    } else if (msg.getMethod().equals(HttpMethod.GET)) {
        out.add(new DefaultResourceRequest.Builder(RequestType.READ, new ResourcePath(path))
                .resourceParams(params).mediaTypeMatcher(mediaTypeMatcher)
                .requestAttribute(HttpHeaders.Names.AUTHORIZATION,
                        msg.headers().get(HttpHeaders.Names.AUTHORIZATION))
                .requestAttribute(HttpHeaders.Names.ACCEPT, new MediaType(acceptHeader))
                .requestAttribute(HTTP_REQUEST, msg).pagination(decodePagination(params))
                .returnFields(decodeReturnFields(params)).sorting(decodeSorting(params)).build());
    } else if (msg.getMethod().equals(HttpMethod.PUT)) {
        String contentTypeHeader = msg.headers().get(HttpHeaders.Names.CONTENT_TYPE);
        MediaType contentType = new MediaType(contentTypeHeader);
        out.add(new DefaultResourceRequest.Builder(RequestType.UPDATE, new ResourcePath(path))
                .resourceParams(params).mediaTypeMatcher(mediaTypeMatcher)
                .requestAttribute(HttpHeaders.Names.AUTHORIZATION,
                        msg.headers().get(HttpHeaders.Names.AUTHORIZATION))
                .requestAttribute(HttpHeaders.Names.CONTENT_TYPE, contentType)
                .requestAttribute(HTTP_REQUEST, msg)
                .resourceState(new DefaultLazyResourceState(codecManager, contentType, content)).build());
    } else if (msg.getMethod().equals(HttpMethod.DELETE)) {
        out.add(new DefaultResourceRequest.Builder(RequestType.DELETE, new ResourcePath(path))
                .resourceParams(params).mediaTypeMatcher(mediaTypeMatcher)
                .requestAttribute(HttpHeaders.Names.AUTHORIZATION,
                        msg.headers().get(HttpHeaders.Names.AUTHORIZATION))
                .requestAttribute(HttpHeaders.Names.ACCEPT, new MediaType(acceptHeader))
                .requestAttribute(HTTP_REQUEST, msg).build());
    }
}

From source file:io.liveoak.container.protocols.websocket.WebSocketHandshakerHandler.java

License:Open Source License

@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (!(msg instanceof FullHttpRequest)) {
        DefaultHttpRequest req = (DefaultHttpRequest) msg;
        String upgrade = req.headers().get(HttpHeaders.Names.UPGRADE);
        if (HttpHeaders.Values.WEBSOCKET.equalsIgnoreCase(upgrade)) {
            // ensure FullHttpRequest by installing HttpObjectAggregator in front of this handler
            ReferenceCountUtil.retain(msg);
            this.configurator.switchToWebSocketsHandshake(ctx.pipeline());
            ctx.pipeline().fireChannelRead(msg);
        } else {//  w  ww. jav a2s.  co m
            ReferenceCountUtil.retain(msg);
            this.configurator.switchToPlainHttp(ctx.pipeline());
            ctx.pipeline().fireChannelRead(msg);
        }
    } else {
        // do the handshake
        FullHttpRequest req = (FullHttpRequest) msg;
        WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(req.getUri(), null,
                false);
        WebSocketServerHandshaker handshaker = wsFactory.newHandshaker(req);
        if (handshaker == null) {
            WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
        } else {
            ChannelFuture future = handshaker.handshake(ctx.channel(), req);
            future.addListener(f -> {
                this.configurator.switchToWebSockets(ctx.pipeline());
            });
        }
    }
}

From source file:localhost.apps.proxy.sensor.HttpSnoopClient.java

License:Apache License

public static void send(DefaultHttpRequest request, LocalhostResponse response) {
    HttpSnoopClient client;/*  www.ja  v a2s  .c o m*/
    try {
        client = HttpSnoopClient.getMap(request.getUri());
        client.request = request;
        client.response = response;
    } catch (URISyntaxException e) {
        logger.error(e.getMessage(), e);
    }
}