List of usage examples for io.netty.handler.codec.http HttpMethod GET
HttpMethod GET
To view the source code for io.netty.handler.codec.http HttpMethod GET.
Click Source Link
From source file:io.urmia.job.handler.JobHandler.java
License:Open Source License
private void setupProxyGet(final ChannelHandlerContext ctx, JobGetRequest getRequest) throws Exception { ServiceInstance<NodeType> ods = ns.get(NodeType.ODS, getRequest.getStorageNodeId()); List<ServiceInstance<NodeType>> l = Lists.newArrayList(ods); log.info("proxy storage node: {}", ods); HttpRequest initHttpRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, getRequest.objectName.toString()); HttpProxyFrontendHandler proxy = new HttpProxyFrontendHandler(l, mds, initHttpRequest, ctx, true, Optional.<FullObjectName>absent()); ctx.pipeline().remove("encoder"); ctx.pipeline().remove("aggregator"); ctx.pipeline().remove("job-decoder"); ctx.pipeline().remove("job"); ctx.pipeline().addLast("proxy", proxy); }
From source file:io.urmia.st.StorageServerHandler.java
License:Open Source License
@Override protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception { if (msg instanceof HttpRequest) { requestStartMS = System.currentTimeMillis(); request = (HttpRequest) msg;/*from ww w .j a v a 2 s . co m*/ log.info("received HttpRequest: {} {}", request.getMethod(), request.getUri()); // todo: what's this? //if (is100ContinueExpected(request)) { // send100Continue(ctx); //} if (HttpMethod.PUT.equals(request.getMethod())) { // start doing the fs put. next msg is not a LastHttpContent handlePUT(ctx, request); //return; } ctx.read(); return; } if (msg instanceof HttpContent) { // New chunk is received HttpContent chunk = (HttpContent) msg; //log.info("chunk {} of size: {}", chunk, chunk.content().readableBytes()); if (fileChannel != null) { writeToFile(chunk.content()); } // example of reading only if at the end if (chunk instanceof LastHttpContent) { log.trace("received LastHttpContent: {}", chunk); if (HttpMethod.HEAD.equals(request.getMethod())) { handleHEAD(ctx, request); ctx.read(); return; } if (HttpMethod.GET.equals(request.getMethod())) { handleGET(ctx, request); ctx.read(); return; } if (HttpMethod.DELETE.equals(request.getMethod())) { handleDELETE(ctx, request); ctx.read(); return; } if (HttpMethod.PUT.equals(request.getMethod())) { // TODO: reset() if exception catch or timeout (i.e. no LastHttpContent) writeResponse(ctx, new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK), true); // close the connection after upload (mput) done reset(); access.success(ctx, "PUT", uri, requestStartMS); ctx.read(); return; } log.warn("unknown request: {}", request); sendError(ctx, HttpResponseStatus.BAD_REQUEST); } ctx.read(); return; } log.warn("unknown msg type: {}", msg); }
From source file:io.vertx.core.http.impl.Http1xServerConnection.java
License:Open Source License
private WebSocketServerHandshaker createHandshaker(HttpRequest request) { // As a fun part, Firefox 6.0.2 supports Websockets protocol '7'. But, // it doesn't send a normal 'Connection: Upgrade' header. Instead it // sends: 'Connection: keep-alive, Upgrade'. Brilliant. Channel ch = channel();//from w w w.j a v a 2 s .c o m String connectionHeader = request.headers().get(io.vertx.core.http.HttpHeaders.CONNECTION); if (connectionHeader == null || !connectionHeader.toLowerCase().contains("upgrade")) { HttpUtils.sendError(ch, BAD_REQUEST, "\"Connection\" must be \"Upgrade\"."); return null; } if (request.method() != HttpMethod.GET) { HttpUtils.sendError(ch, METHOD_NOT_ALLOWED, null); return null; } try { WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory( HttpUtils.getWebSocketLocation(request, isSSL()), options.getWebsocketSubProtocols(), options.perMessageWebsocketCompressionSupported() || options.perFrameWebsocketCompressionSupported(), options.getMaxWebsocketFrameSize(), options.isAcceptUnmaskedFrames()); WebSocketServerHandshaker shake = factory.newHandshaker(request); if (shake == null) { log.error("Unrecognised websockets handshake"); WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ch); } return shake; } catch (Exception e) { throw new VertxException(e); } }
From source file:io.vertx.core.http.impl.HttpServerImpl.java
License:Open Source License
WebSocketServerHandshaker createHandshaker(Channel ch, HttpRequest request) { // As a fun part, Firefox 6.0.2 supports Websockets protocol '7'. But, // it doesn't send a normal 'Connection: Upgrade' header. Instead it // sends: 'Connection: keep-alive, Upgrade'. Brilliant. String connectionHeader = request.headers().get(io.vertx.core.http.HttpHeaders.CONNECTION); if (connectionHeader == null || !connectionHeader.toLowerCase().contains("upgrade")) { sendError("\"Connection\" must be \"Upgrade\".", BAD_REQUEST, ch); return null; }//from w w w . j av a2 s. com if (request.getMethod() != HttpMethod.GET) { sendError(null, METHOD_NOT_ALLOWED, ch); return null; } try { WebSocketServerHandshakerFactory factory = new WebSocketServerHandshakerFactory( getWebSocketLocation(ch.pipeline(), request), subProtocols, false, options.getMaxWebsocketFrameSize(), options.isAcceptUnmaskedFrames()); WebSocketServerHandshaker shake = factory.newHandshaker(request); if (shake == null) { log.error("Unrecognised websockets handshake"); WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ch); } return shake; } catch (Exception e) { throw new VertxException(e); } }
From source file:io.vertx.core.http.impl.HttpUtils.java
License:Open Source License
static HttpMethod toNettyHttpMethod(io.vertx.core.http.HttpMethod method, String rawMethod) { switch (method) { case CONNECT: { return HttpMethod.CONNECT; }/*from w w w . j ava2s . co m*/ case GET: { return HttpMethod.GET; } case PUT: { return HttpMethod.PUT; } case POST: { return HttpMethod.POST; } case DELETE: { return HttpMethod.DELETE; } case HEAD: { return HttpMethod.HEAD; } case OPTIONS: { return HttpMethod.OPTIONS; } case TRACE: { return HttpMethod.TRACE; } case PATCH: { return HttpMethod.PATCH; } default: { return HttpMethod.valueOf(rawMethod); } } }
From source file:io.vertx.core.net.NetTest.java
License:Open Source License
private void testNetClientInternal_(HttpServerOptions options, boolean expectSSL) throws Exception { waitFor(2);/*w w w .j av a 2 s . c o m*/ HttpServer server = vertx.createHttpServer(options); server.requestHandler(req -> { req.response().end("Hello World"); }); CountDownLatch latch = new CountDownLatch(1); server.listen(onSuccess(v -> { latch.countDown(); })); awaitLatch(latch); client.connect(1234, "localhost", onSuccess(so -> { NetSocketInternal soInt = (NetSocketInternal) so; assertEquals(expectSSL, soInt.isSsl()); ChannelHandlerContext chctx = soInt.channelHandlerContext(); ChannelPipeline pipeline = chctx.pipeline(); pipeline.addBefore("handler", "http", new HttpClientCodec()); AtomicInteger status = new AtomicInteger(); soInt.handler(buff -> fail()); soInt.messageHandler(obj -> { switch (status.getAndIncrement()) { case 0: assertTrue(obj instanceof HttpResponse); HttpResponse resp = (HttpResponse) obj; assertEquals(200, resp.status().code()); break; case 1: assertTrue(obj instanceof LastHttpContent); ByteBuf content = ((LastHttpContent) obj).content(); assertEquals(!expectSSL, content.isDirect()); assertEquals(1, content.refCnt()); String val = content.toString(StandardCharsets.UTF_8); assertTrue(content.release()); assertEquals("Hello World", val); complete(); break; default: fail(); } }); soInt.writeMessage(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/somepath"), onSuccess(v -> complete())); })); await(); }
From source file:io.viewserver.network.netty.websocket.WebSocketServerHandler.java
License:Apache License
private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req) { if (!req.getDecoderResult().isSuccess()) { sendHttpResponse(ctx, req,/*from www . j av a 2 s .c o m*/ new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.BAD_REQUEST)); return; } if (req.getMethod() != HttpMethod.GET) { sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.FORBIDDEN)); return; } WebSocketServerHandshakerFactory handshakerFactory = new WebSocketServerHandshakerFactory(uri.toString(), null, true); handshaker = handshakerFactory.newHandshaker(req); if (handshaker == null) { WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel()); } else { handshaker.handshake(ctx.channel(), req); } }
From source file:jj.http.server.EmbeddedHttpRequest.java
License:Apache License
public EmbeddedHttpRequest(final String uri) { this(HttpMethod.GET, uri); }
From source file:jj.http.server.EngineHttpHandlerTest.java
License:Apache License
@Test public void testChannelRead0WebSocketRequest() throws Exception { FullHttpRequest fullHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"); given(webSocketRequestChecker.isWebSocketRequest(fullHttpRequest)).willReturn(true); prepareInjectorStubbing();// w w w .ja va2 s . co m handler.channelRead0(ctx, fullHttpRequest); verify(webSocketConnectionMaker).handshakeWebsocket(); }
From source file:jj.http.server.EngineHttpHandlerTest.java
License:Apache License
@Test public void testChannelRead0HttpRequest() throws Exception { FullHttpRequest fullHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"); prepareInjectorStubbing();//from w w w . j a v a 2 s . c o m handler.channelRead0(ctx, fullHttpRequest); verify(injector).createChildInjector(moduleCaptor.capture()); Module module = moduleCaptor.getValue(); assertThat(module, is(notNullValue())); module.configure(binder); verify(binder).bind(ChannelHandlerContext.class); verify(abb).toInstance(ctx); verify(binder).bind(FullHttpRequest.class); verify(abb).toInstance(fullHttpRequest); verify(binder).bind(HttpServerRequest.class); verify(abb).to(HttpServerRequestImpl.class); verify(binder).bind(HttpServerResponse.class); verify(abb).to(HttpServerResponseImpl.class); verifyNoMoreInteractions(binder, abb); }