From 8a2f9ff9839e7d81b0d001fe6f4deab886b90e7b Mon Sep 17 00:00:00 2001
From: mochaholic
Date: Mon, 23 Feb 2015 21:10:38 -0700
Subject: [PATCH 1/2] Fixed this bug: the security labels wouldn't be encoded
if versionId or lastUpdated weren't present.
---
.../src/main/java/ca/uhn/fhir/parser/JsonParser.java | 9 +++++----
.../src/main/java/ca/uhn/fhir/parser/XmlParser.java | 12 ++++++++----
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java
index dad5d934391..09fb3a13618 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/JsonParser.java
@@ -670,14 +670,15 @@ public class JsonParser extends BaseParser implements IParser {
if (myContext.getVersion().getVersion().isNewerThan(FhirVersionEnum.DSTU1) && theResource instanceof IResource) {
IResource resource = (IResource) theResource;
- if (!ElementUtil.isEmpty(resource.getId().getVersionIdPart(), ResourceMetadataKeyEnum.UPDATED.get(resource))) {
+ //Object securityLabelRawObj =
+ List securityLabels = (List) resource.getResourceMetadata().get(ResourceMetadataKeyEnum.SECURITY_LABELS);
+ if (!ElementUtil.isEmpty(resource.getId().getVersionIdPart(), ResourceMetadataKeyEnum.UPDATED.get(resource))
+ || (securityLabels != null && !securityLabels.isEmpty())) {
theEventWriter.writeStartObject("meta");
writeOptionalTagWithTextNode(theEventWriter, "versionId", resource.getId().getVersionIdPart());
writeOptionalTagWithTextNode(theEventWriter, "lastUpdated", ResourceMetadataKeyEnum.UPDATED.get(resource));
- Object securityLabelRawObj = resource.getResourceMetadata().get(ResourceMetadataKeyEnum.SECURITY_LABELS);
- if (securityLabelRawObj != null) {
- List securityLabels = (List) securityLabelRawObj;
+ if (securityLabels != null) {
if (!securityLabels.isEmpty()) {
theEventWriter.writeStartArray("security");
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java
index 2564b674a11..ece6edf7fd9 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/XmlParser.java
@@ -747,8 +747,12 @@ public class XmlParser extends BaseParser implements IParser {
InstantDt updated = (InstantDt) resource.getResourceMetadata().get(ResourceMetadataKeyEnum.UPDATED);
+ //Object securityLabelRawObj = resource.getResourceMetadata().get(ResourceMetadataKeyEnum.SECURITY_LABELS);
+ List securityLabels = (List) resource.getResourceMetadata().get(ResourceMetadataKeyEnum.SECURITY_LABELS);
IdDt resourceId = resource.getId();
- if (resourceId != null && isNotBlank(resourceId.getVersionIdPart()) || (updated != null && !updated.isEmpty())) {
+ if (resourceId != null && isNotBlank(resourceId.getVersionIdPart())
+ || (updated != null && !updated.isEmpty())
+ || (securityLabels != null && !securityLabels.isEmpty())) {
theEventWriter.writeStartElement("meta");
String versionIdPart = resourceId.getVersionIdPart();
if (isBlank(versionIdPart)) {
@@ -758,9 +762,9 @@ public class XmlParser extends BaseParser implements IParser {
if (updated != null) {
writeOptionalTagWithValue(theEventWriter, "lastUpdated", updated.getValueAsString());
}
- Object securityLabelRawObj = resource.getResourceMetadata().get(ResourceMetadataKeyEnum.SECURITY_LABELS);
- if (securityLabelRawObj != null) {
- List securityLabels = (List) securityLabelRawObj;
+
+ if (securityLabels != null) {
+
if (!securityLabels.isEmpty()) {
for (BaseCodingDt securityLabel : securityLabels) {
From 3003b5e17bb10f91173763cd874d04b343a3c306 Mon Sep 17 00:00:00 2001
From: mochaholic
Date: Thu, 9 Apr 2015 07:25:09 -0600
Subject: [PATCH 2/2] Update to the latest upstream.
---
.../java/example/GenericClientExample.java | 100 +++++++++---------
.../java/ca/uhn/fhir/parser/ParserState.java | 4 +-
.../ca/uhn/fhir/rest/api/MethodOutcome.java | 2 +-
.../BaseOutcomeReturningMethodBinding.java | 4 +-
.../src/main/resources/fhir-spring-config.xml | 2 +
.../ca/uhn/fhirtest/TestRestfulServer.java | 8 +-
.../WEB-INF/hapi-fhir-server-config.xml | 9 ++
.../fhir/rest/client/GenericClientTest.java | 10 +-
.../ca/uhn/fhir/model/dstu2/FhirDstu2.java | 2 +-
src/site/xdoc/doc_rest_client.xml | 32 +++---
10 files changed, 96 insertions(+), 77 deletions(-)
diff --git a/examples/src/main/java/example/GenericClientExample.java b/examples/src/main/java/example/GenericClientExample.java
index 1c0b4de6569..135253caf6e 100644
--- a/examples/src/main/java/example/GenericClientExample.java
+++ b/examples/src/main/java/example/GenericClientExample.java
@@ -74,30 +74,30 @@ public class GenericClientExample {
// END SNIPPET: create
}
{
- Patient patient = new Patient();
- // START SNIPPET: createConditional
- // One form
- MethodOutcome outcome = client.create()
- .resource(patient)
- .conditionalByUrl("Patient?identifier=system%7C00001")
- .execute();
+ Patient patient = new Patient();
+ // START SNIPPET: createConditional
+ // One form
+ MethodOutcome outcome = client.create()
+ .resource(patient)
+ .conditionalByUrl("Patient?identifier=system%7C00001")
+ .execute();
- // Another form
- MethodOutcome outcome2 = client.create()
- .resource(patient)
- .conditional()
- .where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
- .execute();
-
- // This will return true if the server responded with an HTTP 201 created,
- // otherwise it will return null.
- Boolean created = outcome.getCreated();
-
- // The ID of the created, or the pre-existing resource
- IdDt id = outcome.getId();
- // END SNIPPET: createConditional
+ // Another form
+ MethodOutcome outcome2 = client.create()
+ .resource(patient)
+ .conditional()
+ .where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
+ .execute();
+
+ // This will return true if the server responded with an HTTP 201 created,
+ // otherwise it will return null.
+ Boolean created = outcome.getCreated();
+
+ // The ID of the created, or the pre-existing resource
+ IdDt id = outcome.getId();
+ // END SNIPPET: createConditional
}
- {
+ {
// START SNIPPET: update
Patient patient = new Patient();
// ..populate the patient object..
@@ -125,21 +125,21 @@ public class GenericClientExample {
// END SNIPPET: update
}
{
- Patient patient = new Patient();
- // START SNIPPET: updateConditional
- client.update()
- .resource(patient)
- .conditionalByUrl("Patient?identifier=system%7C00001")
- .execute();
-
- client.update()
- .resource(patient)
- .conditional()
- .where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
- .execute();
- // END SNIPPET: updateConditional
+ Patient patient = new Patient();
+ // START SNIPPET: updateConditional
+ client.update()
+ .resource(patient)
+ .conditionalByUrl("Patient?identifier=system%7C00001")
+ .execute();
+
+ client.update()
+ .resource(patient)
+ .conditional()
+ .where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
+ .execute();
+ // END SNIPPET: updateConditional
}
- {
+ {
// START SNIPPET: etagupdate
// First, let's retrive the latest version of a resource
// from the server
@@ -176,26 +176,26 @@ public class GenericClientExample {
}
{
// START SNIPPET: delete
- BaseOperationOutcome resp = client.delete().resourceById(new IdDt("Patient", "1234")).execute();
+ BaseOperationOutcome resp = client.delete().resourceById(new IdDt("Patient", "1234")).execute();
// outcome may be null if the server didn't return one
- if (resp != null) {
- OperationOutcome outcome = (OperationOutcome) resp;
+ if (resp != null) {
+ OperationOutcome outcome = (OperationOutcome) resp;
System.out.println(outcome.getIssueFirstRep().getDetailsElement().getValue());
}
// END SNIPPET: delete
}
- {
- // START SNIPPET: deleteConditional
- client.delete()
- .resourceConditionalByUrl("Patient?identifier=system%7C00001")
- .execute();
-
- client.delete()
- .resourceConditionalByType("Patient")
- .where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
- .execute();
- // END SNIPPET: deleteConditional
+ {
+ // START SNIPPET: deleteConditional
+ client.delete()
+ .resourceConditionalByUrl("Patient?identifier=system%7C00001")
+ .execute();
+
+ client.delete()
+ .resourceConditionalByType("Patient")
+ .where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
+ .execute();
+ // END SNIPPET: deleteConditional
}
{
// START SNIPPET: search
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java
index edce214a543..b68ec4d5acb 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/parser/ParserState.java
@@ -1676,7 +1676,7 @@ class ParserState {
private class SecurityLabelElementStateHapi extends ElementCompositeState {
- public SecurityLabelElementStateHapi(ParserState.PreResourceState thePreResourceState,BaseRuntimeElementCompositeDefinition> theDef, BaseCodingDt codingDt) {
+ public SecurityLabelElementStateHapi(ParserState.PreResourceState thePreResourceState, BaseRuntimeElementCompositeDefinition> theDef, BaseCodingDt codingDt) {
super(thePreResourceState, theDef, codingDt);
}
@@ -1718,7 +1718,7 @@ class ParserState {
securityLabels = new ArrayList();
myMap.put(ResourceMetadataKeyEnum.SECURITY_LABELS, securityLabels);
}
- BaseCodingDt securityLabel= myContext.getVersion().newCodingDt();
+ BaseCodingDt securityLabel = myContext.getVersion().newCodingDt();
BaseRuntimeElementCompositeDefinition> codinfDef = (BaseRuntimeElementCompositeDefinition>) myContext.getElementDefinition(securityLabel.getClass());
push(new SecurityLabelElementStateHapi(getPreResourceState(), codinfDef, securityLabel));
securityLabels.add(securityLabel);
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/MethodOutcome.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/MethodOutcome.java
index 63e58755f95..70cf63a0f84 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/MethodOutcome.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/api/MethodOutcome.java
@@ -135,7 +135,7 @@ public class MethodOutcome {
}
/**
- * This will be set to {@link Boolean#TRUE} for instance of MethodOutcome which are
+ * This will be set to {@link Boolean#TRUE} for instance of MethodOutcome which are
* returned to client instances, if the server has responded with an HTTP 201 Created.
*/
public Boolean getCreated() {
diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBinding.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBinding.java
index 288095ab83a..9ca10643fce 100644
--- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBinding.java
+++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/method/BaseOutcomeReturningMethodBinding.java
@@ -280,9 +280,9 @@ abstract class BaseOutcomeReturningMethodBinding extends BaseMethodBinding
+
+
\ No newline at end of file
diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java
index 33cab9ca62f..a315308712e 100644
--- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java
+++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/java/ca/uhn/fhirtest/TestRestfulServer.java
@@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
import ca.uhn.fhir.jpa.provider.JpaSystemProviderDstu2;
+import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
@@ -167,10 +168,15 @@ public class TestRestfulServer extends RestfulServer {
* Do some fancy logging to create a nice access log that has details
* about each incoming request.
*/
- LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
+ List interceptorBeans = myAppCtx.getBean("myServerInterceptors", List.class);
+ for (IServerInterceptor interceptor : interceptorBeans)
+ this.registerInterceptor(interceptor);
+
+ /*LoggingInterceptor loggingInterceptor = new LoggingInterceptor();
loggingInterceptor.setLoggerName("fhirtest.access");
loggingInterceptor.setMessageFormat("Path[${servletPath}] Source[${requestHeader.x-forwarded-for}] Operation[${operationType} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}]");
this.registerInterceptor(loggingInterceptor);
+ */
}
diff --git a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-config.xml b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-config.xml
index 3922d51ebb8..e99cfbb79ad 100644
--- a/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-config.xml
+++ b/hapi-fhir-jpaserver-uhnfhirtest/src/main/webapp/WEB-INF/hapi-fhir-server-config.xml
@@ -21,4 +21,13 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/GenericClientTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/GenericClientTest.java
index 782a4d971c6..97c4bd8e852 100644
--- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/GenericClientTest.java
+++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/client/GenericClientTest.java
@@ -132,7 +132,7 @@ public class GenericClientTest {
ArgumentCaptor capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
- when(myHttpResponse.getAllHeaders()).thenReturn(new Header[] { new BasicHeader(Constants.HEADER_LOCATION, "/Patient/44/_history/22") });
+ when(myHttpResponse.getAllHeaders()).thenReturn(new Header[]{new BasicHeader(Constants.HEADER_LOCATION, "/Patient/44/_history/22")});
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(""), Charset.forName("UTF-8")));
@@ -141,14 +141,14 @@ public class GenericClientTest {
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 201, "OK"));
MethodOutcome resp = client.create().resource(ourCtx.newXmlParser().encodeResourceToString(p1)).execute();
assertTrue(resp.getCreated());
-
+
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
resp = client.create().resource(ourCtx.newXmlParser().encodeResourceToString(p1)).execute();
assertNull(resp.getCreated());
-
+
}
-
-
+
+
@Test
public void testCreateWithStringAutoDetectsEncoding() throws Exception {
diff --git a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/FhirDstu2.java b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/FhirDstu2.java
index 5480b4a40dd..a4210031bb2 100644
--- a/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/FhirDstu2.java
+++ b/hapi-fhir-structures-dstu2/src/main/java/ca/uhn/fhir/model/dstu2/FhirDstu2.java
@@ -105,7 +105,7 @@ public class FhirDstu2 implements IFhirVersion {
public Class extends BaseContainedDt> getContainedType() {
return ContainedDt.class;
}
-
+
@Override
public BaseCodingDt newCodingDt() {
return new CodingDt();
diff --git a/src/site/xdoc/doc_rest_client.xml b/src/site/xdoc/doc_rest_client.xml
index 8128e6a589f..40e2cb8dc7b 100644
--- a/src/site/xdoc/doc_rest_client.xml
+++ b/src/site/xdoc/doc_rest_client.xml
@@ -165,8 +165,10 @@
Search - Using HTTP POST
- The FHIR specification allows the use of an HTTP POST to transmit a search to a server instead of using
- an HTTP GET. With this style of search, the search parameters are included in the request body instead
+ The FHIR specification allows the use of an HTTP POST to transmit a search to a server instead of
+ using
+ an HTTP GET. With this style of search, the search parameters are included in the request body
+ instead
of the request URL, which can be useful if you need to transmit a search with a large number
of parameters.
@@ -176,7 +178,7 @@
case the client automatically switches to POST.
- An alternate form of the search URL (using a URL ending with _search
) was also
+ An alternate form of the search URL (using a URL ending with_search
) was also
supported in FHIR DSTU1. This form is no longer valid in FHIR DSTU2, but HAPI retains support
for using this form in order to interoperate with servers which use it.
@@ -211,18 +213,18 @@
-
+
Conditional Creates
FHIR also specifies a type of update called "conditional create", where
a set of search parameters are provided and a new resource is only
- created if no existing resource matches those parameters. See the
- FHIR specification for more information on conditional creation.
+ created if no existing resource matches those parameters. See the
+ FHIR specification for more information on conditional creation.
-
+
+ value="examples/src/main/java/example/GenericClientExample.java"/>
@@ -276,7 +278,7 @@
Conditional Deletes
- Conditional deletions are also possible, which is a form where
+ Conditional deletions are also possible, which is a form where
instead of deleting a resource using its logical ID, you specify
a set of search criteria and a single resource is deleted if
it matches that criteria. Note that this is not a mechanism
@@ -284,9 +286,9 @@
on conditional deletes and how they are used.
-
+
+ value="examples/src/main/java/example/GenericClientExample.java"/>
@@ -305,19 +307,19 @@
-
+
Conditional Updates
FHIR also specifies a type of update called "conditional updates", where
insetad of using the logical ID of a resource to update, a set of
search parameters is provided. If a single resource matches that set of
- parameters, that resource is updated. See the FHIR specification for
+ parameters, that resource is updated. See the FHIR specification for
information on how conditional updates work.
-
+
+ value="examples/src/main/java/example/GenericClientExample.java"/>
ETags and Resource Contention