List of usage examples for io.netty.handler.codec.http HttpRequest getUri
@Deprecated String getUri();
From source file:org.wso2.carbon.transport.http.netty.contractimpl.websocket.message.WebSocketInitMessageImpl.java
License:Open Source License
private String getWebSocketURL(HttpRequest req) { String protocol = Constants.WEBSOCKET_PROTOCOL; if (isConnectionSecured) { protocol = Constants.WEBSOCKET_PROTOCOL_SECURED; }/* w ww .j a v a 2 s .com*/ String url = protocol + "://" + req.headers().get("Host") + req.getUri(); return url; }
From source file:org.wso2.carbon.transport.http.netty.listener.SourceHandler.java
License:Open Source License
private HTTPCarbonMessage setupCarbonMessage(HttpMessage httpMessage) throws URISyntaxException { if (handlerExecutor != null) { handlerExecutor.executeAtSourceRequestReceiving(sourceReqCmsg); }/*from w ww . j a v a 2s.c om*/ sourceReqCmsg = new HttpCarbonRequest((HttpRequest) httpMessage); HttpRequest httpRequest = (HttpRequest) httpMessage; sourceReqCmsg.setProperty(Constants.CHNL_HNDLR_CTX, this.ctx); sourceReqCmsg.setProperty(Constants.SRC_HANDLER, this); sourceReqCmsg.setProperty(Constants.HTTP_VERSION, httpRequest.getProtocolVersion().text()); sourceReqCmsg.setProperty(Constants.HTTP_METHOD, httpRequest.getMethod().name()); InetSocketAddress localAddress = (InetSocketAddress) ctx.channel().localAddress(); sourceReqCmsg.setProperty(org.wso2.carbon.messaging.Constants.LISTENER_PORT, localAddress.getPort()); sourceReqCmsg.setProperty(org.wso2.carbon.messaging.Constants.LISTENER_INTERFACE_ID, interfaceId); sourceReqCmsg.setProperty(org.wso2.carbon.messaging.Constants.PROTOCOL, Constants.HTTP_SCHEME); boolean isSecuredConnection = false; if (ctx.channel().pipeline().get(Constants.SSL_HANDLER) != null) { isSecuredConnection = true; } sourceReqCmsg.setProperty(Constants.IS_SECURED_CONNECTION, isSecuredConnection); sourceReqCmsg.setProperty(Constants.LOCAL_ADDRESS, ctx.channel().localAddress()); sourceReqCmsg.setProperty(Constants.REQUEST_URL, httpRequest.getUri()); sourceReqCmsg.setProperty(Constants.TO, httpRequest.getUri()); //Added protocol name as a string return sourceReqCmsg; }
From source file:org.wso2.carbon.uuf.connector.ms.MicroserviceHttpRequest.java
License:Open Source License
public MicroserviceHttpRequest(io.netty.handler.codec.http.HttpRequest request, byte[] contentBytes) { this.url = null; // Netty HttpRequest does not have a 'getUrl()' method. this.method = request.getMethod().name(); this.protocol = request.getProtocolVersion().text(); this.headers = request.headers().entries().stream() .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); String rawUri = request.getUri(); int uriPathEndIndex = rawUri.indexOf('?'); String rawUriPath, rawQueryString; if (uriPathEndIndex == -1) { rawUriPath = rawUri;//from w w w. j a v a2 s . c o m rawQueryString = null; } else { rawUriPath = rawUri.substring(0, uriPathEndIndex); rawQueryString = rawUri.substring(uriPathEndIndex + 1, rawUri.length()); } this.uri = QueryStringDecoder.decodeComponent(rawUriPath); this.appContext = UriUtils.getAppContext(this.uri); this.uriWithoutAppContext = UriUtils.getUriWithoutAppContext(this.uri); this.queryString = rawQueryString; // Query string is not very useful, so we don't bother to decode it. if (rawQueryString != null) { HashMap<String, Object> map = new HashMap<>(); new QueryStringDecoder(rawQueryString, false).parameters() .forEach((key, value) -> map.put(key, (value.size() == 1) ? value.get(0) : value)); this.queryParams = map; } else { this.queryParams = Collections.emptyMap(); } if (contentBytes != null) { this.contentBytes = contentBytes; this.contentLength = contentBytes.length; this.inputStream = new ByteArrayInputStream(contentBytes); } else { this.contentBytes = null; this.contentLength = 0; this.inputStream = null; } }
From source file:org.wso2.gw.emulator.http.consumer.HttpRequestInformationProcessor.java
License:Open Source License
private void populateQueryParameters(HttpRequest request, HttpRequestContext requestContext) { QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.getUri()); Map<String, List<String>> params = queryStringDecoder.parameters(); requestContext.setQueryParameters(params); }
From source file:org.wso2.gw.emulator.http.consumer.HttpRequestInformationProcessor.java
License:Open Source License
private void populateRequestContext(HttpRequest request, HttpRequestContext requestContext) { requestContext.setUri(request.getUri()); }
From source file:org.wso2.msf4j.internal.router.HttpResourceModelProcessor.java
License:Open Source License
/** * Handle http Request./*from w w w. j a v a 2s .c o m*/ * * @param request HttpRequest to be handled. * @param responder HttpResponder to write the response. * @param groupValues Values needed for the invocation. * @param contentType Content types * @param acceptTypes Accept types * @return HttpMethodInfo * @throws HandlerException If an error occurs */ @SuppressWarnings("unchecked") public HttpMethodInfo buildHttpMethodInfo(HttpRequest request, HttpResponder responder, Map<String, String> groupValues, String contentType, List<String> acceptTypes) throws HandlerException { //TODO: Refactor group values. try { if (httpResourceModel.getHttpMethod().contains(request.getMethod())) { //Setup args for reflection call List<HttpResourceModel.ParameterInfo<?>> paramInfoList = httpResourceModel.getParamInfoList(); List<String> producesMediaTypes = httpResourceModel.getProducesMediaTypes(); Object[] args = new Object[paramInfoList.size()]; String acceptType = "*/*"; if (!producesMediaTypes.contains("*/*") && acceptTypes != null) { acceptType = acceptTypes.contains("*/*") ? producesMediaTypes.get(0) : producesMediaTypes.stream().filter(acceptTypes::contains).findFirst().get(); } int idx = 0; for (HttpResourceModel.ParameterInfo<?> paramInfo : paramInfoList) { if (paramInfo.getAnnotation() != null) { Class<? extends Annotation> annotationType = paramInfo.getAnnotation().annotationType(); if (PathParam.class.isAssignableFrom(annotationType)) { args[idx] = getPathParamValue((HttpResourceModel.ParameterInfo<String>) paramInfo, groupValues); } else if (QueryParam.class.isAssignableFrom(annotationType)) { args[idx] = getQueryParamValue( (HttpResourceModel.ParameterInfo<List<String>>) paramInfo, request.getUri()); } else if (HeaderParam.class.isAssignableFrom(annotationType)) { args[idx] = getHeaderParamValue( (HttpResourceModel.ParameterInfo<List<String>>) paramInfo, request); } else if (Context.class.isAssignableFrom(annotationType)) { args[idx] = getContextParamValue((HttpResourceModel.ParameterInfo<Object>) paramInfo, request, responder); } } else if (request instanceof FullHttpRequest) { // If an annotation is not present the parameter is considered a // request body data parameter String content = ((FullHttpRequest) request).content().toString(Charsets.UTF_8); Type paramType = paramInfo.getParameterType(); args[idx] = BeanConverter.instance((contentType != null) ? contentType : "*/*") .toObject(content, paramType); } idx++; } if (httpStreamer == null) { return new HttpMethodInfo(httpResourceModel.getMethod(), httpResourceModel.getHttpHandler(), request, responder, args, httpResourceModel.getExceptionHandler(), acceptType); } else { return new HttpMethodInfo(httpResourceModel.getMethod(), httpResourceModel.getHttpHandler(), request, responder, args, httpResourceModel.getExceptionHandler(), acceptType, httpStreamer); } } else { //Found a matching resource but could not find the right HttpMethod so return 405 throw new HandlerException(HttpResponseStatus.METHOD_NOT_ALLOWED, String.format("Problem accessing: %s. Reason: Method Not Allowed", request.getUri())); } } catch (Throwable e) { throw new HandlerException(HttpResponseStatus.INTERNAL_SERVER_ERROR, String.format("Error in executing request: %s %s", request.getMethod(), request.getUri()), e); } }
From source file:org.wso2.msf4j.security.oauth2.OAuth2SecurityInterceptor.java
License:Open Source License
@Override public boolean preCall(HttpRequest request, HttpResponder responder, ServiceMethodInfo serviceMethodInfo) { SecurityErrorCode errorCode;/*from ww w . java 2 s. c om*/ try { HttpHeaders headers = request.headers(); if (headers != null && headers.contains(AUTHORIZATION_HTTP_HEADER)) { String authHeader = headers.get(AUTHORIZATION_HTTP_HEADER); return validateToken(authHeader); } else { throw new MSF4JSecurityException(SecurityErrorCode.AUTHENTICATION_FAILURE, "Missing Authorization header is the request.`"); } } catch (MSF4JSecurityException e) { errorCode = e.getErrorCode(); log.error(e.getMessage() + " Requested Path: " + request.getUri()); } handleSecurityError(errorCode, responder); return false; }
From source file:reactor.net.tcp.TcpServerTests.java
License:Open Source License
@Test public void exposesHttpServer() throws InterruptedException { final int port = SocketUtils.findAvailableTcpPort(); final TcpServer<HttpRequest, HttpResponse> server = new TcpServerSpec<HttpRequest, HttpResponse>( NettyTcpServer.class).env(env).listen(port) .options(new NettyServerSocketOptions().pipelineConfigurer(new Consumer<ChannelPipeline>() { @Override public void accept(ChannelPipeline pipeline) { pipeline.addLast(new HttpRequestDecoder()); pipeline.addLast(new HttpObjectAggregator(Integer.MAX_VALUE)); pipeline.addLast(new HttpResponseEncoder()); }/*from w w w . j a v a 2s . c om*/ })).consume(new Consumer<NetChannel<HttpRequest, HttpResponse>>() { @Override public void accept(final NetChannel<HttpRequest, HttpResponse> ch) { ch.in().consume(new Consumer<HttpRequest>() { @Override public void accept(HttpRequest req) { ByteBuf buf = Unpooled.copiedBuffer("Hello World!".getBytes()); int len = buf.readableBytes(); DefaultFullHttpResponse resp = new DefaultFullHttpResponse( HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buf); resp.headers().set(HttpHeaders.Names.CONTENT_LENGTH, len); resp.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/plain"); resp.headers().set(HttpHeaders.Names.CONNECTION, "Keep-Alive"); ch.send(resp); if (req.getMethod() == HttpMethod.GET && "/test".equals(req.getUri())) { latch.countDown(); } } }); } }).get(); log.info("Starting HTTP server on http://localhost:{}/", port); server.start().await(); for (int i = 0; i < threads; i++) { threadPool.submit(new HttpRequestWriter(port)); } assertTrue("Latch was counted down", latch.await(15, TimeUnit.SECONDS)); end.set(System.currentTimeMillis()); double elapsed = (end.get() - start.get()); System.out.println("HTTP elapsed: " + (int) elapsed + "ms"); System.out.println("HTTP throughput: " + (int) ((msgs * threads) / (elapsed / 1000)) + "/sec"); server.shutdown().await(); }
From source file:reactor.tcp.TcpServerTests.java
License:Open Source License
@Test public void exposesHttpServer() throws InterruptedException { final int port = SocketUtils.findAvailableTcpPort(); final TcpServer<HttpRequest, HttpResponse> server = new TcpServerSpec<HttpRequest, HttpResponse>( NettyTcpServer.class).env(env).listen(port) .options(new NettyServerSocketOptions().pipelineConfigurer(new Consumer<ChannelPipeline>() { @Override public void accept(ChannelPipeline pipeline) { pipeline.addLast(new HttpRequestDecoder()); pipeline.addLast(new HttpObjectAggregator(Integer.MAX_VALUE)); pipeline.addLast(new HttpResponseEncoder()); }/*from ww w.java 2 s .com*/ })).consume(new Consumer<TcpConnection<HttpRequest, HttpResponse>>() { @Override public void accept(final TcpConnection<HttpRequest, HttpResponse> conn) { conn.in().consume(new Consumer<HttpRequest>() { @Override public void accept(HttpRequest req) { ByteBuf buf = Unpooled.copiedBuffer("Hello World!".getBytes()); int len = buf.readableBytes(); DefaultFullHttpResponse resp = new DefaultFullHttpResponse( HttpVersion.HTTP_1_1, HttpResponseStatus.OK, buf); resp.headers().set(HttpHeaders.Names.CONTENT_LENGTH, len); resp.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/plain"); resp.headers().set(HttpHeaders.Names.CONNECTION, "Keep-Alive"); conn.send(resp); if (req.getMethod() == HttpMethod.GET && "/test".equals(req.getUri())) { latch.countDown(); } } }); } }).get(); log.info("Starting HTTP server on http://localhost:{}/", port); server.start(new Consumer<Void>() { @Override public void accept(Void v) { for (int i = 0; i < threads; i++) { threadPool.submit(new HttpRequestWriter(port)); } } }); assertTrue("Latch was counted down", latch.await(15, TimeUnit.SECONDS)); end.set(System.currentTimeMillis()); double elapsed = (end.get() - start.get()); System.out.println("HTTP elapsed: " + (int) elapsed + "ms"); System.out.println("HTTP throughput: " + (int) ((msgs * threads) / (elapsed / 1000)) + "/sec"); server.shutdown().await(); }
From source file:software.betamax.util.ProxyOverrider.java
License:Apache License
/** * Used by LittleProxy to connect to a downstream proxy if there is one. *//*from w ww . j a v a 2s .co m*/ @Override public void lookupChainedProxies(HttpRequest request, Queue<ChainedProxy> chainedProxies) { final InetSocketAddress originalProxy = originalProxies.get(URI.create(request.getUri()).getScheme()); if (originalProxy != null) { ChainedProxy chainProxy = new ChainedProxyAdapter() { @Override public InetSocketAddress getChainedProxyAddress() { return originalProxy; } }; chainedProxies.add(chainProxy); } else { chainedProxies.add(ChainedProxyAdapter.FALLBACK_TO_DIRECT_CONNECTION); } }