Fix timeout issue in vsac
This commit is contained in:
parent
a86e3d2bdc
commit
1814a69826
|
@ -33,60 +33,6 @@ import org.hl7.fhir.utilities.json.model.JsonObject;
|
|||
import org.hl7.fhir.utilities.json.model.JsonProperty;
|
||||
|
||||
public class VSACImporter extends OIDBasedValueSetImporter {
|
||||
|
||||
private static class StatsTracker {
|
||||
private String runNumber;
|
||||
private JsonObject stats;
|
||||
private File file;
|
||||
|
||||
protected StatsTracker() throws IOException {
|
||||
super();
|
||||
file = new File(Utilities.path("[tmp]", "vsac.stats.json"));
|
||||
if (file.exists() ) {
|
||||
stats = org.hl7.fhir.utilities.json.parser.JsonParser.parseObject(file);
|
||||
runNumber = ""+(stats.asInteger("last-run")+1);
|
||||
} else {
|
||||
stats = new JsonObject();
|
||||
runNumber = "1";
|
||||
}
|
||||
stats.set("last-run", runNumber);
|
||||
}
|
||||
|
||||
public void recordTime(String oid, boolean expand, int offset, long time) {
|
||||
JsonArray arr = stats.forceObject(oid).forceObject(runNumber).forceArray(expand ? "e"+offset : "r");
|
||||
arr.add(Long.toString(time));
|
||||
}
|
||||
|
||||
public void recordError(String oid, boolean expand, int offset, String error) {
|
||||
JsonArray arr = stats.forceObject(oid).forceObject(runNumber).forceArray(expand ? "e"+offset : "r");
|
||||
arr.add(error.contains("time") ? "t" : error);
|
||||
}
|
||||
|
||||
public boolean hasFailed(String oid) {
|
||||
JsonObject obj = stats.forceObject(oid);
|
||||
for (JsonProperty p : obj.getProperties()) {
|
||||
if (p.getValue().isJsonObject()) {
|
||||
JsonObject o = p.getValue().asJsonObject();
|
||||
for (JsonProperty p1 : o.getProperties()) {
|
||||
if (p1.getValue().isJsonArray()) {
|
||||
JsonArray a = p1.getValue().asJsonArray();
|
||||
for (String s : a.asStrings()) {
|
||||
if ("t".equals(s)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void save() throws IOException {
|
||||
org.hl7.fhir.utilities.json.parser.JsonParser.compose(stats, file);
|
||||
}
|
||||
}
|
||||
|
||||
public VSACImporter() throws FHIRException, IOException {
|
||||
super();
|
||||
|
@ -102,12 +48,11 @@ public class VSACImporter extends OIDBasedValueSetImporter {
|
|||
CSVReader csv = new CSVReader(new FileInputStream(source));
|
||||
csv.readHeaders();
|
||||
Map<String, String> errs = new HashMap<>();
|
||||
StatsTracker st = new StatsTracker();
|
||||
|
||||
FHIRToolingClient fhirToolingClient = new FHIRToolingClient("https://cts.nlm.nih.gov/fhir", "fhir/vsac");
|
||||
fhirToolingClient.setUsername("apikey");
|
||||
fhirToolingClient.setPassword(apiKey);
|
||||
fhirToolingClient.setTimeout(120000);
|
||||
fhirToolingClient.setTimeoutNormal(6000);
|
||||
|
||||
CapabilityStatement cs = fhirToolingClient.getCapabilitiesStatement();
|
||||
JsonParser json = new JsonParser();
|
||||
|
@ -117,9 +62,6 @@ public class VSACImporter extends OIDBasedValueSetImporter {
|
|||
List<String> oids = new ArrayList<>();
|
||||
while (csv.line()) {
|
||||
String oid = csv.cell("OID");
|
||||
if (st.hasFailed(oid)) {
|
||||
oid = " "+oid; // do these first
|
||||
}
|
||||
oids.add(oid);
|
||||
}
|
||||
Collections.sort(oids);
|
||||
|
@ -128,18 +70,16 @@ public class VSACImporter extends OIDBasedValueSetImporter {
|
|||
int j = 0;
|
||||
for (String oid : oids) {
|
||||
try {
|
||||
j = processOid(dest, onlyNew, errs, st, fhirToolingClient, j, oid.trim());
|
||||
j = processOid(dest, onlyNew, errs, fhirToolingClient, j, oid.trim());
|
||||
i++;
|
||||
if (i % 100 == 0) {
|
||||
System.out.println(":"+i+" ("+j+")");
|
||||
st.save();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Unable to fetch OID " + oid + ": " + e.getMessage());
|
||||
errs.put(oid, e.getMessage());
|
||||
}
|
||||
}
|
||||
st.save();
|
||||
OperationOutcome oo = new OperationOutcome();
|
||||
for (String oid : errs.keySet()) {
|
||||
oo.addIssue().setSeverity(IssueSeverity.ERROR).setCode(IssueType.EXCEPTION).setDiagnostics(errs.get(oid)).addLocation(oid);
|
||||
|
@ -148,67 +88,36 @@ public class VSACImporter extends OIDBasedValueSetImporter {
|
|||
System.out.println("Done. " + i + " ValueSets");
|
||||
}
|
||||
|
||||
private int processOid(String dest, boolean onlyNew, Map<String, String> errs, StatsTracker st,
|
||||
FHIRToolingClient fhirToolingClient, int j, String oid)
|
||||
private int processOid(String dest, boolean onlyNew, Map<String, String> errs, FHIRToolingClient fhirToolingClient, int j, String oid)
|
||||
throws IOException, InterruptedException, FileNotFoundException {
|
||||
if (!onlyNew || !(new File(Utilities.path(dest, "ValueSet-" + oid + ".json")).exists())) {
|
||||
ValueSet vs = null;
|
||||
try {
|
||||
long t = System.currentTimeMillis();
|
||||
vs = fhirToolingClient.read(ValueSet.class, oid);
|
||||
st.recordTime(oid, false, 0, System.currentTimeMillis()-t);
|
||||
} catch (Exception e) {
|
||||
st.recordError(oid, false, 0, e.getMessage());
|
||||
errs.put(oid, "Read: " +e.getMessage()+". Try again");
|
||||
System.out.println("Read "+oid+" failed: "+e.getMessage()+". Try again after 10sec");
|
||||
Thread.sleep(10000);
|
||||
try {
|
||||
long t = System.currentTimeMillis();
|
||||
vs = fhirToolingClient.read(ValueSet.class, oid);
|
||||
st.recordTime(oid, false, 0, System.currentTimeMillis()-t);
|
||||
} catch (Exception e2) {
|
||||
st.recordError(oid, false, 0, e2.getMessage());
|
||||
errs.put(oid, "Read: " +e2.getMessage()+". Give up");
|
||||
System.out.println("Read "+oid+" failed: "+e2.getMessage()+". Give up");
|
||||
}
|
||||
errs.put(oid, "Read: " +e.getMessage());
|
||||
System.out.println("Read "+oid+" failed: "+e.getMessage());
|
||||
}
|
||||
if (vs != null) {
|
||||
try {
|
||||
long t = System.currentTimeMillis();
|
||||
ValueSet vse = fhirToolingClient.expandValueset(vs.getUrl(), null);
|
||||
st.recordTime(oid, true, 0, System.currentTimeMillis()-t);
|
||||
vs.setExpansion(vse.getExpansion());
|
||||
j++;
|
||||
} catch (Exception e) {
|
||||
st.recordError(oid, true, 0, e.getMessage());
|
||||
errs.put(oid, "Expansion: " +e.getMessage()+". Try again");
|
||||
System.out.println("Expand "+oid+" failed: "+e.getMessage()+". Try again");
|
||||
try {
|
||||
long t = System.currentTimeMillis();
|
||||
ValueSet vse = fhirToolingClient.expandValueset(vs.getUrl(), null);
|
||||
st.recordTime(oid, true, 0, System.currentTimeMillis()-t);
|
||||
vs.setExpansion(vse.getExpansion());
|
||||
j++;
|
||||
} catch (Exception e2) {
|
||||
st.recordError(oid, true, 0, e2.getMessage());
|
||||
errs.put(oid, "Expansion: " +e2.getMessage()+". Give up");
|
||||
System.out.println("Expand "+oid+" failed: "+e2.getMessage()+". Give up");
|
||||
}
|
||||
errs.put(oid, "Expansion: " +e.getMessage());
|
||||
System.out.println("Expand "+oid+" failed: "+e.getMessage());
|
||||
}
|
||||
while (isIncomplete(vs.getExpansion())) {
|
||||
Parameters p = new Parameters();
|
||||
int offset = vs.getExpansion().getParameter("offset").getValueIntegerType().getValue() + vs.getExpansion().getParameter("count").getValueIntegerType().getValue();
|
||||
p.addParameter("offset", offset);
|
||||
try {
|
||||
long t = System.currentTimeMillis();
|
||||
ValueSet vse = fhirToolingClient.expandValueset(vs.getUrl(), p);
|
||||
st.recordTime(oid, true, offset, System.currentTimeMillis()-t);
|
||||
vs.getExpansion().getContains().addAll(vse.getExpansion().getContains());
|
||||
vs.getExpansion().setParameter(vse.getExpansion().getParameter());
|
||||
} catch (Exception e2) {
|
||||
st.recordError(oid, true, 0, e2.getMessage());
|
||||
errs.put(oid, "Expansion: " +e2.getMessage()+" @ "+offset+". Give up");
|
||||
System.out.println("Expand "+oid+" @ "+offset+" failed: "+e2.getMessage()+". Give up");
|
||||
errs.put(oid, "Expansion: " +e2.getMessage()+" @ "+offset);
|
||||
System.out.println("Expand "+oid+" @ "+offset+" failed: "+e2.getMessage());
|
||||
}
|
||||
}
|
||||
vs.getExpansion().setOffsetElement(null);
|
||||
|
|
|
@ -133,8 +133,8 @@ public class TerminologyClientR4 implements ITerminologyClient {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ITerminologyClient setTimeout(int i) {
|
||||
client.setTimeout(i);
|
||||
public ITerminologyClient setTimeout(int i) { // #FIXME
|
||||
client.setTimeoutNormal(i);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ public class TerminologyClientR4 implements TerminologyClient {
|
|||
|
||||
@Override
|
||||
public void setTimeout(int i) {
|
||||
client.setTimeout(i);
|
||||
client.setTimeoutNormal(i); // #FIXME
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -67,12 +67,12 @@ public class FHIRToolingClient {
|
|||
public static final String hostKey = "http.proxyHost";
|
||||
public static final String portKey = "http.proxyPort";
|
||||
|
||||
private static final int TIMEOUT_NORMAL = 1500;
|
||||
private static final int TIMEOUT_OPERATION = 30000;
|
||||
private static final int TIMEOUT_ENTRY = 500;
|
||||
private static final int TIMEOUT_OPERATION_LONG = 60000;
|
||||
private static final int TIMEOUT_OPERATION_EXPAND = 120000;
|
||||
|
||||
private static final int DEFAULT_TIMEOUT_NORMAL = 1500;
|
||||
private static final int DEFAULT_TIMEOUT_OPERATION = 30000;
|
||||
private static final int DEFAULT_TIMEOUT_ENTRY = 500;
|
||||
private static final int DEFAULT_TIMEOUT_OPERATION_LONG = 60000;
|
||||
private static final int DEFAULT_TIMEOUT_OPERATION_EXPAND = 120000;
|
||||
|
||||
private String base;
|
||||
private ResourceAddress resourceAddress;
|
||||
private ResourceFormat preferredResourceFormat;
|
||||
|
@ -84,6 +84,11 @@ public class FHIRToolingClient {
|
|||
private String password;
|
||||
private String userAgent;
|
||||
private String acceptLang;
|
||||
private int timeoutNormal = DEFAULT_TIMEOUT_NORMAL;
|
||||
private int timeoutOperation = DEFAULT_TIMEOUT_OPERATION;
|
||||
private int timeoutEntry = DEFAULT_TIMEOUT_ENTRY;
|
||||
private int timeoutLong = DEFAULT_TIMEOUT_OPERATION_LONG;
|
||||
private int timeoutExpand = DEFAULT_TIMEOUT_OPERATION_EXPAND;
|
||||
|
||||
// Pass endpoint for client - URI
|
||||
public FHIRToolingClient(String baseServiceUrl, String userAgent) throws URISyntaxException {
|
||||
|
@ -134,7 +139,7 @@ public class FHIRToolingClient {
|
|||
TerminologyCapabilities capabilities = null;
|
||||
try {
|
||||
capabilities = (TerminologyCapabilities) client.issueGetResourceRequest(resourceAddress.resolveMetadataTxCaps(),
|
||||
getPreferredResourceFormat(), generateHeaders(), "TerminologyCapabilities", TIMEOUT_NORMAL).getReference();
|
||||
getPreferredResourceFormat(), generateHeaders(), "TerminologyCapabilities", timeoutNormal).getReference();
|
||||
} catch (Exception e) {
|
||||
throw new FHIRException("Error fetching the server's terminology capabilities", e);
|
||||
}
|
||||
|
@ -145,7 +150,7 @@ public class FHIRToolingClient {
|
|||
CapabilityStatement conformance = null;
|
||||
try {
|
||||
conformance = (CapabilityStatement) client.issueGetResourceRequest(resourceAddress.resolveMetadataUri(false),
|
||||
getPreferredResourceFormat(), generateHeaders(), "CapabilitiesStatement", TIMEOUT_NORMAL).getReference();
|
||||
getPreferredResourceFormat(), generateHeaders(), "CapabilitiesStatement", timeoutNormal).getReference();
|
||||
} catch (Exception e) {
|
||||
throw new FHIRException("Error fetching the server's conformance statement", e);
|
||||
}
|
||||
|
@ -157,7 +162,7 @@ public class FHIRToolingClient {
|
|||
return capabilities;
|
||||
try {
|
||||
capabilities = (CapabilityStatement) client.issueGetResourceRequest(resourceAddress.resolveMetadataUri(true),
|
||||
getPreferredResourceFormat(), generateHeaders(), "CapabilitiesStatement-Quick", TIMEOUT_NORMAL)
|
||||
getPreferredResourceFormat(), generateHeaders(), "CapabilitiesStatement-Quick", timeoutNormal)
|
||||
.getReference();
|
||||
} catch (Exception e) {
|
||||
throw new FHIRException("Error fetching the server's capability statement: " + e.getMessage(), e);
|
||||
|
@ -170,7 +175,7 @@ public class FHIRToolingClient {
|
|||
try {
|
||||
result = client.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id),
|
||||
getPreferredResourceFormat(), generateHeaders(), "Read " + resourceClass + "/" + id,
|
||||
TIMEOUT_NORMAL);
|
||||
timeoutNormal);
|
||||
if (result.isUnsuccessfulRequest()) {
|
||||
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(),
|
||||
(OperationOutcome) result.getPayload());
|
||||
|
@ -186,7 +191,7 @@ public class FHIRToolingClient {
|
|||
try {
|
||||
result = client.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id),
|
||||
getPreferredResourceFormat(), generateHeaders(), "Read " + resourceClass.getName() + "/" + id,
|
||||
TIMEOUT_NORMAL);
|
||||
timeoutNormal);
|
||||
if (result.isUnsuccessfulRequest()) {
|
||||
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(),
|
||||
(OperationOutcome) result.getPayload());
|
||||
|
@ -203,7 +208,7 @@ public class FHIRToolingClient {
|
|||
result = client.issueGetResourceRequest(
|
||||
resourceAddress.resolveGetUriFromResourceClassAndIdAndVersion(resourceClass, id, version),
|
||||
getPreferredResourceFormat(), generateHeaders(),
|
||||
"VRead " + resourceClass.getName() + "/" + id + "/?_history/" + version, TIMEOUT_NORMAL);
|
||||
"VRead " + resourceClass.getName() + "/" + id + "/?_history/" + version, timeoutNormal);
|
||||
if (result.isUnsuccessfulRequest()) {
|
||||
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(),
|
||||
(OperationOutcome) result.getPayload());
|
||||
|
@ -220,7 +225,7 @@ public class FHIRToolingClient {
|
|||
result = client.issueGetResourceRequest(
|
||||
resourceAddress.resolveGetUriFromResourceClassAndCanonical(resourceClass, canonicalURL),
|
||||
getPreferredResourceFormat(), generateHeaders(), "Read " + resourceClass.getName() + "?url=" + canonicalURL,
|
||||
TIMEOUT_NORMAL);
|
||||
timeoutNormal);
|
||||
if (result.isUnsuccessfulRequest()) {
|
||||
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(),
|
||||
(OperationOutcome) result.getPayload());
|
||||
|
@ -243,7 +248,7 @@ public class FHIRToolingClient {
|
|||
resourceAddress.resolveGetUriFromResourceClassAndId(resource.getClass(), resource.getId()),
|
||||
ByteUtils.resourceToByteArray(resource, false, isJson(getPreferredResourceFormat())),
|
||||
getPreferredResourceFormat(), generateHeaders(), "Update " + resource.fhirType() + "/" + resource.getId(),
|
||||
TIMEOUT_OPERATION);
|
||||
timeoutOperation);
|
||||
if (result.isUnsuccessfulRequest()) {
|
||||
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(),
|
||||
(OperationOutcome) result.getPayload());
|
||||
|
@ -272,7 +277,7 @@ public class FHIRToolingClient {
|
|||
result = client.issuePutRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id),
|
||||
ByteUtils.resourceToByteArray(resource, false, isJson(getPreferredResourceFormat())),
|
||||
getPreferredResourceFormat(), generateHeaders(), "Update " + resource.fhirType() + "/" + id,
|
||||
TIMEOUT_OPERATION);
|
||||
timeoutOperation);
|
||||
if (result.isUnsuccessfulRequest()) {
|
||||
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(),
|
||||
(OperationOutcome) result.getPayload());
|
||||
|
@ -309,10 +314,10 @@ public class FHIRToolingClient {
|
|||
if (complex) {
|
||||
byte[] body = ByteUtils.resourceToByteArray(params, false, isJson(getPreferredResourceFormat()));
|
||||
result = client.issuePostRequest(url, body, getPreferredResourceFormat(), generateHeaders(),
|
||||
"POST " + resourceClass.getName() + "/$" + name, TIMEOUT_OPERATION_LONG);
|
||||
"POST " + resourceClass.getName() + "/$" + name, timeoutLong);
|
||||
} else {
|
||||
result = client.issueGetResourceRequest(url, getPreferredResourceFormat(), generateHeaders(),
|
||||
"GET " + resourceClass.getName() + "/$" + name, TIMEOUT_OPERATION_LONG);
|
||||
"GET " + resourceClass.getName() + "/$" + name, timeoutLong);
|
||||
}
|
||||
if (result.isUnsuccessfulRequest()) {
|
||||
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(),
|
||||
|
@ -332,7 +337,7 @@ public class FHIRToolingClient {
|
|||
try {
|
||||
transactionResult = client.postBatchRequest(resourceAddress.getBaseServiceUri(),
|
||||
ByteUtils.resourceToByteArray(batch, false, isJson(getPreferredResourceFormat())),
|
||||
getPreferredResourceFormat(), "transaction", TIMEOUT_OPERATION + (TIMEOUT_ENTRY * batch.getEntry().size()));
|
||||
getPreferredResourceFormat(), "transaction", timeoutOperation + (timeoutEntry * batch.getEntry().size()));
|
||||
} catch (Exception e) {
|
||||
handleException("An error occurred trying to process this transaction request", e);
|
||||
}
|
||||
|
@ -346,7 +351,7 @@ public class FHIRToolingClient {
|
|||
result = client.issuePostRequest(resourceAddress.resolveValidateUri(resourceClass, id),
|
||||
ByteUtils.resourceToByteArray(resource, false, isJson(getPreferredResourceFormat())),
|
||||
getPreferredResourceFormat(), generateHeaders(),
|
||||
"POST " + resourceClass.getName() + (id != null ? "/" + id : "") + "/$validate", TIMEOUT_OPERATION_LONG);
|
||||
"POST " + resourceClass.getName() + (id != null ? "/" + id : "") + "/$validate", timeoutLong);
|
||||
if (result.isUnsuccessfulRequest()) {
|
||||
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(),
|
||||
(OperationOutcome) result.getPayload());
|
||||
|
@ -389,7 +394,7 @@ public class FHIRToolingClient {
|
|||
public Bundle fetchFeed(String url) {
|
||||
Bundle feed = null;
|
||||
try {
|
||||
feed = client.issueGetFeedRequest(new URI(url), getPreferredResourceFormat());
|
||||
feed = client.issueGetFeedRequest(new URI(url), getPreferredResourceFormat(), timeoutLong);
|
||||
} catch (Exception e) {
|
||||
handleException("An error has occurred while trying to retrieve history since last update", e);
|
||||
}
|
||||
|
@ -414,7 +419,7 @@ public class FHIRToolingClient {
|
|||
org.hl7.fhir.r4.utils.client.network.ResourceRequest<Resource> result = null;
|
||||
try {
|
||||
result = client.issueGetResourceRequest(resourceAddress.resolveOperationUri(ValueSet.class, "expand", parameters),
|
||||
getPreferredResourceFormat(), generateHeaders(), "ValueSet/$expand?url=" + vsUrl, TIMEOUT_OPERATION_EXPAND);
|
||||
getPreferredResourceFormat(), generateHeaders(), "ValueSet/$expand?url=" + vsUrl, timeoutExpand);
|
||||
} catch (IOException e) {
|
||||
throw new FHIRException(e);
|
||||
}
|
||||
|
@ -432,7 +437,7 @@ public class FHIRToolingClient {
|
|||
try {
|
||||
result = client.issuePostRequest(resourceAddress.resolveOperationUri(ValueSet.class, "expand"),
|
||||
ByteUtils.resourceToByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(),
|
||||
generateHeaders(), "ValueSet/$expand?url=" + source.getUrl(), TIMEOUT_OPERATION_EXPAND);
|
||||
generateHeaders(), "ValueSet/$expand?url=" + source.getUrl(), timeoutExpand);
|
||||
if (result.isUnsuccessfulRequest()) {
|
||||
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(),
|
||||
(OperationOutcome) result.getPayload());
|
||||
|
@ -447,7 +452,7 @@ public class FHIRToolingClient {
|
|||
org.hl7.fhir.r4.utils.client.network.ResourceRequest<Resource> result = null;
|
||||
try {
|
||||
result = client.issueGetResourceRequest(resourceAddress.resolveOperationUri(CodeSystem.class, "lookup", params),
|
||||
getPreferredResourceFormat(), generateHeaders(), "CodeSystem/$lookup", TIMEOUT_NORMAL);
|
||||
getPreferredResourceFormat(), generateHeaders(), "CodeSystem/$lookup", timeoutNormal);
|
||||
} catch (IOException e) {
|
||||
throw new FHIRException(e);
|
||||
}
|
||||
|
@ -471,7 +476,7 @@ public class FHIRToolingClient {
|
|||
result = client.issuePostRequest(resourceAddress.resolveOperationUri(ValueSet.class, "expand", params),
|
||||
ByteUtils.resourceToByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(),
|
||||
generateHeaders(), source == null ? "ValueSet/$expand" : "ValueSet/$expand?url=" + source.getUrl(),
|
||||
TIMEOUT_OPERATION_EXPAND);
|
||||
timeoutExpand);
|
||||
if (result.isUnsuccessfulRequest()) {
|
||||
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(),
|
||||
(OperationOutcome) result.getPayload());
|
||||
|
@ -500,7 +505,7 @@ public class FHIRToolingClient {
|
|||
result = client.issuePostRequest(
|
||||
resourceAddress.resolveOperationUri(null, "closure", new HashMap<String, String>()),
|
||||
ByteUtils.resourceToByteArray(params, false, isJson(getPreferredResourceFormat())),
|
||||
getPreferredResourceFormat(), generateHeaders(), "Closure?name=" + name, TIMEOUT_NORMAL);
|
||||
getPreferredResourceFormat(), generateHeaders(), "Closure?name=" + name, timeoutNormal);
|
||||
if (result.isUnsuccessfulRequest()) {
|
||||
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(),
|
||||
(OperationOutcome) result.getPayload());
|
||||
|
@ -520,7 +525,7 @@ public class FHIRToolingClient {
|
|||
result = client.issuePostRequest(
|
||||
resourceAddress.resolveOperationUri(null, "closure", new HashMap<String, String>()),
|
||||
ByteUtils.resourceToByteArray(params, false, isJson(getPreferredResourceFormat())),
|
||||
getPreferredResourceFormat(), generateHeaders(), "UpdateClosure?name=" + name, TIMEOUT_OPERATION);
|
||||
getPreferredResourceFormat(), generateHeaders(), "UpdateClosure?name=" + name, timeoutOperation);
|
||||
if (result.isUnsuccessfulRequest()) {
|
||||
throw new EFhirClientException("Server returned error code " + result.getHttpStatus(),
|
||||
(OperationOutcome) result.getPayload());
|
||||
|
@ -547,14 +552,6 @@ public class FHIRToolingClient {
|
|||
this.password = password;
|
||||
}
|
||||
|
||||
public long getTimeout() {
|
||||
return client.getTimeout();
|
||||
}
|
||||
|
||||
public void setTimeout(long timeout) {
|
||||
client.setTimeout(timeout);
|
||||
}
|
||||
|
||||
public ToolingClientLogger getLogger() {
|
||||
return client.getLogger();
|
||||
}
|
||||
|
@ -631,7 +628,7 @@ public class FHIRToolingClient {
|
|||
org.hl7.fhir.r4.utils.client.network.ResourceRequest<Resource> result = null;
|
||||
try {
|
||||
result = client.issueGetResourceRequest(resourceAddress.resolveGetResource(resourceClass, id),
|
||||
getPreferredResourceFormat(), generateHeaders(), resourceClass.getName()+"/"+id, TIMEOUT_NORMAL);
|
||||
getPreferredResourceFormat(), generateHeaders(), resourceClass.getName()+"/"+id, timeoutNormal);
|
||||
} catch (IOException e) {
|
||||
throw new FHIRException(e);
|
||||
}
|
||||
|
@ -641,4 +638,46 @@ public class FHIRToolingClient {
|
|||
}
|
||||
return (T) result.getPayload();
|
||||
}
|
||||
|
||||
|
||||
public long getTimeoutNormal() {
|
||||
return timeoutNormal;
|
||||
}
|
||||
|
||||
public void setTimeoutNormal(int timeoutNormal) {
|
||||
this.timeoutNormal = timeoutNormal;
|
||||
}
|
||||
|
||||
public long getTimeoutOperation() {
|
||||
return timeoutOperation;
|
||||
}
|
||||
|
||||
public void setTimeoutOperation(int timeoutOperation) {
|
||||
this.timeoutOperation = timeoutOperation;
|
||||
}
|
||||
|
||||
public long getTimeoutEntry() {
|
||||
return timeoutEntry;
|
||||
}
|
||||
|
||||
public void setTimeoutEntry(int timeoutEntry) {
|
||||
this.timeoutEntry = timeoutEntry;
|
||||
}
|
||||
|
||||
public long getTimeoutLong() {
|
||||
return timeoutLong;
|
||||
}
|
||||
|
||||
public void setTimeoutLong(int timeoutLong) {
|
||||
this.timeoutLong = timeoutLong;
|
||||
}
|
||||
|
||||
public long getTimeoutExpand() {
|
||||
return timeoutExpand;
|
||||
}
|
||||
|
||||
public void setTimeoutExpand(int timeoutExpand) {
|
||||
this.timeoutExpand = timeoutExpand;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,13 +16,13 @@ import okhttp3.Request;
|
|||
import okhttp3.RequestBody;
|
||||
|
||||
public class Client {
|
||||
|
||||
|
||||
|
||||
public static final String DEFAULT_CHARSET = "UTF-8";
|
||||
private static final long DEFAULT_TIMEOUT = 5000;
|
||||
private ToolingClientLogger logger;
|
||||
private FhirLoggingInterceptor fhirLoggingInterceptor;
|
||||
private int retryCount;
|
||||
private long timeout = DEFAULT_TIMEOUT;
|
||||
private String base;
|
||||
|
||||
public String getBase() {
|
||||
|
@ -51,14 +51,6 @@ public class Client {
|
|||
this.retryCount = retryCount;
|
||||
}
|
||||
|
||||
public long getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public void setTimeout(long timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public <T extends Resource> ResourceRequest<T> issueOptionsRequest(URI optionsUri, String resourceFormat,
|
||||
String message, long timeout) throws IOException {
|
||||
Request.Builder request = new Request.Builder().method("OPTIONS", null).url(optionsUri.toURL());
|
||||
|
@ -107,20 +99,20 @@ public class Client {
|
|||
return executeFhirRequest(request, resourceFormat, headers, message, retryCount, timeout);
|
||||
}
|
||||
|
||||
public boolean issueDeleteRequest(URI resourceUri) throws IOException {
|
||||
public boolean issueDeleteRequest(URI resourceUri, int timeout) throws IOException {
|
||||
Request.Builder request = new Request.Builder().url(resourceUri.toURL()).delete();
|
||||
return executeFhirRequest(request, null, new Headers.Builder().build(), null, retryCount, timeout)
|
||||
.isSuccessfulRequest();
|
||||
}
|
||||
|
||||
public Bundle issueGetFeedRequest(URI resourceUri, String resourceFormat) throws IOException {
|
||||
public Bundle issueGetFeedRequest(URI resourceUri, String resourceFormat, int timeout) throws IOException {
|
||||
Request.Builder request = new Request.Builder().url(resourceUri.toURL());
|
||||
|
||||
return executeBundleRequest(request, resourceFormat, new Headers.Builder().build(), null, retryCount, timeout);
|
||||
}
|
||||
|
||||
public Bundle issuePostFeedRequest(URI resourceUri, Map<String, String> parameters, String resourceName,
|
||||
Resource resource, String resourceFormat) throws IOException {
|
||||
Resource resource, String resourceFormat, int timeout) throws IOException {
|
||||
String boundary = "----WebKitFormBoundarykbMUo6H8QaUnYtRy";
|
||||
byte[] payload = ByteUtils.encodeFormSubmission(parameters, resourceName, resource, boundary);
|
||||
RequestBody body = RequestBody.create(MediaType.parse(resourceFormat + ";charset=" + DEFAULT_CHARSET), payload);
|
||||
|
|
Loading…
Reference in New Issue