public static UriInfoImpl extractUriInfo(HttpServletRequest request, String servletPrefix) { String contextPath = request.getContextPath(); if (servletPrefix != null && servletPrefix.length() > 0) { if (!contextPath.endsWith("/") && !servletPrefix.startsWith("/")) contextPath += "/"; contextPath += servletPrefix; } URI absolutePath = null; try { URL absolute = new URL(request.getRequestURL().toString()); UriBuilderImpl builder = new UriBuilderImpl(); builder.scheme(absolute.getProtocol()); builder.host(absolute.getHost()); builder.port(absolute.getPort()); builder.path(absolute.getPath()); builder.replaceQuery(absolute.getQuery()); absolutePath = builder.build(); } catch (MalformedURLException e) { throw new RuntimeException(e); } String path = PathHelper.getEncodedPathInfo(absolutePath.getRawPath(), contextPath); List<PathSegment> pathSegments = PathSegmentImpl.parseSegments(path, false); URI baseURI = absolutePath; if (!path.trim().equals("")) { String tmpContextPath = contextPath; if (!tmpContextPath.endsWith("/")) tmpContextPath += "/"; baseURI = UriBuilder.fromUri(absolutePath).replacePath(tmpContextPath).build(); } // System.out.println("path: " + path); // System.out.println("query string: " + request.getQueryString()); UriInfoImpl uriInfo = new UriInfoImpl(absolutePath, baseURI, path, request.getQueryString(), pathSegments); return uriInfo; }