69 lines
2.4 KiB
Plaintext
69 lines
2.4 KiB
Plaintext
@Override
|
|
public void invokeServer(RestfulServer theServer, Request theRequest, HttpServletResponse theResponse) throws BaseServerResponseException, IOException {
|
|
EncodingUtil encoding = BaseMethodBinding.determineResponseEncoding(theRequest.getServletRequest(), theRequest.getParameters());
|
|
IParser parser = encoding.newParser(getContext());
|
|
IResource resource = parser.parseResource(theRequest.getInputReader());
|
|
|
|
Object[] params = new Object[getParameters().size()];
|
|
for (int i = 0; i < getParameters().size(); i++) {
|
|
IParameter param = getParameters().get(i);
|
|
if (param == null) {
|
|
continue;
|
|
}
|
|
params[i] = param.translateQueryParametersIntoServerArgument(theRequest, resource);
|
|
}
|
|
|
|
addParametersForServerRequest(theRequest, params);
|
|
|
|
MethodOutcome response;
|
|
try {
|
|
response = (MethodOutcome) invokeServerMethod(getProvider(), params);
|
|
} catch (BaseServerResponseException e) {
|
|
streamOperationOutcome(e, theServer, encoding, theResponse);
|
|
return;
|
|
}
|
|
|
|
if (response == null) {
|
|
if (isReturnVoid() == false) {
|
|
throw new ConfigurationException("Method " + getMethod().getName() + " in type " + getMethod().getDeclaringClass().getCanonicalName() + " returned null");
|
|
}
|
|
} else if (!isReturnVoid()) {
|
|
if (response.isCreated()) {
|
|
theResponse.setStatus(Constants.STATUS_HTTP_201_CREATED);
|
|
StringBuilder b = new StringBuilder();
|
|
b.append(theRequest.getFhirServerBase());
|
|
b.append('/');
|
|
b.append(getResourceName());
|
|
b.append('/');
|
|
b.append(response.getId().getValue());
|
|
if (response.getVersionId() != null && response.getVersionId().isEmpty() == false) {
|
|
b.append("/_history/");
|
|
b.append(response.getVersionId().getValue());
|
|
}
|
|
theResponse.addHeader("Location", b.toString());
|
|
} else {
|
|
theResponse.setStatus(Constants.STATUS_HTTP_200_OK);
|
|
}
|
|
} else {
|
|
theResponse.setStatus(Constants.STATUS_HTTP_204_NO_CONTENT);
|
|
}
|
|
|
|
theServer.addHeadersToResponse(theResponse);
|
|
|
|
if (response != null && response.getOperationOutcome() != null) {
|
|
theResponse.setContentType(encoding.getResourceContentType());
|
|
Writer writer = theResponse.getWriter();
|
|
try {
|
|
parser.encodeResourceToWriter(response.getOperationOutcome(), writer);
|
|
} finally {
|
|
writer.close();
|
|
}
|
|
} else {
|
|
theResponse.setContentType(Constants.CT_TEXT);
|
|
Writer writer = theResponse.getWriter();
|
|
writer.close();
|
|
}
|
|
|
|
// getMethod().in
|
|
}
|