diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR2.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR2.java index bd34dd4fe..47a1d8134 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR2.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR2.java @@ -125,8 +125,8 @@ public class TerminologyClientR2 implements ITerminologyClient { } @Override - public ITerminologyClient setTimeout(int i) { - client.setTimeout(i); + public ITerminologyClient setTimeoutFactor(int i) { + client.setTimeoutFactor(i); return this; } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR3.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR3.java index d88ace719..3e26ec6af 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR3.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR3.java @@ -123,8 +123,8 @@ public class TerminologyClientR3 implements ITerminologyClient { } @Override - public ITerminologyClient setTimeout(int i) { - client.setTimeout(i); + public ITerminologyClient setTimeoutFactor(int i) { + client.setTimeoutFactor(i); return this; } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR4.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR4.java index a67fd3fba..f2aac799a 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR4.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR4.java @@ -133,8 +133,8 @@ public class TerminologyClientR4 implements ITerminologyClient { } @Override - public ITerminologyClient setTimeout(int i) { // #FIXME - client.setTimeoutNormal(i); + public ITerminologyClient setTimeoutFactor(int i) { + client.setTimeoutFactor(i); return this; } diff --git a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR5.java b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR5.java index 0c835bbab..472cf898b 100644 --- a/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR5.java +++ b/org.hl7.fhir.convertors/src/main/java/org/hl7/fhir/convertors/txClient/TerminologyClientR5.java @@ -117,8 +117,8 @@ public class TerminologyClientR5 implements ITerminologyClient { } @Override - public ITerminologyClient setTimeout(int i) { - client.setTimeout(i); + public ITerminologyClient setTimeoutFactor(int i) { + client.setTimeoutFactor(i); return this; } diff --git a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/client/FHIRToolingClient.java b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/client/FHIRToolingClient.java index 5337d3e74..c7cf07706 100644 --- a/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.dstu2/src/main/java/org/hl7/fhir/dstu2/utils/client/FHIRToolingClient.java @@ -48,6 +48,7 @@ import org.hl7.fhir.dstu2.model.PrimitiveType; import org.hl7.fhir.dstu2.model.Resource; import org.hl7.fhir.dstu2.model.StringType; import org.hl7.fhir.dstu2.model.ValueSet; +import org.hl7.fhir.utilities.FHIRBaseToolingClient; import org.hl7.fhir.utilities.ToolingClientLogger; import org.hl7.fhir.utilities.Utilities; @@ -81,15 +82,12 @@ import org.hl7.fhir.utilities.Utilities; * @author Claude Nanjo * */ -public class FHIRToolingClient { +public class FHIRToolingClient extends FHIRBaseToolingClient { public static final String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ssK"; public static final String DATE_FORMAT = "yyyy-MM-dd"; public static final String hostKey = "http.proxyHost"; public static final String portKey = "http.proxyPort"; - private static final int TIMEOUT_NORMAL = 1; - private static final int TIMEOUT_OPERATION = 2; - private static final int TIMEOUT_OPERATION_LONG = 3; private String base; private ResourceAddress resourceAddress; @@ -179,11 +177,11 @@ public class FHIRToolingClient { try { if (useOptionsVerb) { conformance = (Conformance) utils - .issueOptionsRequest(resourceAddress.getBaseServiceUri(), getPreferredResourceFormat(), TIMEOUT_NORMAL) + .issueOptionsRequest(resourceAddress.getBaseServiceUri(), getPreferredResourceFormat(), timeoutNormal) .getReference();// TODO fix this } else { conformance = (Conformance) utils.issueGetResourceRequest(resourceAddress.resolveMetadataUri(false), - getPreferredResourceFormat(), TIMEOUT_NORMAL).getReference(); + getPreferredResourceFormat(), timeoutNormal).getReference(); } } catch (Exception e) { handleException("An error has occurred while trying to fetch the server's conformance statement", e); @@ -202,11 +200,11 @@ public class FHIRToolingClient { try { if (useOptionsVerb) { conformance = (Conformance) utils - .issueOptionsRequest(resourceAddress.getBaseServiceUri(), getPreferredResourceFormat(), TIMEOUT_NORMAL) + .issueOptionsRequest(resourceAddress.getBaseServiceUri(), getPreferredResourceFormat(), timeoutNormal) .getReference();// TODO fix this } else { conformance = (Conformance) utils.issueGetResourceRequest(resourceAddress.resolveMetadataUri(true), - getPreferredResourceFormat(), TIMEOUT_NORMAL).getReference(); + getPreferredResourceFormat(), timeoutNormal).getReference(); } } catch (Exception e) { handleException("An error has occurred while trying to fetch the server's conformance statement", e); @@ -218,7 +216,7 @@ public class FHIRToolingClient { ResourceRequest result = null; try { result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id), - getPreferredResourceFormat(), TIMEOUT_NORMAL); + getPreferredResourceFormat(), timeoutNormal); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addSuccessStatus(200);// Only one for now @@ -237,7 +235,7 @@ public class FHIRToolingClient { try { result = utils.issueGetResourceRequest( resourceAddress.resolveGetUriFromResourceClassAndIdAndVersion(resourceClass, id, version), - getPreferredResourceFormat(), TIMEOUT_NORMAL); + getPreferredResourceFormat(), timeoutNormal); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addErrorStatus(405);// unknown @@ -260,7 +258,7 @@ public class FHIRToolingClient { try { result = utils.issueGetResourceRequest( resourceAddress.resolveGetUriFromResourceClassAndCanonical(resourceClass, canonicalURL), - getPreferredResourceFormat(), TIMEOUT_NORMAL); + getPreferredResourceFormat(), timeoutNormal); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addErrorStatus(405);// unknown @@ -287,7 +285,7 @@ public class FHIRToolingClient { result = utils.issuePutRequest( resourceAddress.resolveGetUriFromResourceClassAndId(resource.getClass(), resource.getId()), utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), - getPreferredResourceFormat(), headers, TIMEOUT_OPERATION); + getPreferredResourceFormat(), headers, timeoutOperation); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addErrorStatus(405); @@ -322,7 +320,7 @@ public class FHIRToolingClient { List
headers = null; result = utils.issuePutRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id), utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), - getPreferredResourceFormat(), headers, TIMEOUT_OPERATION); + getPreferredResourceFormat(), headers, timeoutOperation); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addErrorStatus(405); @@ -530,10 +528,10 @@ public class FHIRToolingClient { if (complex) result = utils.issuePostRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), - getPreferredResourceFormat(), TIMEOUT_OPERATION_LONG); + getPreferredResourceFormat(), timeoutLong); else result = utils.issueGetResourceRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), - getPreferredResourceFormat(), TIMEOUT_OPERATION_LONG); + getPreferredResourceFormat(), timeoutLong); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addSuccessStatus(200);// Only one for now @@ -554,7 +552,7 @@ public class FHIRToolingClient { try { transactionResult = utils.postBatchRequest(resourceAddress.getBaseServiceUri(), utils.getFeedAsByteArray(batch, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), - TIMEOUT_NORMAL + batch.getEntry().size()); + timeoutNormal + batch.getEntry().size()); } catch (Exception e) { handleException("An error occurred trying to process this transaction request", e); } @@ -721,7 +719,7 @@ public class FHIRToolingClient { ResourceRequest result = utils.issuePostRequest( resourceAddress.resolveOperationUri(ValueSet.class, "expand"), utils.getResourceAsByteArray(source, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), - headers, TIMEOUT_OPERATION_LONG); + headers, timeoutLong); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addErrorStatus(405); @@ -738,7 +736,7 @@ public class FHIRToolingClient { public Parameters lookupCode(Map params) { ResourceRequest result = utils.issueGetResourceRequest( resourceAddress.resolveOperationUri(ValueSet.class, "lookup", params), getPreferredResourceFormat(), - TIMEOUT_NORMAL); + timeoutNormal); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addErrorStatus(405); @@ -802,7 +800,7 @@ public class FHIRToolingClient { ResourceRequest result = utils.issuePostRequest( resourceAddress.resolveOperationUri(null, "closure", new HashMap()), utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), - headers, TIMEOUT_NORMAL); + headers, timeoutNormal); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addErrorStatus(405); @@ -824,7 +822,7 @@ public class FHIRToolingClient { ResourceRequest result = utils.issuePostRequest( resourceAddress.resolveOperationUri(null, "closure", new HashMap()), utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), - headers, TIMEOUT_OPERATION); + headers, timeoutOperation); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addErrorStatus(405); @@ -864,7 +862,7 @@ public class FHIRToolingClient { public Parameters getTerminologyCapabilities() { return (Parameters) utils - .issueGetResourceRequest(resourceAddress.resolveMetadataTxCaps(), getPreferredResourceFormat(), TIMEOUT_NORMAL) + .issueGetResourceRequest(resourceAddress.resolveMetadataTxCaps(), getPreferredResourceFormat(), timeoutNormal) .getReference(); } @@ -899,4 +897,5 @@ public class FHIRToolingClient { public void setLanguage(String lang) { utils.setLanguage(lang); } + } \ No newline at end of file diff --git a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/client/FHIRToolingClient.java b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/client/FHIRToolingClient.java index 23e49a79b..a70da6859 100644 --- a/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.dstu2016may/src/main/java/org/hl7/fhir/dstu2016may/utils/client/FHIRToolingClient.java @@ -49,6 +49,7 @@ import org.hl7.fhir.dstu2016may.model.PrimitiveType; import org.hl7.fhir.dstu2016may.model.Resource; import org.hl7.fhir.dstu2016may.model.StringType; import org.hl7.fhir.dstu2016may.model.ValueSet; +import org.hl7.fhir.utilities.FHIRBaseToolingClient; import org.hl7.fhir.utilities.ToolingClientLogger; import org.hl7.fhir.utilities.Utilities; @@ -82,15 +83,12 @@ import org.hl7.fhir.utilities.Utilities; * @author Claude Nanjo * */ -public class FHIRToolingClient { +public class FHIRToolingClient extends FHIRBaseToolingClient { public static final String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ssK"; public static final String DATE_FORMAT = "yyyy-MM-dd"; public static final String hostKey = "http.proxyHost"; public static final String portKey = "http.proxyPort"; - private static final int TIMEOUT_NORMAL = 1; - private static final int TIMEOUT_OPERATION = 2; - private static final int TIMEOUT_OPERATION_LONG = 3; private String base; private ResourceAddress resourceAddress; @@ -177,11 +175,11 @@ public class FHIRToolingClient { try { if (useOptionsVerb) { conformance = (Conformance) utils - .issueOptionsRequest(resourceAddress.getBaseServiceUri(), getPreferredResourceFormat(), TIMEOUT_NORMAL) + .issueOptionsRequest(resourceAddress.getBaseServiceUri(), getPreferredResourceFormat(), timeoutNormal) .getReference();// TODO fix this } else { conformance = (Conformance) utils.issueGetResourceRequest(resourceAddress.resolveMetadataUri(false), - getPreferredResourceFormat(), TIMEOUT_NORMAL).getReference(); + getPreferredResourceFormat(), timeoutNormal).getReference(); } } catch (Exception e) { handleException("An error has occurred while trying to fetch the server's conformance statement", e); @@ -200,11 +198,11 @@ public class FHIRToolingClient { try { if (useOptionsVerb) { conformance = (Conformance) utils - .issueOptionsRequest(resourceAddress.getBaseServiceUri(), getPreferredResourceFormat(), TIMEOUT_NORMAL) + .issueOptionsRequest(resourceAddress.getBaseServiceUri(), getPreferredResourceFormat(), timeoutNormal) .getReference();// TODO fix this } else { conformance = (Conformance) utils.issueGetResourceRequest(resourceAddress.resolveMetadataUri(true), - getPreferredResourceFormat(), TIMEOUT_NORMAL).getReference(); + getPreferredResourceFormat(), timeoutNormal).getReference(); } } catch (Exception e) { handleException("An error has occurred while trying to fetch the server's conformance statement", e); @@ -216,7 +214,7 @@ public class FHIRToolingClient { ResourceRequest result = null; try { result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id), - getPreferredResourceFormat(), TIMEOUT_NORMAL); + getPreferredResourceFormat(), timeoutNormal); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addSuccessStatus(200);// Only one for now @@ -235,7 +233,7 @@ public class FHIRToolingClient { try { result = utils.issueGetResourceRequest( resourceAddress.resolveGetUriFromResourceClassAndIdAndVersion(resourceClass, id, version), - getPreferredResourceFormat(), TIMEOUT_NORMAL); + getPreferredResourceFormat(), timeoutNormal); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addErrorStatus(405);// unknown @@ -258,7 +256,7 @@ public class FHIRToolingClient { try { result = utils.issueGetResourceRequest( resourceAddress.resolveGetUriFromResourceClassAndCanonical(resourceClass, canonicalURL), - getPreferredResourceFormat(), TIMEOUT_NORMAL); + getPreferredResourceFormat(), timeoutNormal); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addErrorStatus(405);// unknown @@ -285,7 +283,7 @@ public class FHIRToolingClient { result = utils.issuePutRequest( resourceAddress.resolveGetUriFromResourceClassAndId(resource.getClass(), resource.getId()), utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), - getPreferredResourceFormat(), headers, TIMEOUT_OPERATION); + getPreferredResourceFormat(), headers, timeoutOperation); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addErrorStatus(405); @@ -320,7 +318,7 @@ public class FHIRToolingClient { List
headers = null; result = utils.issuePutRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id), utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), - getPreferredResourceFormat(), headers, TIMEOUT_OPERATION); + getPreferredResourceFormat(), headers, timeoutOperation); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addErrorStatus(405); @@ -529,10 +527,10 @@ public class FHIRToolingClient { if (complex) result = utils.issuePostRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), - getPreferredResourceFormat(), TIMEOUT_OPERATION_LONG); + getPreferredResourceFormat(), timeoutLong); else result = utils.issueGetResourceRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), - getPreferredResourceFormat(), TIMEOUT_OPERATION_LONG); + getPreferredResourceFormat(), timeoutLong); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addSuccessStatus(200);// Only one for now @@ -558,7 +556,7 @@ public class FHIRToolingClient { try { transactionResult = utils.postBatchRequest(resourceAddress.getBaseServiceUri(), utils.getFeedAsByteArray(batch, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), - TIMEOUT_NORMAL + batch.getEntry().size()); + timeoutNormal + batch.getEntry().size()); } catch (Exception e) { handleException("An error occurred trying to process this transaction request", e); } @@ -745,7 +743,7 @@ public class FHIRToolingClient { public Parameters lookupCode(Map params) { ResourceRequest result = utils.issueGetResourceRequest( resourceAddress.resolveOperationUri(CodeSystem.class, "lookup", params), getPreferredResourceFormat(), - TIMEOUT_NORMAL); + timeoutNormal); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addErrorStatus(405); @@ -809,7 +807,7 @@ public class FHIRToolingClient { ResourceRequest result = utils.issuePostRequest( resourceAddress.resolveOperationUri(null, "closure", new HashMap()), utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), - headers, TIMEOUT_NORMAL); + headers, timeoutNormal); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addErrorStatus(405); @@ -831,7 +829,7 @@ public class FHIRToolingClient { ResourceRequest result = utils.issuePostRequest( resourceAddress.resolveOperationUri(null, "closure", new HashMap()), utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), - headers, TIMEOUT_OPERATION); + headers, timeoutOperation); result.addErrorStatus(410);// gone result.addErrorStatus(404);// unknown result.addErrorStatus(405); @@ -871,7 +869,7 @@ public class FHIRToolingClient { public Parameters getTerminologyCapabilities() { return (Parameters) utils - .issueGetResourceRequest(resourceAddress.resolveMetadataTxCaps(), getPreferredResourceFormat(), TIMEOUT_NORMAL) + .issueGetResourceRequest(resourceAddress.resolveMetadataTxCaps(), getPreferredResourceFormat(), timeoutNormal) .getReference(); } diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/client/FHIRToolingClient.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/client/FHIRToolingClient.java index 0c549bdc1..de19a3706 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/client/FHIRToolingClient.java @@ -26,6 +26,7 @@ import org.hl7.fhir.dstu3.utils.client.network.ByteUtils; import org.hl7.fhir.dstu3.utils.client.network.Client; import org.hl7.fhir.dstu3.utils.client.network.ResourceRequest; import org.hl7.fhir.exceptions.FHIRException; +import org.hl7.fhir.utilities.FHIRBaseToolingClient; import org.hl7.fhir.utilities.FhirPublication; import org.hl7.fhir.utilities.ToolingClientLogger; import org.hl7.fhir.utilities.Utilities; @@ -58,19 +59,13 @@ import okhttp3.internal.http2.Header; * * @author Claude Nanjo */ -public class FHIRToolingClient { +public class FHIRToolingClient extends FHIRBaseToolingClient { public static final String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ssK"; public static final String DATE_FORMAT = "yyyy-MM-dd"; 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 String base; private ResourceAddress resourceAddress; private ResourceFormat preferredResourceFormat; @@ -155,7 +150,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "TerminologyCapabilities", - TIMEOUT_NORMAL).getReference(); + timeoutNormal).getReference(); } catch (Exception e) { throw new FHIRException("Error fetching the server's terminology capabilities", e); } @@ -169,7 +164,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "CapabilitiesStatement", - TIMEOUT_NORMAL).getReference(); + timeoutNormal).getReference(); } catch (Exception e) { throw new FHIRException("Error fetching the server's conformance statement", e); } @@ -183,7 +178,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "CapabilitiesStatement-Quick", - TIMEOUT_NORMAL).getReference(); + timeoutNormal).getReference(); } catch (Exception e) { throw new FHIRException("Error fetching the server's capability statement: "+e.getMessage(), e); } @@ -197,7 +192,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "Read " + resourceClass.getName() + "/" + id, - TIMEOUT_NORMAL); + timeoutNormal); if (result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); } @@ -214,7 +209,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "VRead " + resourceClass.getName() + "/" + id + "/?_history/" + version, - TIMEOUT_NORMAL); + timeoutNormal); if (result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); } @@ -231,7 +226,7 @@ public class FHIRToolingClient { 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()); } @@ -254,7 +249,7 @@ public class FHIRToolingClient { 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()); } @@ -281,7 +276,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "Update " + resource.fhirType() + "/" + id, - TIMEOUT_OPERATION); + timeoutOperation); if (result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); } @@ -318,12 +313,12 @@ public class FHIRToolingClient { client.getLogger().logRequest("POST", url.toString(), null, body); } result = client.issuePostRequest(url, body, getPreferredResourceFormat(), generateHeaders(), - "POST " + resourceClass.getName() + "/$" + name, TIMEOUT_OPERATION_LONG); + "POST " + resourceClass.getName() + "/$" + name, timeoutLong); } else { if (client.getLogger() != null) { client.getLogger().logRequest("GET", url.toString(), null, null); } - result = client.issueGetResourceRequest(url, getPreferredResourceFormat(), generateHeaders(), "GET " + resourceClass.getName() + "/$" + name, TIMEOUT_OPERATION_LONG); + result = client.issueGetResourceRequest(url, getPreferredResourceFormat(), generateHeaders(), "GET " + resourceClass.getName() + "/$" + name, timeoutLong); } if (result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); @@ -345,7 +340,7 @@ public class FHIRToolingClient { public Bundle transaction(Bundle batch) { Bundle transactionResult = null; try { - transactionResult = client.postBatchRequest(resourceAddress.getBaseServiceUri(), ByteUtils.resourceToByteArray(batch, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), "transaction", TIMEOUT_OPERATION + (TIMEOUT_ENTRY * batch.getEntry().size())); + transactionResult = client.postBatchRequest(resourceAddress.getBaseServiceUri(), ByteUtils.resourceToByteArray(batch, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), "transaction", timeoutOperation + (timeoutEntry * batch.getEntry().size())); } catch (Exception e) { handleException("An error occurred trying to process this transaction request", e); } @@ -359,7 +354,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()); } @@ -418,7 +413,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "ValueSet/$expand?url=" + source.getUrl(), - TIMEOUT_OPERATION_EXPAND); + timeoutExpand); if (result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); } @@ -436,7 +431,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "CodeSystem/$lookup", - TIMEOUT_NORMAL); + timeoutNormal); } catch (IOException e) { e.printStackTrace(); } @@ -459,7 +454,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "ValueSet/$expand?url=" + source.getUrl(), - TIMEOUT_OPERATION_EXPAND); + timeoutExpand); if (result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); } @@ -483,7 +478,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "ValueSet/$expand?url=" + source.getUrl(), - TIMEOUT_OPERATION_EXPAND); + timeoutExpand); if (result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); } @@ -507,7 +502,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "Closure?name=" + name, - TIMEOUT_NORMAL); + timeoutNormal); if (result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); } @@ -528,7 +523,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "UpdateClosure?name=" + name, - TIMEOUT_OPERATION); + timeoutOperation); if (result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); } diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/FHIRToolingClient.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/FHIRToolingClient.java index 543921341..a5a707bf0 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/FHIRToolingClient.java @@ -25,6 +25,7 @@ import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.r4.utils.client.network.ByteUtils; import org.hl7.fhir.r4.utils.client.network.Client; import org.hl7.fhir.r4.utils.client.network.ResourceRequest; +import org.hl7.fhir.utilities.FHIRBaseToolingClient; import org.hl7.fhir.utilities.ToolingClientLogger; import org.hl7.fhir.utilities.Utilities; @@ -60,19 +61,13 @@ import okhttp3.internal.http2.Header; * * @author Claude Nanjo */ -public class FHIRToolingClient { +public class FHIRToolingClient extends FHIRBaseToolingClient { public static final String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ssK"; public static final String DATE_FORMAT = "yyyy-MM-dd"; public static final String hostKey = "http.proxyHost"; public static final String portKey = "http.proxyPort"; - 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,11 +79,6 @@ 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 { @@ -640,44 +630,4 @@ public class FHIRToolingClient { } - 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; - } - } diff --git a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/client/FHIRToolingClient.java b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/client/FHIRToolingClient.java index 3bb65d634..965918354 100644 --- a/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.r4b/src/main/java/org/hl7/fhir/r4b/utils/client/FHIRToolingClient.java @@ -39,6 +39,7 @@ import org.hl7.fhir.r4b.utils.client.network.ByteUtils; import org.hl7.fhir.r4b.utils.client.network.Client; import org.hl7.fhir.r4b.utils.client.network.ClientHeaders; import org.hl7.fhir.r4b.utils.client.network.ResourceRequest; +import org.hl7.fhir.utilities.FHIRBaseToolingClient; import org.hl7.fhir.utilities.ToolingClientLogger; import org.hl7.fhir.utilities.Utilities; @@ -77,19 +78,13 @@ import java.util.*; * * @author Claude Nanjo */ -public class FHIRToolingClient { +public class FHIRToolingClient extends FHIRBaseToolingClient{ public static final String DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ssK"; public static final String DATE_FORMAT = "yyyy-MM-dd"; 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 String base; private ResourceAddress resourceAddress; private ResourceFormat preferredResourceFormat; @@ -151,7 +146,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); } @@ -162,7 +157,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); } @@ -174,7 +169,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); @@ -187,7 +182,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()); @@ -204,7 +199,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()); @@ -221,7 +216,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()); @@ -244,7 +239,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()); @@ -273,7 +268,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()); @@ -311,10 +306,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(), @@ -340,7 +335,7 @@ public class FHIRToolingClient { transactionResult = client.postBatchRequest(resourceAddress.getBaseServiceUri(), ByteUtils.resourceToByteArray(batch, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), generateHeaders(), "transaction", - TIMEOUT_OPERATION + (TIMEOUT_ENTRY * batch.getEntry().size())); + timeoutOperation + (timeoutEntry * batch.getEntry().size())); } catch (Exception e) { handleException("An error occurred trying to process this transaction request", e); } @@ -354,7 +349,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()); @@ -411,7 +406,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()); @@ -426,7 +421,7 @@ public class FHIRToolingClient { org.hl7.fhir.r4b.utils.client.network.ResourceRequest 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) { e.printStackTrace(); } @@ -448,7 +443,7 @@ public class FHIRToolingClient { result = client.issuePostRequest(resourceAddress.resolveOperationUri(ValueSet.class, "expand", params), 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()); @@ -471,7 +466,7 @@ public class FHIRToolingClient { result = client.issuePostRequest( resourceAddress.resolveOperationUri(null, "closure", new HashMap()), 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()); @@ -491,7 +486,7 @@ public class FHIRToolingClient { result = client.issuePostRequest( resourceAddress.resolveOperationUri(null, "closure", new HashMap()), 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()); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/client/ITerminologyClient.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/client/ITerminologyClient.java index 156b1cb00..2e0f5edf2 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/client/ITerminologyClient.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/terminologies/client/ITerminologyClient.java @@ -54,7 +54,7 @@ public interface ITerminologyClient { ValueSet expandValueset(ValueSet vs, Parameters p, Map params) throws FHIRException; Parameters validateCS(Parameters pin) throws FHIRException; Parameters validateVS(Parameters pin) throws FHIRException; - ITerminologyClient setTimeout(int i) throws FHIRException; + ITerminologyClient setTimeoutFactor(int i) throws FHIRException; ITerminologyClient setLogger(ToolingClientLogger txLog) throws FHIRException; int getRetryCount() throws FHIRException; ITerminologyClient setRetryCount(int retryCount) throws FHIRException; diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java index 5cf6d9fa8..290581b31 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/FHIRToolingClient.java @@ -38,6 +38,7 @@ import org.hl7.fhir.r5.model.Parameters.ParametersParameterComponent; import org.hl7.fhir.r5.utils.client.network.ByteUtils; import org.hl7.fhir.r5.utils.client.network.Client; import org.hl7.fhir.r5.utils.client.network.ResourceRequest; +import org.hl7.fhir.utilities.FHIRBaseToolingClient; import org.hl7.fhir.utilities.ToolingClientLogger; import org.hl7.fhir.utilities.Utilities; import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager; @@ -76,7 +77,7 @@ import java.util.stream.Stream; * * @author Claude Nanjo */ -public class FHIRToolingClient { +public class FHIRToolingClient extends FHIRBaseToolingClient { private static final Logger logger = LoggerFactory.getLogger(FHIRToolingClient.class); @@ -86,12 +87,6 @@ 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 String base; private ResourceAddress resourceAddress; private ResourceFormat preferredResourceFormat; @@ -160,7 +155,7 @@ public class FHIRToolingClient { preferredResourceFormat.getHeader(), generateHeaders(), message, - TIMEOUT_NORMAL).getReference(); + timeoutNormal).getReference(); if (attemptedResourceFormat != preferredResourceFormat) { setPreferredResourceFormat(attemptedResourceFormat); } @@ -212,7 +207,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "Read " + resourceClass.getName() + "/" + id, - TIMEOUT_NORMAL); + timeoutNormal); if (result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); } @@ -229,7 +224,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "VRead " + resourceClass.getName() + "/" + id + "/?_history/" + version, - TIMEOUT_NORMAL); + timeoutNormal); if (result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); } @@ -246,7 +241,7 @@ public class FHIRToolingClient { 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()); } @@ -269,7 +264,7 @@ public class FHIRToolingClient { 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()); } @@ -296,7 +291,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "Update " + resource.fhirType() + "/" + id, - TIMEOUT_OPERATION); + timeoutOperation); if (result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); } @@ -330,9 +325,9 @@ 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); + result = client.issueGetResourceRequest(url, getPreferredResourceFormat(), generateHeaders(), "GET " + resourceClass.getName() + "/$" + name, timeoutLong); } if (result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); @@ -355,7 +350,7 @@ public class FHIRToolingClient { try { transactionResult = client.postBatchRequest(resourceAddress.getBaseServiceUri(), ByteUtils.resourceToByteArray(batch, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), generateHeaders(), - "transaction", TIMEOUT_OPERATION + (TIMEOUT_ENTRY * batch.getEntry().size())); + "transaction", timeoutOperation + (timeoutEntry * batch.getEntry().size())); } catch (Exception e) { handleException("An error occurred trying to process this transaction request", e); } @@ -369,7 +364,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()); } @@ -428,7 +423,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "ValueSet/$expand?url=" + source.getUrl(), - TIMEOUT_OPERATION_EXPAND); + timeoutExpand); } catch (IOException e) { throw new FHIRException(e); } @@ -446,7 +441,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "CodeSystem/$lookup", - TIMEOUT_NORMAL); + timeoutNormal); } catch (IOException e) { e.printStackTrace(); } @@ -475,7 +470,7 @@ public class FHIRToolingClient { 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()); } @@ -499,7 +494,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "Closure?name=" + name, - TIMEOUT_NORMAL); + timeoutNormal); if (result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); } @@ -520,7 +515,7 @@ public class FHIRToolingClient { getPreferredResourceFormat(), generateHeaders(), "UpdateClosure?name=" + name, - TIMEOUT_OPERATION); + timeoutOperation); if (result.isUnsuccessfulRequest()) { throw new EFhirClientException("Server returned error code " + result.getHttpStatus(), (OperationOutcome) result.getPayload()); } diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/FHIRBaseToolingClient.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/FHIRBaseToolingClient.java new file mode 100644 index 000000000..bc9d5e83f --- /dev/null +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/FHIRBaseToolingClient.java @@ -0,0 +1,68 @@ +package org.hl7.fhir.utilities; + + +public class FHIRBaseToolingClient { + + 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; + + protected int timeoutNormal = DEFAULT_TIMEOUT_NORMAL; + protected int timeoutOperation = DEFAULT_TIMEOUT_OPERATION; + protected int timeoutEntry = DEFAULT_TIMEOUT_ENTRY; + protected int timeoutLong = DEFAULT_TIMEOUT_OPERATION_LONG; + protected int timeoutExpand = DEFAULT_TIMEOUT_OPERATION_EXPAND; + + + 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; + } + + + public void setTimeoutFactor(int i) { + timeoutNormal = i * DEFAULT_TIMEOUT_NORMAL; + timeoutOperation = i * DEFAULT_TIMEOUT_OPERATION; + timeoutEntry = i * DEFAULT_TIMEOUT_ENTRY; + timeoutLong = i * DEFAULT_TIMEOUT_OPERATION_LONG; + timeoutExpand = i * DEFAULT_TIMEOUT_OPERATION_EXPAND; + } + +}