Example usage for io.netty.handler.codec.http HttpMethod GET

List of usage examples for io.netty.handler.codec.http HttpMethod GET

Introduction

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

Prototype

HttpMethod GET

To view the source code for io.netty.handler.codec.http HttpMethod GET.

Click Source Link

Document

The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI.

Usage

From source file:io.scalecube.socketio.pipeline.JsonpPollingHandlerTest.java

License:Apache License

@Test
public void testChannelReadWrongPath() throws Exception {
    HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/wrongPath/");
    LastOutboundHandler lastOutboundHandler = new LastOutboundHandler();
    EmbeddedChannel channel = new EmbeddedChannel(lastOutboundHandler, jsonpPollingHandler);
    channel.writeInbound(request);//from  w  w  w  .  j a v  a  2s.  com
    Object object = channel.readInbound();
    Assert.assertTrue(object instanceof HttpRequest);
    Assert.assertEquals(request, object);
    channel.finish();
}

From source file:io.scalecube.socketio.pipeline.JsonpPollingHandlerTest.java

License:Apache License

@Test
public void testChannelReadConnect() throws Exception {
    HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
            "/socket.io/1/jsonp-polling");
    String origin = "http://localhost:8080";
    HttpHeaders.addHeader(request, HttpHeaders.Names.ORIGIN, origin);
    LastOutboundHandler lastOutboundHandler = new LastOutboundHandler();
    EmbeddedChannel channel = new EmbeddedChannel(lastOutboundHandler, jsonpPollingHandler);
    channel.writeInbound(request);/* ww  w.j  a v a  2 s  .c om*/
    Object object = channel.readInbound();
    Assert.assertTrue(object instanceof ConnectPacket);
    ConnectPacket packet = (ConnectPacket) object;
    Assert.assertEquals(TransportType.JSONP_POLLING, packet.getTransportType());
    Assert.assertEquals(origin, packet.getOrigin());
    Assert.assertNull(packet.getRemoteAddress());
    channel.finish();
}

From source file:io.scalecube.socketio.pipeline.JsonpPollingHandlerTest.java

License:Apache License

@Test
public void testChannelReadConnectWithClientIpInHeader() throws Exception {
    HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
            "/socket.io/1/jsonp-polling");
    String origin = "http://localhost:8080";
    HttpHeaders.addHeader(request, HttpHeaders.Names.ORIGIN, origin);
    HttpHeaders.addHeader(request, X_FORWARDED_FOR, "1.2.3.4");

    LastOutboundHandler lastOutboundHandler = new LastOutboundHandler();
    EmbeddedChannel channel = new EmbeddedChannel(lastOutboundHandler, jsonpPollingHandler);
    channel.writeInbound(request);//from w  w  w . j  a  va 2 s.  com
    Object object = channel.readInbound();
    Assert.assertTrue(object instanceof ConnectPacket);
    ConnectPacket packet = (ConnectPacket) object;
    Assert.assertEquals(TransportType.JSONP_POLLING, packet.getTransportType());
    Assert.assertEquals(origin, packet.getOrigin());
    Assert.assertEquals("/1.2.3.4:0", packet.getRemoteAddress().toString());
    channel.finish();
}

From source file:io.scalecube.socketio.pipeline.WebSocketHandler.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    // ?//  w w w .ja v  a2  s  . c om
    if (msg instanceof FullHttpRequest) {
        FullHttpRequest req = (FullHttpRequest) msg;
        if (req.getMethod() == HttpMethod.GET && req.getUri().startsWith(connectPath)) {
            final QueryStringDecoder queryDecoder = new QueryStringDecoder(req.getUri());
            final String requestPath = queryDecoder.path();

            if (log.isDebugEnabled())
                log.debug("Received HTTP {} handshake request: {} {} from channel: {}",
                        getTransportType().getName(), req.getMethod(), requestPath, ctx.channel());

            handshake(ctx, req, requestPath);

            ReferenceCountUtil.release(msg);
            return;
        }
    } else if (msg instanceof WebSocketFrame && isCurrentHandlerSession(ctx)) {
        handleWebSocketFrame(ctx, (WebSocketFrame) msg);
        return;
    }
    ctx.fireChannelRead(msg);
}

From source file:io.scalecube.socketio.pipeline.WebSocketHandlerTest.java

License:Apache License

@Test
public void testChannelReadWrongPath() throws Exception {
    HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/wrongPath/");
    LastOutboundHandler lastOutboundHandler = new LastOutboundHandler();
    EmbeddedChannel channel = new EmbeddedChannel(lastOutboundHandler, webSocketHandler);
    channel.writeInbound(request);//from  ww  w. j  a v  a2  s  .  c o  m
    Object object = channel.readInbound();
    Assert.assertTrue(object instanceof HttpRequest);
    Assert.assertEquals(request, object);
    channel.finish();
}

From source file:io.scalecube.socketio.pipeline.XHRPollingHandler.java

