Add cascading delete to client (#1804)

* Add cascading delete to client

* Add changelog
This commit is contained in:
James Agnew 2020-04-18 11:16:16 -04:00 committed by GitHub
parent 461739fb32
commit 42c8cd0e38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 233 additions and 96 deletions

View File

@ -0,0 +1,15 @@
package ca.uhn.fhir.rest.api;
/**
* Used by the client to indicate the cascade mode associated with a delete operation.
* <p>
* Note that this is a HAPI FHIR specific feature, and may not work on other platforms.
* </p>
*/
public enum DeleteCascadeModeEnum {
NONE,
DELETE
}

View File

@ -20,10 +20,14 @@ package ca.uhn.fhir.rest.gclient;
* #L%
*/
import ca.uhn.fhir.rest.api.DeleteCascadeModeEnum;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
public interface IDeleteTyped extends IClientExecutable<IDeleteTyped, IBaseOperationOutcome> {
// nothing for now
/**
* Delete cascade mode - Note that this is a HAPI FHIR specific feature and is not supported on all servers.
*/
IDeleteTyped cascade(DeleteCascadeModeEnum theDelete);
}

View File

@ -610,20 +610,34 @@ public class GenericClient extends BaseClient implements IGenericClient {
private IIdType myId;
private String myResourceType;
private String mySearchUrl;
private DeleteCascadeModeEnum myCascadeMode;
@Override
public IBaseOperationOutcome execute() {
Map<String, List<String>> additionalParams = new HashMap<>();
if (myCascadeMode != null) {
switch (myCascadeMode) {
case DELETE:
addParam(getParamMap(), Constants.PARAMETER_CASCADE_DELETE, Constants.CASCADE_DELETE);
break;
default:
case NONE:
break;
}
}
HttpDeleteClientInvocation invocation;
if (myId != null) {
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), myId);
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), myId, getParamMap());
} else if (myConditional) {
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), myResourceType, getParamMap());
} else {
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), mySearchUrl);
invocation = DeleteMethodBinding.createDeleteInvocation(getFhirContext(), mySearchUrl, getParamMap());
}
OperationOutcomeResponseHandler binding = new OperationOutcomeResponseHandler();
Map<String, List<String>> params = new HashMap<String, List<String>>();
return invoke(params, binding, invocation);
return invoke(additionalParams, binding, invocation);
}
@Override
@ -687,6 +701,11 @@ public class GenericClient extends BaseClient implements IGenericClient {
return this;
}
@Override
public IDeleteTyped cascade(DeleteCascadeModeEnum theDelete) {
myCascadeMode = theDelete;
return this;
}
}
@SuppressWarnings({"rawtypes", "unchecked"})

View File

