From a1d69f05bbbb342d574e8a1fb411d2e83b9b8f17 Mon Sep 17 00:00:00 2001 From: peacekeeper Date: Mon, 6 Mar 2017 11:39:53 +0100 Subject: [PATCH] alternative way of constructing HTTP request --- .../servlet/ServletHttpTransportRequest.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/transport-http/src/main/java/xdi2/transport/impl/http/impl/servlet/ServletHttpTransportRequest.java b/transport-http/src/main/java/xdi2/transport/impl/http/impl/servlet/ServletHttpTransportRequest.java index 9886f87b..f9927ad1 100644 --- a/transport-http/src/main/java/xdi2/transport/impl/http/impl/servlet/ServletHttpTransportRequest.java +++ b/transport-http/src/main/java/xdi2/transport/impl/http/impl/servlet/ServletHttpTransportRequest.java @@ -34,10 +34,7 @@ private ServletHttpTransportRequest(HttpServletRequest httpServletRequest, Strin public static ServletHttpTransportRequest fromHttpServletRequest(HttpServletRequest httpServletRequest) { - // determine request path - - String requestUri = httpServletRequest.getRequestURI(); - if (log.isDebugEnabled()) log.debug("Request URI: " + requestUri); + // determine base path String contextPath = httpServletRequest.getContextPath(); if (contextPath.endsWith("/")) contextPath = contextPath.substring(0, contextPath.length() - 1); @@ -45,7 +42,22 @@ public static ServletHttpTransportRequest fromHttpServletRequest(HttpServletRequ String servletPath = httpServletRequest.getServletPath(); if (servletPath.endsWith("/")) servletPath = servletPath.substring(0, servletPath.length() - 1); - String requestPath = requestUri.substring(contextPath.length() + servletPath.length()); + String basePath = contextPath + servletPath; + if (basePath.endsWith("/")) basePath = basePath.substring(0, basePath.length() - 1); + + // done + + return fromHttpServletRequest(httpServletRequest, basePath); + } + + public static ServletHttpTransportRequest fromHttpServletRequest(HttpServletRequest httpServletRequest, String basePath) { + + // determine request path + + String requestUri = httpServletRequest.getRequestURI(); + if (log.isDebugEnabled()) log.debug("Request URI: " + requestUri); + + String requestPath = requestUri.substring(basePath.length()); if (! requestPath.startsWith("/")) requestPath = "/" + requestPath; try {