Check for a null response resource in the ResponseHighlighterInterceptor (#4407)
* Check for a null request resource in the ResponseHighlighterInterceptor when handling the response. * Small fix to check the right resource, namely, the response resource, not the request resource. * Check for theGraphqlResponse being null also, as otherwise this breaks a unit test. * Add a new test to ResponseHighlighterInterceptor.
This commit is contained in:
parent
31e4f039ff
commit
21f497574a
|
@ -430,6 +430,10 @@ public class ResponseHighlighterInterceptor {
|
||||||
|
|
||||||
|
|
||||||
private boolean handleOutgoingResponse(RequestDetails theRequestDetails, ResponseDetails theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse, String theGraphqlResponse, IBaseResource theResourceResponse) {
|
private boolean handleOutgoingResponse(RequestDetails theRequestDetails, ResponseDetails theResponseObject, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse, String theGraphqlResponse, IBaseResource theResourceResponse) {
|
||||||
|
if (theResourceResponse == null && theGraphqlResponse == null) {
|
||||||
|
// this will happen during, for example, a bulk export polling request
|
||||||
|
return true;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Request for _raw
|
* Request for _raw
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -15,8 +15,10 @@ import ca.uhn.fhir.rest.annotation.Search;
|
||||||
import ca.uhn.fhir.rest.api.Constants;
|
import ca.uhn.fhir.rest.api.Constants;
|
||||||
import ca.uhn.fhir.rest.api.EncodingEnum;
|
import ca.uhn.fhir.rest.api.EncodingEnum;
|
||||||
import ca.uhn.fhir.rest.api.RequestTypeEnum;
|
import ca.uhn.fhir.rest.api.RequestTypeEnum;
|
||||||
|
import ca.uhn.fhir.rest.api.server.RequestDetails;
|
||||||
import ca.uhn.fhir.rest.api.server.ResponseDetails;
|
import ca.uhn.fhir.rest.api.server.ResponseDetails;
|
||||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||||
|
import ca.uhn.fhir.rest.server.IRestfulServerDefaults;
|
||||||
import ca.uhn.fhir.rest.server.RestfulServer;
|
import ca.uhn.fhir.rest.server.RestfulServer;
|
||||||
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
|
||||||
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
|
||||||
|
@ -57,6 +59,7 @@ import java.io.StringWriter;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -868,6 +871,30 @@ public class ResponseHighlightingInterceptorTest {
|
||||||
assertThat(responseContent, (containsStringIgnoringCase("Content-Type")));
|
assertThat(responseContent, (containsStringIgnoringCase("Content-Type")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testNullResponseResource() {
|
||||||
|
ourInterceptor.setShowResponseHeaders(true);
|
||||||
|
|
||||||
|
final RequestDetails requestDetails = mock(RequestDetails.class);
|
||||||
|
when(requestDetails.getRequestType()).thenReturn(RequestTypeEnum.GET);
|
||||||
|
final IRestfulServerDefaults server = mock(IRestfulServerDefaults.class);
|
||||||
|
when(server.getDefaultResponseEncoding()).thenReturn(EncodingEnum.JSON);
|
||||||
|
when(server.getFhirContext()).thenReturn(ourCtx);
|
||||||
|
when(requestDetails.getServer()).thenReturn(server);
|
||||||
|
|
||||||
|
final ResponseDetails responseObject = mock(ResponseDetails.class);
|
||||||
|
|
||||||
|
final HttpServletRequest servletRequest = mock(HttpServletRequest.class);
|
||||||
|
final Enumeration<String> headers = mock(Enumeration.class);
|
||||||
|
when(headers.hasMoreElements()).thenReturn(true).thenReturn(false);
|
||||||
|
when(headers.nextElement()).thenReturn("text/html");
|
||||||
|
when(servletRequest.getHeaders(Constants.HEADER_ACCEPT)).thenReturn(headers);
|
||||||
|
|
||||||
|
final HttpServletResponse servletResponse = mock(HttpServletResponse.class);
|
||||||
|
|
||||||
|
assertTrue(ourInterceptor.outgoingResponse(requestDetails, responseObject, servletRequest, servletResponse));
|
||||||
|
}
|
||||||
|
|
||||||
@AfterAll
|
@AfterAll
|
||||||
public static void afterClassClearContext() throws Exception {
|
public static void afterClassClearContext() throws Exception {
|
||||||
JettyUtil.closeServer(ourServer);
|
JettyUtil.closeServer(ourServer);
|
||||||
|
|
Loading…
Reference in New Issue