Java Code Examples for io.vertx.core.http.HttpServerRequest#absoluteURI()

The following examples show how to use io.vertx.core.http.HttpServerRequest#absoluteURI() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VertxUtil.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public static ResteasyUriInfo extractUriInfo(HttpServerRequest req, String contextPath) {
    String uri = req.absoluteURI();
    String protocol = req.scheme();

    String uriString;

    // If we appear to have an absolute URL, don't try to recreate it from the host and request line.
    if (uri.startsWith(protocol + "://")) {
        uriString = uri;
    } else {
        String host = req.host();
        if (host == null) {
            host = "unknown";
        }
        uriString = protocol + "://" + host + uri;
    }

    // ResteasyUriInfo expects a context path to start with a "/" character
    if (!contextPath.startsWith("/")) {
        contextPath = "/" + contextPath;
    }

    return new ResteasyUriInfo(uriString, contextPath);
}
 
Example 2
Source File: SfsHttpUtil.java    From sfs with Apache License 2.0 6 votes vote down vote up
public static String getRemoteServiceUrl(HttpServerRequest httpServerRequest) {
    try {
        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);
    }
}
 
Example 3
Source File: PaginationContext.java    From nubes with Apache License 2.0 6 votes vote down vote up
private String pageUrl(HttpServerRequest request, int pageNum, String rel) {
  StringBuilder sb = new StringBuilder("<");
  String url = request.absoluteURI();
  if (!url.contains("?")) { // can't rely on params() 'cause we might have injected some stuff (routing)
    url += "?" + CURRENT_PAGE_QUERY_PARAM + "=" + pageNum;
    url += "&" + PER_PAGE_QUERY_PARAM + "=" + itemsPerPage;
  } else {
    if (url.indexOf(CURRENT_PAGE_QUERY_PARAM + "=") > url.indexOf('?')) {
      url = url.replaceAll(CURRENT_PAGE_QUERY_PARAM + "=([^&]+)", CURRENT_PAGE_QUERY_PARAM + "=" + pageNum);
    } else {
      url += "&" + CURRENT_PAGE_QUERY_PARAM + "=" + pageNum;
    }
    if (!url.contains("&" + PER_PAGE_QUERY_PARAM) && !url.contains("?" + PER_PAGE_QUERY_PARAM)) {
      url += "&" + PER_PAGE_QUERY_PARAM + "=" + itemsPerPage;
    }
  }
  sb.append(url);
  sb.append(">; ");
  sb.append("rel=\"").append(rel).append("\"");
  return sb.toString();
}
 
Example 4
Source File: TestRest.java    From rest.vertx with Apache License 2.0 5 votes vote down vote up
@GET
@Path("/context/path")
@Produces("text/plain")
public String getRoutePath(@Context HttpServerRequest request) {

	return request.absoluteURI();
}