From ce879b38637b9e301530a36371ebc679f392600b Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 20 Aug 2019 08:35:27 -0400 Subject: [PATCH 1/2] Fix versioned API incompatibility with GraphQL --- .../server/VersionedApiConverterInterceptor.java | 6 +++++- .../registry/BaseSearchParamRegistry.java | 2 +- .../ResponseHighlightingInterceptorTest.java | 15 +++++++++++++++ src/changes/changes.xml | 4 ++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/server/VersionedApiConverterInterceptor.java b/hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/server/VersionedApiConverterInterceptor.java index 5c0dba29a2f..1e43400f641 100644 --- a/hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/server/VersionedApiConverterInterceptor.java +++ b/hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/server/VersionedApiConverterInterceptor.java @@ -69,6 +69,11 @@ public class VersionedApiConverterInterceptor extends InterceptorAdapter { @Override public boolean outgoingResponse(RequestDetails theRequestDetails, ResponseDetails theResponseDetails, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws AuthenticationException { + IBaseResource responseResource = theResponseDetails.getResponseResource(); + if (responseResource == null) { + return true; + } + String[] formatParams = theRequestDetails.getParameters().get(Constants.PARAM_FORMAT); String accept = null; if (formatParams != null && formatParams.length > 0) { @@ -92,7 +97,6 @@ public class VersionedApiConverterInterceptor extends InterceptorAdapter { wantVersion = FhirVersionEnum.forVersionString(wantVersionString); } - IBaseResource responseResource = theResponseDetails.getResponseResource(); FhirVersionEnum haveVersion = responseResource.getStructureFhirVersionEnum(); IBaseResource converted = null; diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/registry/BaseSearchParamRegistry.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/registry/BaseSearchParamRegistry.java index f0a9b3bac6d..cfe084e6096 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/registry/BaseSearchParamRegistry.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/registry/BaseSearchParamRegistry.java @@ -70,7 +70,7 @@ public abstract class BaseSearchParamRegistry implemen private volatile Map> myActiveSearchParams; private volatile long myLastRefresh; - @Autowired + @autowired private IInterceptorBroadcaster myInterceptorBroadcaster; @Override diff --git a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/interceptor/ResponseHighlightingInterceptorTest.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/interceptor/ResponseHighlightingInterceptorTest.java index 59a36e486dc..5c29017e28d 100644 --- a/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/interceptor/ResponseHighlightingInterceptorTest.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/server/interceptor/ResponseHighlightingInterceptorTest.java @@ -403,6 +403,21 @@ public class ResponseHighlightingInterceptorTest { } + @Test + public void testHighlightGraphQLResponseNonHighlighted() throws Exception { + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/A/$graphql?query=" + UrlUtil.escapeUrlParam("{name}")); + httpGet.addHeader("Accept", "application/jon"); + CloseableHttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent(), Charsets.UTF_8); + status.close(); + + ourLog.info("Resp: {}", responseContent); + assertEquals(200, status.getStatusLine().getStatusCode()); + + assertThat(responseContent, stringContainsInOrder("{\"foo\":\"bar\"}")); + + } + @Test public void testHighlightException() throws Exception { ResponseHighlighterInterceptor ic = ourInterceptor; diff --git a/src/changes/changes.xml b/src/changes/changes.xml index f8ddff5e88b..1fc9a9a63ec 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -44,6 +44,10 @@ SubscriptionDstu2Config incorrectly pointed to a DSTU3 configuration file. This has been corrected. + + When using the VersionedApiConverterInterceptor, GraphQL responses failed with an HTTP + 500 error. + From 84836aed8477c25dc8a799833d8bb3324513f1e2 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 20 Aug 2019 08:39:46 -0400 Subject: [PATCH 2/2] Fix accidental typo --- .../fhir/jpa/searchparam/registry/BaseSearchParamRegistry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/registry/BaseSearchParamRegistry.java b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/registry/BaseSearchParamRegistry.java index cfe084e6096..f0a9b3bac6d 100644 --- a/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/registry/BaseSearchParamRegistry.java +++ b/hapi-fhir-jpaserver-searchparam/src/main/java/ca/uhn/fhir/jpa/searchparam/registry/BaseSearchParamRegistry.java @@ -70,7 +70,7 @@ public abstract class BaseSearchParamRegistry implemen private volatile Map> myActiveSearchParams; private volatile long myLastRefresh; - @autowired + @Autowired private IInterceptorBroadcaster myInterceptorBroadcaster; @Override