List of usage examples for io.vertx.core.http HttpServerRequest absoluteURI
String absoluteURI();
From source file:com.englishtown.vertx.jersey.impl.DefaultJerseyHandler.java
License:Open Source License
protected URI getAbsoluteURI(HttpServerRequest vertxRequest) { URI absoluteUri;/*from w ww . j a v a2s .c om*/ String hostAndPort = vertxRequest.headers().get(HttpHeaders.HOST); try { absoluteUri = URI.create(vertxRequest.absoluteURI()); if (hostAndPort != null && !hostAndPort.isEmpty()) { String[] parts = hostAndPort.split(":"); String host = parts[0]; int port = (parts.length > 1 ? Integer.valueOf(parts[1]) : -1); if (!host.equalsIgnoreCase(absoluteUri.getHost()) || port != absoluteUri.getPort()) { absoluteUri = UriBuilder.fromUri(absoluteUri).host(host).port(port).build(); } } return absoluteUri; } catch (IllegalArgumentException e) { String uri = vertxRequest.uri(); if (!uri.contains("?")) { throw e; } try { logger.warn("Invalid URI: " + uri + ". Attempting to parse query string.", e); QueryStringDecoder decoder = new QueryStringDecoder(uri); StringBuilder sb = new StringBuilder(decoder.path() + "?"); for (Map.Entry<String, List<String>> p : decoder.parameters().entrySet()) { for (String value : p.getValue()) { sb.append(p.getKey()).append("=").append(URLEncoder.encode(value, "UTF-8")); } } return URI.create(sb.toString()); } catch (Exception e1) { throw new RuntimeException(e1); } } }
From source file:io.advantageous.qbit.vertx.http.server.HttpServerVertx.java
License:Apache License
private void handleRequestWithBody(HttpServerRequest request) { final String contentType = request.headers().get("Content-Type"); if (HttpContentTypes.isFormContentType(contentType)) { request.setExpectMultipart(true); }/* w ww .ja va 2 s . c o m*/ final Buffer[] bufferHolder = new Buffer[1]; final HttpRequest bodyHttpRequest = vertxUtils.createRequest(request, () -> bufferHolder[0], new HashMap<>(), simpleHttpServer.getDecorators(), simpleHttpServer.getHttpResponseCreator()); if (simpleHttpServer.getShouldContinueReadingRequestBody().test(bodyHttpRequest)) { request.bodyHandler((buffer) -> { bufferHolder[0] = buffer; simpleHttpServer.handleRequest(bodyHttpRequest); }); } else { logger.info("Request body rejected {} {}", request.method(), request.absoluteURI()); } }
From source file:io.apiman.gateway.platforms.vertx3.http.HttpApiFactory.java
License:Apache License
private static void parsePath(HttpServerRequest request, ApiRequest apimanRequest) { // NB: The apiman version of the headers has already been parsed, so the headers have already been filtered/modified. // Therefore we wrap the original inbound headers (just get) to efficiently access the necessary data. ApiRequestPathInfo parsedPath = requestPathParser.parseEndpoint(request.path(), wrapMultiMap(request.headers())); apimanRequest.setApiOrgId(parsedPath.orgId); apimanRequest.setApiId(parsedPath.apiId); apimanRequest.setApiVersion(parsedPath.apiVersion); apimanRequest.setUrl(request.absoluteURI()); apimanRequest.setDestination(parsedPath.resource); }
From source file:io.apiman.gateway.platforms.vertx3.http.HttpServiceFactory.java
License:Apache License
private static void mungePath(HttpServerRequest request, VertxServiceRequest apimanRequest) { ServiceRequestPathInfo parsedPath = ApimanPathUtils.parseServiceRequestPath( request.getHeader(ApimanPathUtils.X_API_VERSION_HEADER), request.getHeader(ApimanPathUtils.ACCEPT_HEADER), request.path()); apimanRequest.setServiceOrgId(parsedPath.orgId); apimanRequest.setServiceId(parsedPath.serviceId); apimanRequest.setServiceVersion(parsedPath.serviceVersion); apimanRequest.setUrl(request.absoluteURI()); apimanRequest.setDestination(parsedPath.resource); if (apimanRequest.getServiceOrgId() == null) { throw new IllegalArgumentException("Invalid endpoint provided: " + request.path()); }//from ww w.java 2 s . c o m }
From source file:io.apiman.rls.vertx.RlsRestVerticle.java
License:Apache License
/** * Populate some links.// w w w .j av a 2 s . c o m * @param request */ private static RlsInfoLinksBean createInfoLinks(HttpServerRequest request) { RlsInfoLinksBean rval = new RlsInfoLinksBean(); try { String absUrl = request.absoluteURI(); if (!absUrl.endsWith("/")) { //$NON-NLS-1$ absUrl = absUrl + "/"; //$NON-NLS-1$ } URI uri = new URI(absUrl); URI createAndList = uri.resolve("limits"); //$NON-NLS-1$ rval.setCreate(createAndList.toString()); rval.setList(createAndList.toString()); } catch (URISyntaxException e) { } return rval; }
From source file:io.apiman.rls.vertx.RlsRestVerticle.java
License:Apache License
/** * Populate some links.// w ww. ja v a 2s . c om * @param request */ private static LimitListLinksBean createLimitListLinks(HttpServerRequest request, int pageNum, int pageSize) { LimitListLinksBean rval = new LimitListLinksBean(); String absUrl = request.absoluteURI(); if (!absUrl.endsWith("/")) { //$NON-NLS-1$ absUrl = absUrl + "/"; //$NON-NLS-1$ } rval.setSelf(absUrl); int qidx = absUrl.indexOf('?'); if (qidx > 0) { absUrl = absUrl.substring(0, qidx); } String nextUrl = absUrl + "?page=" + (pageNum + 1) + "&pageSize=" + pageSize; rval.setNextPage(nextUrl); if (pageNum > 1) { String prevUrl = absUrl + "?page=" + (pageNum - 1) + "&pageSize=" + pageSize; rval.setPrevPage(prevUrl); } return rval; }
From source file:io.apiman.rls.vertx.RlsRestVerticle.java
License:Apache License
/** * Populate some links.// w ww . j a v a2 s. com * @param request * @param limitId */ private static LimitLinksBean createLimitLinks(HttpServerRequest request, String limitId) { LimitLinksBean rval = new LimitLinksBean(); String absUrl = request.absoluteURI(); if (!absUrl.endsWith("/")) { //$NON-NLS-1$ absUrl = absUrl + "/"; //$NON-NLS-1$ } if (absUrl.contains(limitId)) { rval.setDelete(absUrl); rval.setSelf(absUrl); rval.setIncrement(absUrl); } else { try { URI uri = new URI(absUrl); URI limitUri = uri.resolve(limitId); String limitUriStr = limitUri.toString(); rval.setDelete(limitUriStr); rval.setSelf(limitUriStr); rval.setIncrement(limitUriStr); } catch (URISyntaxException e) { } } return rval; }
From source file:org.jberet.vertx.rest.JBeretRouterConfig.java
License:Open Source License
/** * Sets the href field for each {@code org.jberet.rest.entity.JobExecutionEntity} passed in. * * @param routingContext io.vertx.ext.web.RoutingContext * @param entities 1 or more {@code org.jberet.rest.entity.JobExecutionEntity} *///from ww w. ja va 2s . com private static void setJobExecutionEntityHref(final RoutingContext routingContext, final JobExecutionEntity... entities) { final HttpServerRequest request = routingContext.request(); final String absoluteURI = request.absoluteURI(); final String uri = request.uri(); final String baseURI = absoluteURI.substring(0, absoluteURI.length() - uri.length()); for (final JobExecutionEntity e : entities) { e.setHref(baseURI + "/jobexecutions/" + e.getExecutionId()); } }
From source file:org.pac4j.vertx.VertxWebContext.java
License:Apache License
public VertxWebContext(final RoutingContext routingContext) { final HttpServerRequest request = routingContext.request(); this.routingContext = routingContext; this.method = request.method().toString(); this.fullUrl = request.absoluteURI(); URI uri;/*from w w w. j a v a2 s . c o m*/ try { uri = new URI(fullUrl); } catch (URISyntaxException e) { e.printStackTrace(); throw new InvalidParameterException( "Request to invalid URL " + fullUrl + " while constructing VertxWebContext"); } this.scheme = uri.getScheme(); this.serverName = uri.getHost(); this.serverPort = (uri.getPort() != -1) ? uri.getPort() : scheme.equals("http") ? 80 : 443; this.remoteAddress = request.remoteAddress().toString(); headers = new JsonObject(); for (String name : request.headers().names()) { headers.put(name, request.headers().get(name)); } parameters = new JsonObject(); for (String name : request.params().names()) { parameters.put(name, new JsonArray(Arrays.asList(request.params().getAll(name).toArray()))); } mapParameters = new HashMap<>(); for (String name : parameters.fieldNames()) { JsonArray params = parameters.getJsonArray(name); String[] values = new String[params.size()]; int i = 0; for (Object o : params) { values[i++] = (String) o; } mapParameters.put(name, values); } }
From source file:org.sfs.util.SfsHttpUtil.java
License:Apache License
public static String getRemoteServiceUrl(HttpServerRequest httpServerRequest) { try {/*from ww w. j a va 2 s . com*/ URI absoluteRequestURI = new URI(httpServerRequest.absoluteURI()); MultiMap headers = httpServerRequest.headers(); String host = getFirstHeader(httpServerRequest, "X-Forwarded-Host"); String contextRoot = getFirstHeader(httpServerRequest, SfsHttpHeaders.X_CONTEXT_ROOT); if (host == null) host = getFirstHeader(httpServerRequest, HttpHeaders.HOST); if (host == null) host = absoluteRequestURI.getHost(); String proto = headers.get(HttpHeaders.X_FORWARDED_PROTO); if (proto == null) proto = absoluteRequestURI.getScheme(); String serviceUrl; if (contextRoot != null) { serviceUrl = String.format("%s://%s/%s", proto, host, contextRoot); } else { serviceUrl = String.format("%s://%s", proto, host); } return serviceUrl; } catch (URISyntaxException e) { throw new RuntimeException(e); } }