@ -65,18 +65,18 @@ public class DeleteMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
@Override
public BaseHttpClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
IIdType idDt = (IIdType) theArgs[getIdParameterIndex()];
if (idDt == null) {
IIdType id = (IIdType) theArgs[getIdParameterIndex()];
if (id == null) {
throw new NullPointerException("ID can not be null");
}
if (idDt.hasResourceType() == false) {
idDt = idDt.withResourceType(getResourceName());
} else if (getResourceName().equals(idDt.getResourceType()) == false) {
throw new InvalidRequestException("ID parameter has the wrong resource type, expected '" + getResourceName() + "', found: " + idDt.getResourceType());
if (id.hasResourceType() == false) {
id = id.withResourceType(getResourceName());
} else if (getResourceName().equals(id.getResourceType()) == false) {
throw new InvalidRequestException("ID parameter has the wrong resource type, expected '" + getResourceName() + "', found: " + id.getResourceType());
}
HttpDeleteClientInvocation retVal = createDeleteInvocation(getContext(), idDt);
HttpDeleteClientInvocation retVal = createDeleteInvocation(getContext(), id, Collections.emptyMap());
for (int idx = 0; idx < theArgs.length; idx++) {
IParameter nextParam = getParameters().get(idx);
@ -86,9 +86,8 @@ public class DeleteMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
return retVal;
}
public static HttpDeleteClientInvocation createDeleteInvocation(FhirContext theContext, IIdType theId) {
HttpDeleteClientInvocation retVal = new HttpDeleteClientInvocation(theContext, theId);
return retVal;
public static HttpDeleteClientInvocation createDeleteInvocation(FhirContext theContext, IIdType theId, Map<String, List<String>> theAdditionalParams) {
return new HttpDeleteClientInvocation(theContext, theId, theAdditionalParams);
}
@ -97,13 +96,8 @@ public class DeleteMethodBinding extends BaseOutcomeReturningMethodBindingWithRe
return null;
}
public static HttpDeleteClientInvocation createDeleteInvocation(FhirContext theContext, String theSearchUrl) {
HttpDeleteClientInvocation retVal = new HttpDeleteClientInvocation(theContext, theSearchUrl);
return retVal;
}
public static HttpDeleteClientInvocation createDeleteInvocation(FhirContext theContext, String theResourceType, Map<String, List<String>> theParams) {
return new HttpDeleteClientInvocation(theContext, theResourceType, theParams);
public static HttpDeleteClientInvocation createDeleteInvocation(FhirContext theContext, String theSearchUrl, Map<String, List<String>> theParams) {
return new HttpDeleteClientInvocation(theContext, theSearchUrl, theParams);
}
}

View File

@ -36,19 +36,15 @@ public class HttpDeleteClientInvocation extends BaseHttpClientInvocation {
private String myUrlPath;
private Map<String, List<String>> myParams;
public HttpDeleteClientInvocation(FhirContext theContext, IIdType theId) {
public HttpDeleteClientInvocation(FhirContext theContext, IIdType theId, Map<String, List<String>> theAdditionalParams) {
super(theContext);
myUrlPath = theId.toUnqualifiedVersionless().getValue();
myParams = theAdditionalParams;
}
public HttpDeleteClientInvocation(FhirContext theContext, String theSearchUrl) {
public HttpDeleteClientInvocation(FhirContext theContext, String theSearchUrl, Map<String, List<String>> theParams) {
super(theContext);
myUrlPath = theSearchUrl;
}
public HttpDeleteClientInvocation(FhirContext theContext, String theResourceType, Map<String, List<String>> theParams) {
super(theContext);
myUrlPath = theResourceType;
myParams = theParams;
}
@ -67,10 +63,4 @@ public class HttpDeleteClientInvocation extends BaseHttpClientInvocation {
return createHttpRequest(b.toString(), theEncoding, RequestTypeEnum.DELETE);
}
@Override
protected IHttpRequest createHttpRequest(String theUrl, EncodingEnum theEncoding, RequestTypeEnum theRequestType) {
// TODO Auto-generated method stub
return super.createHttpRequest(theUrl, theEncoding, theRequestType);
}
}

View File

@ -23,6 +23,7 @@ package ca.uhn.hapi.fhir.docs;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.PerformanceOptionsEnum;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.rest.api.DeleteCascadeModeEnum;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.SearchStyleEnum;
import ca.uhn.fhir.rest.api.SummaryEnum;
@ -262,6 +263,19 @@ public class GenericClientExample {
.execute();
// END SNIPPET: deleteConditional
}
{
// START SNIPPET: deleteCascade
client.delete()
.resourceById(new IdType("Patient/123"))
.cascade(DeleteCascadeModeEnum.DELETE)
.execute();
client.delete()
.resourceConditionalByType("Patient")
.where(Patient.IDENTIFIER.exactly().systemAndIdentifier("system", "00001"))
.execute();
// END SNIPPET: deleteCascade
}
{
// START SNIPPET: search
Bundle response = client.search()

View File

@ -0,0 +1,4 @@
---
type: add
issue: 1804
title: Support for HAPI FHIR cascading deletes has been added to the Generic Client.

View File

@ -181,6 +181,14 @@ Conditional deletions are also possible, which is a form where instead of deleti
{{snippet:classpath:/ca/uhn/hapi/fhir/docs/GenericClientExample.java|deleteConditional}}
```
## Cascading Delete
The following snippet shows now to request a cascading delete. Note that this is a HAPI FHIR specific feature and is not supported on all servers.
```java
{{snippet:classpath:/ca/uhn/hapi/fhir/docs/GenericClientExample.java|deleteCascade}}
```
# Update - Instance
Updating a resource is similar to creating one, except that an ID must be supplied since you are updating a previously existing resource instance.

View File

@ -9,8 +9,13 @@ import ca.uhn.fhir.model.primitive.StringDt;
import ca.uhn.fhir.parser.CustomTypeR4Test;
import ca.uhn.fhir.parser.CustomTypeR4Test.MyCustomPatient;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.api.DeleteCascadeModeEnum;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.*;
import ca.uhn.fhir.rest.api.EncodingEnum;
import ca.uhn.fhir.rest.api.MethodOutcome;
import ca.uhn.fhir.rest.api.PreferReturnEnum;
import ca.uhn.fhir.rest.api.SortOrderEnum;
import ca.uhn.fhir.rest.api.SortSpec;
import ca.uhn.fhir.rest.client.api.IGenericClient;
import ca.uhn.fhir.rest.client.api.ServerValidationModeEnum;
import ca.uhn.fhir.rest.client.exceptions.FhirClientConnectionException;
@ -39,6 +44,7 @@ import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.message.BasicHeader;
import org.apache.http.message.BasicStatusLine;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;
import org.hl7.fhir.r4.model.*;
@ -56,13 +62,24 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -93,7 +110,7 @@ public class GenericClientR4Test {
}
private String extractBodyAsString(ArgumentCaptor<HttpUriRequest> capt) throws IOException {
String body = IOUtils.toString(((HttpEntityEnclosingRequestBase) capt.getAllValues().get(0)).getEntity().getContent(), "UTF-8");
String body = IOUtils.toString(((HttpEntityEnclosingRequestBase) capt.getAllValues().get(0)).getEntity().getContent(), StandardCharsets.UTF_8);
return body;
}
@ -107,7 +124,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8);
}
});
return capt;
@ -124,7 +141,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8);
}
});
@ -183,7 +200,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -193,7 +210,7 @@ public class GenericClientR4Test {
pt.getText().setDivAsString("A PATIENT");
Binary bin = new Binary();
bin.setContent(ourCtx.newJsonParser().encodeResourceToString(pt).getBytes("UTF-8"));
bin.setContent(ourCtx.newJsonParser().encodeResourceToString(pt).getBytes(StandardCharsets.UTF_8));
bin.setContentType(Constants.CT_FHIR_JSON);
client.create().resource(bin).execute();
@ -207,7 +224,7 @@ public class GenericClientR4Test {
Binary output = ourCtx.newJsonParser().parseResource(Binary.class, extractBodyAsString(capt));
assertEquals(Constants.CT_FHIR_JSON, output.getContentType());
Patient outputPt = (Patient) ourCtx.newJsonParser().parseResource(new String(output.getContent(), "UTF-8"));
Patient outputPt = (Patient) ourCtx.newJsonParser().parseResource(new String(output.getContent(), StandardCharsets.UTF_8));
assertEquals("<div xmlns=\"http://www.w3.org/1999/xhtml\">A PATIENT</div>", outputPt.getText().getDivAsString());
}
@ -226,7 +243,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -290,7 +307,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -330,9 +347,9 @@ public class GenericClientR4Test {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
if (myAnswerCount++ == 0) {
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), StandardCharsets.UTF_8);
} else {
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
}
}
});
@ -379,7 +396,7 @@ public class GenericClientR4Test {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
myAnswerCount++;
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
}
});
@ -400,6 +417,78 @@ public class GenericClientR4Test {
assertEquals("http://example.com/fhir/Patient", capt.getAllValues().get(0).getURI().toASCIIString());
}
@Test
public void testDeleteCascade() throws Exception {
final IParser p = ourCtx.newXmlParser();
OperationOutcome oo = new OperationOutcome();
oo.getText().setDivAsString("FINAL VALUE");
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getAllHeaders()).thenAnswer(new Answer<Header[]>() {
@Override
public Header[] answer(InvocationOnMock theInvocation) {
return new Header[]{new BasicHeader(Constants.HEADER_LOCATION, "http://foo.com/base/Patient/222/_history/3")};
}
});
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
myAnswerCount++;
return new ReaderInputStream(new StringReader(p.encodeResourceToString(oo)), StandardCharsets.UTF_8);
}
});
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
IBaseOperationOutcome outcome;
// Regular delete
outcome = client
.delete()
.resourceById(new IdType("Patient/222"))
.execute();
assertNotNull(outcome);
assertEquals(1, capt.getAllValues().size());
assertEquals("http://example.com/fhir/Patient/222", capt.getAllValues().get(myAnswerCount - 1).getURI().toASCIIString());
assertEquals("DELETE", capt.getAllValues().get(myAnswerCount - 1).getMethod());
// NONE Cascading delete
outcome = client
.delete()
.resourceById(new IdType("Patient/222"))
.cascade(DeleteCascadeModeEnum.NONE)
.execute();
assertNotNull(outcome);
assertEquals(2, capt.getAllValues().size());
assertEquals("http://example.com/fhir/Patient/222", capt.getAllValues().get(myAnswerCount - 1).getURI().toASCIIString());
assertEquals("DELETE", capt.getAllValues().get(myAnswerCount - 1).getMethod());
// DELETE Cascading delete
outcome = client
.delete()
.resourceById(new IdType("Patient/222"))
.cascade(DeleteCascadeModeEnum.DELETE)
.execute();
assertNotNull(outcome);
assertEquals(myAnswerCount, capt.getAllValues().size());
assertEquals("http://example.com/fhir/Patient/222?" + Constants.PARAMETER_CASCADE_DELETE + "=" + Constants.CASCADE_DELETE, capt.getAllValues().get(myAnswerCount - 1).getURI().toASCIIString());
assertEquals("DELETE", capt.getAllValues().get(myAnswerCount - 1).getMethod());
// DELETE Cascading delete on search URL
outcome = client
.delete()
.resourceConditionalByUrl("Patient?identifier=sys|val")
.cascade(DeleteCascadeModeEnum.DELETE)
.execute();
assertNotNull(outcome);
assertEquals(myAnswerCount, capt.getAllValues().size());
assertEquals("http://example.com/fhir/Patient?identifier=sys%7Cval&" + Constants.PARAMETER_CASCADE_DELETE + "=" + Constants.CASCADE_DELETE, capt.getAllValues().get(myAnswerCount - 1).getURI().toASCIIString());
assertEquals("DELETE", capt.getAllValues().get(myAnswerCount - 1).getMethod());
}
@Test
public void testExplicitCustomTypeHistoryType() throws Exception {
final String respString = CustomTypeR4Test.createBundle(CustomTypeR4Test.createResource(false));
@ -410,7 +499,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -437,7 +526,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -482,7 +571,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -522,7 +611,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -567,7 +656,7 @@ public class GenericClientR4Test {
respString = p.encodeResourceToString(conf);
}
myCount++;
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -615,7 +704,7 @@ public class GenericClientR4Test {
respString = p.encodeResourceToString(conf);
}
myAnswerCount++;
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -655,7 +744,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenAnswer(t -> {
IParser p = ourCtx.newXmlParser();
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
});
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
@ -816,7 +905,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -860,7 +949,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -904,7 +993,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -947,7 +1036,7 @@ public class GenericClientR4Test {
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", "text/html"));
when(myHttpResponse.getEntity().getContent()).thenAnswer(t -> new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8")));
when(myHttpResponse.getEntity().getContent()).thenAnswer(t -> new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8));
when(myHttpResponse.getAllHeaders()).thenReturn(new Header[]{
new BasicHeader("content-type", "text/html")
});
@ -982,7 +1071,7 @@ public class GenericClientR4Test {
Parameters inputParams = new Parameters();
inputParams.addParameter().setName("name").setValue(new BooleanType(true));
final byte[] respBytes = new byte[]{0,1,2,3,4,5,6,7,8,9,100};
final byte[] respBytes = new byte[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 100};
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
@ -1027,7 +1116,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1081,7 +1170,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1120,7 +1209,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1159,7 +1248,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1197,7 +1286,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1235,7 +1324,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1273,7 +1362,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1320,7 +1409,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(encoded), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(encoded), StandardCharsets.UTF_8);
}
});
@ -1365,7 +1454,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(encoded), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(encoded), StandardCharsets.UTF_8);
}
});
@ -1394,7 +1483,7 @@ public class GenericClientR4Test {
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8));
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
@ -1423,7 +1512,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1454,7 +1543,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -1502,7 +1591,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8);
}
});
@ -1629,7 +1718,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8);
}
});
@ -1739,7 +1828,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8);
}
});
@ -1831,7 +1920,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8);
}
});
@ -1867,12 +1956,12 @@ public class GenericClientR4Test {
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_JSON + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8));
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
HashMap<String, List<IQueryParameterType>> params = new HashMap<String, List<IQueryParameterType>>();
params.put("foo", Arrays.asList((IQueryParameterType) new DateParam("2001")));
params.put("foo", Arrays.asList(new DateParam("2001")));
Bundle response = client
.search()
.forResource(Patient.class)
@ -1915,7 +2004,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), 200, "OK"));
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(msg), Charset.forName("UTF-8")));
when(myHttpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8));
// httpResponse = new BasicHttpResponse(statusline, catalog, locale)
when(myHttpClient.execute(capt.capture())).thenReturn(myHttpResponse);
@ -1940,7 +2029,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).then(new Answer<InputStream>() {
@Override
public InputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(msg), StandardCharsets.UTF_8);
}
});
@ -1977,7 +2066,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenAnswer(t -> {
IParser p = ourCtx.newXmlParser();
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
});
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
@ -2015,7 +2104,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -2068,7 +2157,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
when(myHttpResponse.getEntity().getContent()).thenAnswer(t -> {
IParser p = ourCtx.newXmlParser();
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
});
IGenericClient client = ourCtx.newRestfulGenericClient("http://example.com/fhir");
@ -2147,7 +2236,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -2194,9 +2283,9 @@ public class GenericClientR4Test {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
if (myAnswerCount++ == 0) {
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), StandardCharsets.UTF_8);
} else {
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
}
}
});
@ -2242,7 +2331,7 @@ public class GenericClientR4Test {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
myAnswerCount++;
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp1)), StandardCharsets.UTF_8);
}
});
@ -2279,7 +2368,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -2316,7 +2405,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -2337,7 +2426,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -2372,7 +2461,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(p.encodeResourceToString(resp0)), StandardCharsets.UTF_8);
}
});
@ -2405,7 +2494,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});
@ -2443,7 +2532,7 @@ public class GenericClientR4Test {
when(myHttpResponse.getEntity().getContent()).thenAnswer(new Answer<ReaderInputStream>() {
@Override
public ReaderInputStream answer(InvocationOnMock theInvocation) {
return new ReaderInputStream(new StringReader(respString), Charset.forName("UTF-8"));
return new ReaderInputStream(new StringReader(respString), StandardCharsets.UTF_8);
}
});