From de5aeb5c7a1146eb11ec4e2c86b48f989ce918d4 Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 29 Jul 2014 17:27:16 -0400 Subject: [PATCH] More tests --- .../fhir/rest/gclient/IClientExecutable.java | 2 ++ .../ca/uhn/fhir/rest/server/Constants.java | 26 +++++++++---------- .../uhn/fhir/rest/server/RestfulServer.java | 2 +- .../fhir/rest/server/ServerFeaturesTest.java | 8 ++++++ 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/IClientExecutable.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/IClientExecutable.java index 7f803ad2d70..ccbdcd8f99c 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/IClientExecutable.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/gclient/IClientExecutable.java @@ -32,6 +32,8 @@ public interface IClientExecutable, Y> { /** * If set to true, the client will log the request and response to the SLF4J logger. This can be useful for * debugging, but is generally not desirable in a production situation. + * + * @deprecated Use the client logging interceptor to log requests and responses instead. See here for more information. */ T andLogRequestAndResponse(boolean theLogRequestAndResponse); diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Constants.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Constants.java index 22747f967f4..b406cba4d51 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Constants.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Constants.java @@ -28,31 +28,39 @@ import java.util.Set; public class Constants { - public static final String HEADER_CORS_EXPOSE_HEADERS = "Access-Control-Expose-Headers"; - public static final String HEADER_CORS_ALLOW_METHODS = "Access-Control-Allow-Methods"; - public static final String HEADER_CORS_ALLOW_ORIGIN = "Access-Control-Allow-Origin"; - public static final String CHARSET_UTF_8 = "UTF-8"; public static final String CT_ATOM_XML = "application/atom+xml"; public static final String CT_FHIR_JSON = "application/json+fhir"; + public static final String CT_FHIR_XML = "application/xml+fhir"; public static final String CT_HTML = "text/html"; public static final String CT_JSON = "application/json"; public static final String CT_OCTET_STREAM = "application/octet-stream"; public static final String CT_TEXT = "text/plain"; public static final String CT_XML = "application/xml"; + public static final String ENCODING_GZIP = "gzip"; public static final String FORMAT_JSON = "json"; public static final Set FORMAT_VAL_JSON; public static final Map FORMAT_VAL_TO_ENCODING; public static final Set FORMAT_VAL_XML; public static final String FORMAT_XML = "xml"; public static final String HEADER_ACCEPT = "Accept"; + public static final String HEADER_ACCEPT_ENCODING = "Accept-Encoding"; + public static final String HEADER_AUTHORIZATION = "Authorization"; public static final String HEADER_CATEGORY = "Category"; + public static final String HEADER_CONTENT_DISPOSITION = "Content-Disposition"; + public static final String HEADER_CONTENT_ENCODING = "Content-Encoding"; public static final String HEADER_CONTENT_LOCATION = "Content-Location"; public static final String HEADER_CONTENT_LOCATION_LC = HEADER_CONTENT_LOCATION.toLowerCase(); public static final String HEADER_CONTENT_TYPE = "Content-Type"; + public static final String HEADER_CORS_ALLOW_METHODS = "Access-Control-Allow-Methods"; + public static final String HEADER_CORS_ALLOW_ORIGIN = "Access-Control-Allow-Origin"; + public static final String HEADER_CORS_EXPOSE_HEADERS = "Access-Control-Expose-Headers"; public static final String HEADER_LAST_MODIFIED = "Last-Modified"; public static final String HEADER_LAST_MODIFIED_LOWERCASE = HEADER_LAST_MODIFIED.toLowerCase(); + public static final String HEADER_LOCATION = "Location"; + public static final String HEADER_LOCATION_LC = HEADER_LOCATION.toLowerCase(); + public static final String HEADERVALUE_CORS_ALLOW_METHODS_ALL = "GET, POST, PUT, DELETE"; public static final String OPENSEARCH_NS_OLDER = "http://purl.org/atompub/tombstones/1.0"; public static final String PARAM_COUNT = "_count"; public static final String PARAM_DELETE = "_delete"; @@ -73,6 +81,7 @@ public class Constants { public static final String PARAM_TAGS = "_tags"; public static final String PARAM_VALIDATE = "_validate"; public static final String PARAMQUALIFIER_STRING_EXACT = ":exact"; + public static final String PARAMQUALIFIER_TOKEN_TEXT = ":text"; public static final int STATUS_HTTP_200_OK = 200; public static final int STATUS_HTTP_201_CREATED = 201; public static final int STATUS_HTTP_204_NO_CONTENT = 204; @@ -87,15 +96,6 @@ public class Constants { public static final int STATUS_HTTP_500_INTERNAL_ERROR = 500; public static final int STATUS_HTTP_501_NOT_IMPLEMENTED = 501; public static final String URL_TOKEN_HISTORY = "_history"; - public static final String HEADER_ACCEPT_ENCODING = "Accept-Encoding"; - public static final String HEADER_CONTENT_ENCODING = "Content-Encoding"; - public static final String ENCODING_GZIP = "gzip"; - public static final String HEADER_LOCATION = "Location"; - public static final String HEADER_LOCATION_LC = HEADER_LOCATION.toLowerCase(); - public static final String HEADERVALUE_CORS_ALLOW_METHODS_ALL = "GET, POST, PUT, DELETE"; - public static final String HEADER_AUTHORIZATION = "Authorization"; - public static final String PARAMQUALIFIER_TOKEN_TEXT = ":text"; - public static final String HEADER_CONTENT_DISPOSITION = "Content-Disposition"; static { diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java index 9814223c2d6..2d8e66ba506 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/RestfulServer.java @@ -500,7 +500,7 @@ public class RestfulServer extends HttpServlet { } if (theRequestType == RequestType.PUT && versionId == null) { - String contentLocation = theRequest.getHeader("Content-Location"); + String contentLocation = theRequest.getHeader(Constants.HEADER_CONTENT_LOCATION); if (contentLocation != null) { versionId = new IdDt(contentLocation); } diff --git a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java index e3515ad714c..7fa8fcb8dc6 100644 --- a/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java +++ b/hapi-fhir-base/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java @@ -231,6 +231,14 @@ public class ServerFeaturesTest { assertThat(responseContent, StringContains.containsString("\",\n")); + httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1"); + httpGet.addHeader("Accept", Constants.CT_FHIR_JSON + "; pretty=true" + ", " + Constants.CT_FHIR_XML + "; pretty=true"); + status = ourClient.execute(httpGet); + responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertThat(responseContent, StringContains.containsString("\"identifier\":")); + } @Test