Skip to content

Commit

Permalink
alternative way of constructing HTTP request
Browse files Browse the repository at this point in the history
  • Loading branch information
peacekeeper committed Mar 6, 2017
1 parent 2b73088 commit a1d69f0
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,30 @@ 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);

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 {
Expand Down

0 comments on commit a1d69f0

Please sign in to comment.