extracting request path generating code to protected method in order to users to have their own mapping to FHIR HAPI rest server #85

This commit is contained in:
harsha89 2015-01-15 14:38:33 +05:30
parent 8e73705000
commit 4c998d2f1b
1 changed files with 14 additions and 4 deletions

View File

@ -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<String, String[]> params = new HashMap<String, String[]>(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));
}
}