From 4c998d2f1b2c39a6f44ce97a2cd7298113d66468 Mon Sep 17 00:00:00 2001 From: harsha89 Date: Thu, 15 Jan 2015 14:38:33 +0530 Subject: [PATCH] extracting request path generating code to protected method in order to users to have their own mapping to FHIR HAPI rest server #85 --- .../ca/uhn/fhir/rest/server/RestfulServer.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java index 450aed7af83..bb44d6ac459 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java @@ -166,7 +166,7 @@ public class RestfulServer extends HttpServlet { /** * Count length of URL string, but treating unescaped sequences (e.g. ' ') as their unescaped equivalent (%20) */ - private int escapedLength(String theServletPath) { + protected int escapedLength(String theServletPath) { int delta = 0; for (int i = 0; i < theServletPath.length(); i++) { char next = theServletPath.charAt(i); @@ -480,13 +480,11 @@ public class RestfulServer extends HttpServlet { String operation = null; String compartment = null; - String requestPath = requestFullPath.substring(escapedLength(servletContextPath) + escapedLength(servletPath)); + String requestPath = getRequestPath(requestFullPath, servletContextPath, servletPath); if (requestPath.length() > 0 && requestPath.charAt(0) == '/') { requestPath = requestPath.substring(1); } - fhirServerBase = getServerBaseForRequest(theRequest); - String completeUrl = StringUtils.isNotBlank(theRequest.getQueryString()) ? requestUrl + "?" + theRequest.getQueryString() : requestUrl.toString(); Map params = new HashMap(theRequest.getParameterMap()); @@ -1493,4 +1491,16 @@ public class RestfulServer extends HttpServlet { } } + /** + * Allows users of RestfulServer to override the getRequestPath method to let them build their custom request path + * implementation + * + * @param requestFullPath the full request path + * @param servletContextPath the servelet context path + * @param servletPath the servelet path + * @return created resource path + */ + protected String getRequestPath(String requestFullPath, String servletContextPath, String servletPath) { + return requestFullPath.substring(escapedLength(servletContextPath) + escapedLength(servletPath)); + } }