Fix #128 - Regression in 0.9 - Server fails with an HTTP 500 and NPE if
the client requests an unknown resource type
This commit is contained in:
parent
1598e7ec5a
commit
5ee0286914
|
@ -496,7 +496,9 @@ public class RestfulServer extends HttpServlet {
|
|||
|
||||
String fhirServerBase = null;
|
||||
boolean requestIsBrowser = requestIsBrowser(theRequest);
|
||||
Request requestDetails = null;
|
||||
Request requestDetails = new Request();
|
||||
requestDetails.setServer(this);
|
||||
|
||||
try {
|
||||
|
||||
String resourceName = null;
|
||||
|
@ -533,6 +535,7 @@ public class RestfulServer extends HttpServlet {
|
|||
String completeUrl = StringUtils.isNotBlank(theRequest.getQueryString()) ? requestUrl + "?" + theRequest.getQueryString() : requestUrl.toString();
|
||||
|
||||
Map<String, String[]> params = new HashMap<String, String[]>(theRequest.getParameterMap());
|
||||
requestDetails.setParameters(params);
|
||||
|
||||
StringTokenizer tok = new StringTokenizer(requestPath, "/");
|
||||
if (tok.hasMoreTokens()) {
|
||||
|
@ -542,6 +545,7 @@ public class RestfulServer extends HttpServlet {
|
|||
resourceName = null;
|
||||
}
|
||||
}
|
||||
requestDetails.setResourceName(resourceName);
|
||||
|
||||
ResourceBinding resourceBinding = null;
|
||||
BaseMethodBinding<?> resourceMethod = null;
|
||||
|
@ -608,6 +612,10 @@ public class RestfulServer extends HttpServlet {
|
|||
id = new IdDt(contentLocation);
|
||||
}
|
||||
}
|
||||
requestDetails.setId(id);
|
||||
requestDetails.setOperation(operation);
|
||||
requestDetails.setSecondaryOperation(secondaryOperation);
|
||||
requestDetails.setCompartmentName(compartment);
|
||||
|
||||
// TODO: look for more tokens for version, compartments, etc...
|
||||
|
||||
|
@ -621,21 +629,13 @@ public class RestfulServer extends HttpServlet {
|
|||
}
|
||||
}
|
||||
}
|
||||
requestDetails.setRespondGzip(respondGzip);
|
||||
|
||||
requestDetails = new Request();
|
||||
requestDetails.setServer(this);
|
||||
requestDetails.setResourceName(resourceName);
|
||||
requestDetails.setId(id);
|
||||
requestDetails.setOperation(operation);
|
||||
requestDetails.setSecondaryOperation(secondaryOperation);
|
||||
requestDetails.setParameters(params);
|
||||
requestDetails.setRequestType(theRequestType);
|
||||
requestDetails.setFhirServerBase(fhirServerBase);
|
||||
requestDetails.setCompleteUrl(completeUrl);
|
||||
requestDetails.setServletRequest(theRequest);
|
||||
requestDetails.setServletResponse(theResponse);
|
||||
requestDetails.setRespondGzip(respondGzip);
|
||||
requestDetails.setCompartmentName(compartment);
|
||||
|
||||
String pagingAction = theRequest.getParameter(Constants.PARAM_PAGINGACTION);
|
||||
if (getPagingProvider() != null && isNotBlank(pagingAction)) {
|
||||
|
@ -660,8 +660,6 @@ public class RestfulServer extends HttpServlet {
|
|||
b.append(params.keySet());
|
||||
throw new InvalidRequestException(b.toString());
|
||||
}
|
||||
|
||||
requestDetails = requestDetails;
|
||||
requestDetails.setResourceOperationType(resourceMethod.getResourceOperationType());
|
||||
requestDetails.setSystemOperationType(resourceMethod.getSystemOperationType());
|
||||
requestDetails.setOtherOperationType(resourceMethod.getOtherOperationType());
|
||||
|
|
|
@ -60,7 +60,6 @@ public class ExceptionHandlingInterceptor extends InterceptorAdapter {
|
|||
|
||||
@Override
|
||||
public boolean handleException(RequestDetails theRequestDetails, Throwable theException, HttpServletRequest theRequest, HttpServletResponse theResponse) throws ServletException, IOException {
|
||||
ourLog.error("AA", theException);
|
||||
BaseOperationOutcome oo = null;
|
||||
int statusCode = Constants.STATUS_HTTP_500_INTERNAL_ERROR;
|
||||
|
||||
|
|
|
@ -127,6 +127,19 @@ public class RestfulServerMethodTest {
|
|||
assertThat(responseContent, StringContains.containsString("AAAABBBB"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidResourceTriggers400() throws Exception {
|
||||
|
||||
HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/FooResource?blah=bar");
|
||||
HttpResponse status = ourClient.execute(httpGet);
|
||||
|
||||
String responseContent = IOUtils.toString(status.getEntity().getContent());
|
||||
IOUtils.closeQuietly(status.getEntity().getContent());
|
||||
|
||||
ourLog.info("Response was:\n{}", responseContent);
|
||||
|
||||
assertEquals(400, status.getStatusLine().getStatusCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateRangeParam() throws Exception {
|
||||
|
|
|
@ -35,6 +35,9 @@
|
|||
was updated after being deleted. Thanks to Elliott Lavy and Lloyd
|
||||
McKenzie for reporting!
|
||||
</action>
|
||||
<action type="fix" issue="128">
|
||||
Fix regression in 0.9 - Server responds with an HTTP 500 and a NullPointerException instead of an HTTP 400 and a useful error message if the client requests an unknown resource type
|
||||
</action>
|
||||
</release>
|
||||
<release version="0.9" date="2015-Mar-14">
|
||||
<action type="add">
|
||||
|
|
Loading…
Reference in New Issue