License:Apache License

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    // ?/*from   ww w . ja v  a  2 s.  c  o m*/
    if (msg instanceof FullHttpRequest) {
        final FullHttpRequest req = (FullHttpRequest) msg;
        final HttpMethod requestMethod = req.getMethod();
        final QueryStringDecoder queryDecoder = new QueryStringDecoder(req.getUri());
        final String requestPath = queryDecoder.path();

        if (requestPath.startsWith(connectPath)) {
            if (log.isDebugEnabled())
                log.debug("Received HTTP XHR-Polling request: {} {} from channel: {}", requestMethod,
                        requestPath, ctx.channel());

            final String sessionId = PipelineUtils.getSessionId(requestPath);
            final String origin = PipelineUtils.getOrigin(req);

            if (HttpMethod.GET.equals(requestMethod)) {
                SocketAddress clientIp = PipelineUtils.getHeaderClientIPParamValue(req, remoteAddressHeader);

                // Process polling request from client
                final ConnectPacket packet = new ConnectPacket(sessionId, origin);
                packet.setTransportType(TransportType.XHR_POLLING);
                packet.setRemoteAddress(clientIp);

                ctx.fireChannelRead(packet);
            } else if (HttpMethod.POST.equals(requestMethod)) {
                // Process message request from client
                List<Packet> packets = PacketFramer.decodePacketsFrame(req.content());
                for (Packet packet : packets) {
                    packet.setSessionId(sessionId);
                    packet.setOrigin(origin);
                    ctx.fireChannelRead(packet);
                }
            } else {
                log.warn("Can't process HTTP XHR-Polling request. Unknown request method: {} from channel: {}",
                        requestMethod, ctx.channel());
            }
            ReferenceCountUtil.release(msg);
            return;
        }
    }

    ctx.fireChannelRead(msg);
}

From source file:io.scalecube.socketio.pipeline.XHRPollingHandlerTest.java

License:Apache License

@Test
public void testChannelReadWrongPath() throws Exception {
    HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/wrongPath/");
    LastOutboundHandler lastOutboundHandler = new LastOutboundHandler();
    EmbeddedChannel channel = new EmbeddedChannel(lastOutboundHandler, xhrPollingHandler);
    channel.writeInbound(request);//w  ww  .  j  ava 2 s .c  o m
    Object object = channel.readInbound();
    Assert.assertTrue(object instanceof HttpRequest);
    Assert.assertEquals(request, object);
    channel.finish();
}

From source file:io.scalecube.socketio.pipeline.XHRPollingHandlerTest.java

License:Apache License

@Test
public void testChannelReadConnect() throws Exception {
    HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
            "/socket.io/1/xhr-polling");
    String origin = "http://localhost:8080";
    HttpHeaders.addHeader(request, HttpHeaders.Names.ORIGIN, origin);
    LastOutboundHandler lastOutboundHandler = new LastOutboundHandler();
    EmbeddedChannel channel = new EmbeddedChannel(lastOutboundHandler, xhrPollingHandler);
    channel.writeInbound(request);//from   w  w  w. ja va2  s  .  co m
    Object object = channel.readInbound();
    Assert.assertTrue(object instanceof ConnectPacket);
    ConnectPacket packet = (ConnectPacket) object;
    Assert.assertEquals(TransportType.XHR_POLLING, packet.getTransportType());
    Assert.assertEquals(origin, packet.getOrigin());
    Assert.assertNull(packet.getRemoteAddress());
    channel.finish();
}

From source file:io.scalecube.socketio.pipeline.XHRPollingHandlerTest.java

License:Apache License

@Test
public void testChannelReadConnectWithClientIpInHeader() throws Exception {
    HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
            "/socket.io/1/xhr-polling");
    String origin = "http://localhost:8080";
    HttpHeaders.addHeader(request, HttpHeaders.Names.ORIGIN, origin);
    HttpHeaders.addHeader(request, X_FORWARDED_FOR, "1.2.3.4");

    LastOutboundHandler lastOutboundHandler = new LastOutboundHandler();
    EmbeddedChannel channel = new EmbeddedChannel(lastOutboundHandler, xhrPollingHandler);
    channel.writeInbound(request);//from ww w. j a v a  2 s  . co  m
    Object object = channel.readInbound();
    Assert.assertTrue(object instanceof ConnectPacket);
    ConnectPacket packet = (ConnectPacket) object;
    Assert.assertEquals(TransportType.XHR_POLLING, packet.getTransportType());
    Assert.assertEquals(origin, packet.getOrigin());
    Assert.assertEquals("/1.2.3.4:0", packet.getRemoteAddress().toString());
    channel.finish();
}

From source file:io.selendroid.android.impl.DefaultHardwareDeviceTests.java

License:Apache License

@Test
public void testShouldBeAbleToStartSelendroid() throws Exception {
    IDevice device = mock(IDevice.class);
    when(device.getSerialNumber()).thenReturn(serial);
    AndroidDevice emulator = new DefaultHardwareDevice(device);
    Assert.assertTrue(emulator.isDeviceReady());
    cleanUpDevice(emulator);//from w  w w . j a v  a  2 s . co  m

    // install apps
    emulator.install(selendroidServer);
    emulator.install(aut);
    String installedAPKs = listInstalledPackages();
    Assert.assertTrue(installedAPKs.contains(SELENDROID_SERVER_PACKAGE));
    Assert.assertTrue(installedAPKs.contains(AUT_PACKAGE));

    // start selendroid
    emulator.startSelendroid(aut, port, new SelendroidCapabilities());
    String url = "http://localhost:" + port + "/wd/hub/status";
    HttpResponse response = HttpClientUtil.executeRequest(url, HttpMethod.GET);
    SelendroidAssert.assertResponseIsOk(response);
    Assert.assertTrue(emulator.isSelendroidRunning());
}