public static ResteasyUriInfo extractUriInfo(HttpExchange exchange) { String host = exchange.getLocalAddress().getHostName(); if (exchange.getLocalAddress().getPort() != 80 && exchange.getLocalAddress().getPort() != 443) { host += ":" + exchange.getLocalAddress().getPort(); } String uri = exchange.getRequestURI().toString(); String protocol = exchange.getHttpContext().getServer() instanceof HttpsServer ? "https" : "http"; URI absoluteURI = URI.create(protocol + "://" + host + uri); String contextPath = exchange.getHttpContext().getPath(); String path = PathHelper.getEncodedPathInfo(absoluteURI.getRawPath(), contextPath); if (!path.startsWith("/")) { path = "/" + path; } URI baseURI = absoluteURI; if (!path.trim().equals("")) { String tmpContextPath = contextPath; if (!tmpContextPath.endsWith("/")) tmpContextPath += "/"; baseURI = UriBuilder.fromUri(absoluteURI).replacePath(tmpContextPath).replaceQuery(null).build(); } else { baseURI = UriBuilder.fromUri(absoluteURI).replaceQuery(null).build(); } URI relativeURI = UriBuilder.fromUri(path).replaceQuery(absoluteURI.getRawQuery()).build(); // System.out.println("path: " + path); // System.out.println("query string: " + request.getQueryString()); ResteasyUriInfo uriInfo = new ResteasyUriInfo(baseURI, relativeURI); return uriInfo; }