From ce6a9dbc36941392ec1566a48b1bd6f012dc4ed1 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 11 Sep 2018 08:27:34 -0400 Subject: [PATCH] Fix regression from new jetty version --- .../main/java/ca/uhn/fhir/util/UrlUtil.java | 3 +- .../uhn/fhir/rest/server/RestfulServer.java | 15 +++++++- ...ompressOutgoingContentInterceptorTest.java | 35 +++++++++---------- 3 files changed, 33 insertions(+), 20 deletions(-) rename {hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/interceptor => hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client}/CompressOutgoingContentInterceptorTest.java (86%) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/UrlUtil.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/UrlUtil.java index 3482eba69bf..1834dcbf9ae 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/UrlUtil.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/util/UrlUtil.java @@ -14,6 +14,7 @@ import java.util.*; import java.util.Map.Entry; import static org.apache.commons.lang3.StringUtils.defaultIfBlank; +import static org.apache.commons.lang3.StringUtils.defaultString; import static org.apache.commons.lang3.StringUtils.isBlank; /* @@ -182,7 +183,7 @@ public class UrlUtil { } private static void parseQueryString(String theQueryString, HashMap> map) { - String query = theQueryString; + String query = defaultString(theQueryString); if (query.startsWith("?")) { query = query.substring(1); } diff --git a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java index 55f2d1a9611..c3d439939a6 100644 --- a/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java +++ b/hapi-fhir-server/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java @@ -824,7 +824,20 @@ public class RestfulServer extends HttpServlet implements IRestfulServer(theRequest.getParameterMap()); + + // If the request is coming in with a content-encoding, don't try to + // load the params from the content. + if (isNotBlank(theRequest.getHeader(Constants.HEADER_CONTENT_ENCODING))) { + if (isNotBlank(theRequest.getQueryString())) { + params = UrlUtil.parseQueryString(theRequest.getQueryString()); + } else { + params = Collections.emptyMap(); + } + } + + if (params == null) { + params = new HashMap<>(theRequest.getParameterMap()); + } } requestDetails.setParameters(params); diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/interceptor/CompressOutgoingContentInterceptorTest.java b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/CompressOutgoingContentInterceptorTest.java similarity index 86% rename from hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/interceptor/CompressOutgoingContentInterceptorTest.java rename to hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/CompressOutgoingContentInterceptorTest.java index 3711e68eebb..bc1914d01f9 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/client/interceptor/CompressOutgoingContentInterceptorTest.java +++ b/hapi-fhir-structures-r4/src/test/java/ca/uhn/fhir/rest/client/CompressOutgoingContentInterceptorTest.java @@ -1,17 +1,6 @@ -package ca.uhn.fhir.rest.client.interceptor; - -import static org.junit.Assert.assertEquals; - -import javax.servlet.http.HttpServletRequest; - -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.servlet.ServletHandler; -import org.eclipse.jetty.servlet.ServletHolder; -import org.junit.*; +package ca.uhn.fhir.rest.client; import ca.uhn.fhir.context.FhirContext; -import ca.uhn.fhir.model.api.IResource; -import ca.uhn.fhir.model.dstu2.resource.Patient; import ca.uhn.fhir.model.primitive.IdDt; import ca.uhn.fhir.rest.annotation.Create; import ca.uhn.fhir.rest.annotation.ResourceParam; @@ -19,14 +8,25 @@ import ca.uhn.fhir.rest.api.Constants; import ca.uhn.fhir.rest.api.MethodOutcome; import ca.uhn.fhir.rest.client.apache.GZipContentInterceptor; import ca.uhn.fhir.rest.client.api.IGenericClient; -import ca.uhn.fhir.rest.server.*; +import ca.uhn.fhir.rest.server.FifoMemoryPagingProvider; +import ca.uhn.fhir.rest.server.IResourceProvider; +import ca.uhn.fhir.rest.server.RestfulServer; import ca.uhn.fhir.util.PortUtil; import ca.uhn.fhir.util.TestUtil; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.servlet.ServletHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.hl7.fhir.r4.model.Patient; +import org.junit.*; + +import javax.servlet.http.HttpServletRequest; + +import static org.junit.Assert.assertEquals; public class CompressOutgoingContentInterceptorTest { private static IGenericClient ourClient; - private static FhirContext ourCtx = FhirContext.forDstu2(); + private static FhirContext ourCtx = FhirContext.forR4(); private static Patient ourLastPatient; private static String ourLastReq; private static String ourLastResponseEncoding; @@ -44,11 +44,11 @@ public class CompressOutgoingContentInterceptorTest { ourClient.registerInterceptor(new GZipContentInterceptor()); Patient p = new Patient(); - p.addName().addFamily("FAMILY"); + p.addName().setFamily("FAMILY"); ourClient.create().resource(p).execute(); - assertEquals("FAMILY", p.getName().get(0).getFamily().get(0).getValue()); + Assert.assertEquals("FAMILY", p.getName().get(0).getFamily()); assertEquals("gzip", ourLastReq); assertEquals("gzip", ourLastResponseEncoding); } @@ -76,7 +76,6 @@ public class CompressOutgoingContentInterceptorTest { proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); ourServer.start(); - } public static class DummyPatientResourceProvider implements IResourceProvider { @@ -90,7 +89,7 @@ public class CompressOutgoingContentInterceptorTest { } @Override - public Class getResourceType() { + public Class getResourceType() { return Patient.class; }