} else if (resourceName == null) {
resourceBinding = myNullResourceBinding;
} else {
resourceBinding = myResourceNameToProvider.get(resourceName);
if (resourceBinding == null) {
throw new InvalidRequestException("Unknown resource type '" + resourceName + "' - Server knows how to handle: " + myResourceNameToProvider.keySet());
}
}
if (tok.hasMoreTokens()) {
String nextString = tok.nextToken();
if (nextString.startsWith("_")) {
operation = nextString;
} else {
id = new IdDt(resourceName, nextString);
}
}
if (tok.hasMoreTokens()) {
String nextString = tok.nextToken();
if (nextString.equals(Constants.PARAM_HISTORY)) {
if (tok.hasMoreTokens()) {
String versionString = tok.nextToken();
if (id == null) {
throw new InvalidRequestException("Don't know how to handle request path: " + requestPath);
}
id = new IdDt(resourceName + "/" + id.getIdPart() + "/_history/" + versionString);
versionId = id;
} else {
operation = Constants.PARAM_HISTORY;
}
} else if (nextString.startsWith("_")) {
if (operation != null) {
throw new InvalidRequestException("URL Path contains two operations (part beginning with _): " + requestPath);
}
operation = nextString;
}
}
// Secondary is for things like ..../_tags/_delete
String secondaryOperation = null;
while (tok.hasMoreTokens()) {
String nextString = tok.nextToken();
if (operation == null) {
operation = nextString;
} else if (secondaryOperation == null) {
secondaryOperation = nextString;
} else {
throw new InvalidRequestException("URL path has unexpected token '" + nextString + "' at the end: " + requestPath);
}
}
if (theRequestType == RequestType.PUT && versionId == null) {
String contentLocation = theRequest.getHeader("Content-Location");
if (contentLocation != null) {
versionId = new IdDt(contentLocation);
}
}
// TODO: look for more tokens for version, compartments, etc...
String acceptEncoding = theRequest.getHeader(Constants.HEADER_ACCEPT_ENCODING);
boolean respondGzip = false;
if (acceptEncoding != null) {
String[] parts = acceptEncoding.trim().split("\\s*,\\s*");
for (String string : parts) {
if (string.equals("gzip")) {
respondGzip = true;
}
}
}
Request r = new Request();
r.setResourceName(resourceName);
r.setId(id);
r.setVersion(versionId);
r.setOperation(operation);
r.setSecondaryOperation(secondaryOperation);
r.setParameters(params);
r.setRequestType(theRequestType);
r.setFhirServerBase(fhirServerBase);
r.setCompleteUrl(completeUrl);
r.setServletRequest(theRequest);
r.setServletResponse(theResponse);
r.setRespondGzip(respondGzip);
String pagingAction = theRequest.getParameter(Constants.PARAM_PAGINGACTION);
if (getPagingProvider() != null && isNotBlank(pagingAction)) {
handlePagingRequest(r, theResponse, pagingAction);
return;
}
if (resourceMethod == null && resourceBinding != null) {
resourceMethod = resourceBinding.getMethod(r);
}
if (null == resourceMethod) {
StringBuilder b = new StringBuilder();
b.append("No resource method available for ");
b.append(theRequestType.name());
b.append(" operation[");
b.append(requestPath);
b.append("]");
b.append(" with parameters ");
b.append(params.keySet());
throw new InvalidRequestException(b.toString());
}
resourceMethod.invokeServer(this, r, theResponse);
} catch (AuthenticationException e) {