From 3f6207bf4fb0d9c6738d32bb1682a4cb0921e7cb Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 6 Aug 2020 07:35:49 +1000 Subject: [PATCH] improve handling of timeout issues in client --- .../fhir/dstu3/utils/client/ClientUtils.java | 55 +++++++----- .../dstu3/utils/client/FHIRToolingClient.java | 40 +++++---- .../hl7/fhir/r4/utils/client/ClientUtils.java | 55 +++++++----- .../r4/utils/client/FHIRToolingClient.java | 38 ++++---- .../hl7/fhir/r5/utils/client/ClientUtils.java | 88 ++++++++++--------- .../r5/utils/client/FHIRToolingClient.java | 37 ++++---- 6 files changed, 175 insertions(+), 138 deletions(-) diff --git a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/client/ClientUtils.java b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/client/ClientUtils.java index 68abe73d8..ddee4790f 100644 --- a/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/client/ClientUtils.java +++ b/org.hl7.fhir.dstu3/src/main/java/org/hl7/fhir/dstu3/utils/client/ClientUtils.java @@ -96,6 +96,7 @@ public class ClientUtils { public static final String DEFAULT_CHARSET = "UTF-8"; public static final String HEADER_LOCATION = "location"; + private static boolean debugging = false; private HttpHost proxy; private int timeout = 5000; @@ -136,34 +137,34 @@ public class ClientUtils { this.password = password; } - public ResourceRequest issueOptionsRequest(URI optionsUri, String resourceFormat) { + public ResourceRequest issueOptionsRequest(URI optionsUri, String resourceFormat, int timeoutLoading) { HttpOptions options = new HttpOptions(optionsUri); - return issueResourceRequest(resourceFormat, options); + return issueResourceRequest(resourceFormat, options, timeoutLoading); } - public ResourceRequest issueGetResourceRequest(URI resourceUri, String resourceFormat) { + public ResourceRequest issueGetResourceRequest(URI resourceUri, String resourceFormat, int timeoutLoading) { HttpGet httpget = new HttpGet(resourceUri); - return issueResourceRequest(resourceFormat, httpget); + return issueResourceRequest(resourceFormat, httpget, timeoutLoading); } - public ResourceRequest issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, List
headers) { + public ResourceRequest issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, List
headers, int timeoutLoading) { HttpPut httpPut = new HttpPut(resourceUri); - return issueResourceRequest(resourceFormat, httpPut, payload, headers); + return issueResourceRequest(resourceFormat, httpPut, payload, headers, timeoutLoading); } - public ResourceRequest issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat) { + public ResourceRequest issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, int timeoutLoading) { HttpPut httpPut = new HttpPut(resourceUri); - return issueResourceRequest(resourceFormat, httpPut, payload, null); + return issueResourceRequest(resourceFormat, httpPut, payload, null, timeoutLoading); } - public ResourceRequest issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, List
headers) { + public ResourceRequest issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, List
headers, int timeoutLoading) { HttpPost httpPost = new HttpPost(resourceUri); - return issueResourceRequest(resourceFormat, httpPost, payload, headers); + return issueResourceRequest(resourceFormat, httpPost, payload, headers, timeoutLoading); } - public ResourceRequest issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat) { - return issuePostRequest(resourceUri, payload, resourceFormat, null); + public ResourceRequest issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, int timeoutLoading) { + return issuePostRequest(resourceUri, payload, resourceFormat, null, timeoutLoading); } public Bundle issueGetFeedRequest(URI resourceUri, String resourceFormat) { @@ -184,10 +185,10 @@ public class ClientUtils { } } - public Bundle postBatchRequest(URI resourceUri, byte[] payload, String resourceFormat) { + public Bundle postBatchRequest(URI resourceUri, byte[] payload, String resourceFormat, int timeoutLoading) { HttpPost httpPost = new HttpPost(resourceUri); configureFhirRequest(httpPost, resourceFormat); - HttpResponse response = sendPayload(httpPost, payload, proxy); + HttpResponse response = sendPayload(httpPost, payload, proxy, timeoutLoading); return unmarshalFeed(response, resourceFormat); } @@ -206,8 +207,8 @@ public class ClientUtils { * Request/Response Helper methods ***********************************************************/ - protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request) { - return issueResourceRequest(resourceFormat, request, null); + protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request, int timeoutLoading) { + return issueResourceRequest(resourceFormat, request, null, timeoutLoading); } /** @@ -215,8 +216,8 @@ public class ClientUtils { * @param options * @return */ - protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload) { - return issueResourceRequest(resourceFormat, request, payload, null); + protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, int timeoutLoading) { + return issueResourceRequest(resourceFormat, request, payload, null, timeoutLoading); } /** @@ -224,11 +225,11 @@ public class ClientUtils { * @param options * @return */ - protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, List
headers) { + protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, List
headers, int timeoutLoading) { configureFhirRequest(request, resourceFormat, headers); HttpResponse response = null; if(request instanceof HttpEntityEnclosingRequest && payload != null) { - response = sendPayload((HttpEntityEnclosingRequestBase)request, payload, proxy); + response = sendPayload((HttpEntityEnclosingRequestBase)request, payload, proxy, timeoutLoading); } else if (request instanceof HttpEntityEnclosingRequest && payload == null){ throw new EFhirClientException("PUT and POST requests require a non-null payload"); } else { @@ -278,14 +279,20 @@ public class ClientUtils { * @param payload * @return */ - protected HttpResponse sendPayload(HttpEntityEnclosingRequestBase request, byte[] payload, HttpHost proxy) { + @SuppressWarnings({ "resource", "deprecation" }) + protected HttpResponse sendPayload(HttpEntityEnclosingRequestBase request, byte[] payload, HttpHost proxy, int timeoutLoading) { HttpResponse response = null; boolean ok = false; + long t = System.currentTimeMillis(); int tryCount = 0; while (!ok) { try { tryCount++; HttpClient httpclient = new DefaultHttpClient(); + HttpParams params = httpclient.getParams(); + HttpConnectionParams.setConnectionTimeout(params, timeout); + HttpConnectionParams.setSoTimeout(params, timeout * timeoutLoading); + if(proxy != null) { httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } @@ -294,7 +301,8 @@ public class ClientUtils { response = httpclient.execute(request); ok = true; } catch(IOException ioe) { - if (tryCount <= retryCount) { + System.out.println(ioe.getMessage()+" ("+(System.currentTimeMillis()-t)+"ms / "+Utilities.describeSize(payload.length)+")"); + if (tryCount <= retryCount || (tryCount < 3 && ioe instanceof org.apache.http.conn.ConnectTimeoutException)) { ok = false; } else { throw new EFhirClientException("Error sending HTTP Post/Put Payload: "+ioe.getMessage(), ioe); @@ -323,6 +331,9 @@ public class ClientUtils { } response = httpclient.execute(request); } catch(IOException ioe) { + if (ClientUtils.debugging ) { + ioe.printStackTrace(); + } throw new EFhirClientException("Error sending Http Request: "+ioe.getMessage(), ioe); } return response; 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 78f85afe8..d5b371957 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 @@ -89,7 +89,10 @@ public class FHIRToolingClient { 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; private ResourceFormat preferredResourceFormat; @@ -168,7 +171,7 @@ public class FHIRToolingClient { public CapabilityStatement getCapabilitiesStatement() { CapabilityStatement conformance = null; try { - conformance = (CapabilityStatement)utils.issueGetResourceRequest(resourceAddress.resolveMetadataUri(false), getPreferredResourceFormat()).getReference(); + conformance = (CapabilityStatement)utils.issueGetResourceRequest(resourceAddress.resolveMetadataUri(false), getPreferredResourceFormat(), TIMEOUT_NORMAL).getReference(); } catch(Exception e) { handleException("An error has occurred while trying to fetch the server's conformance statement", e); } @@ -179,7 +182,7 @@ public class FHIRToolingClient { if (capabilities != null) return capabilities; try { - capabilities = (CapabilityStatement)utils.issueGetResourceRequest(resourceAddress.resolveMetadataUri(true), getPreferredResourceFormat()).getReference(); + capabilities = (CapabilityStatement)utils.issueGetResourceRequest(resourceAddress.resolveMetadataUri(true), getPreferredResourceFormat(), TIMEOUT_NORMAL).getReference(); } catch(Exception e) { handleException("An error has occurred while trying to fetch the server's conformance statement", e); } @@ -189,7 +192,7 @@ public class FHIRToolingClient { public T read(Class resourceClass, String id) {//TODO Change this to AddressableResource ResourceRequest result = null; try { - result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id), getPreferredResourceFormat()); + result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id), getPreferredResourceFormat(), TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addSuccessStatus(200);//Only one for now @@ -205,7 +208,7 @@ public class FHIRToolingClient { public T vread(Class resourceClass, String id, String version) { ResourceRequest result = null; try { - result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndIdAndVersion(resourceClass, id, version), getPreferredResourceFormat()); + result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndIdAndVersion(resourceClass, id, version), getPreferredResourceFormat(), TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405);//unknown @@ -224,7 +227,7 @@ public class FHIRToolingClient { public T getCanonical(Class resourceClass, String canonicalURL) { ResourceRequest result = null; try { - result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndCanonical(resourceClass, canonicalURL), getPreferredResourceFormat()); + result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndCanonical(resourceClass, canonicalURL), getPreferredResourceFormat(), TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405);//unknown @@ -248,7 +251,7 @@ public class FHIRToolingClient { ResourceRequest result = null; try { List
headers = null; - result = utils.issuePutRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resource.getClass(), resource.getId()),utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + result = utils.issuePutRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resource.getClass(), resource.getId()),utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -277,7 +280,7 @@ public class FHIRToolingClient { ResourceRequest result = null; try { List
headers = null; - result = utils.issuePutRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id),utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + result = utils.issuePutRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id),utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -481,9 +484,9 @@ public class FHIRToolingClient { ps += p.getName() + "=" + Utilities.encodeUri(((PrimitiveType) p.getValue()).asStringValue())+"&"; ResourceRequest result; if (complex) - result = utils.issuePostRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat()); + result = utils.issuePostRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), TIMEOUT_OPERATION); else - result = utils.issueGetResourceRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), getPreferredResourceFormat()); + result = utils.issueGetResourceRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), getPreferredResourceFormat(), TIMEOUT_OPERATION); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addSuccessStatus(200);//Only one for now @@ -506,7 +509,7 @@ public class FHIRToolingClient { public Bundle transaction(Bundle batch) { Bundle transactionResult = null; try { - transactionResult = utils.postBatchRequest(resourceAddress.getBaseServiceUri(), utils.getFeedAsByteArray(batch, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat()); + transactionResult = utils.postBatchRequest(resourceAddress.getBaseServiceUri(), utils.getFeedAsByteArray(batch, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), TIMEOUT_NORMAL+batch.getEntry().size()); } catch (Exception e) { handleException("An error occurred trying to process this transaction request", e); } @@ -514,11 +517,10 @@ public class FHIRToolingClient { } @SuppressWarnings("unchecked") - public OperationOutcome validate(Class resourceClass, T resource, String id) { ResourceRequest result = null; try { - result = utils.issuePostRequest(resourceAddress.resolveValidateUri(resourceClass, id), utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat()); + result = utils.issuePostRequest(resourceAddress.resolveValidateUri(resourceClass, id), utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), TIMEOUT_OPERATION); result.addErrorStatus(400);//gone result.addErrorStatus(422);//Unprocessable Entity result.addSuccessStatus(200);//OK @@ -692,7 +694,7 @@ public class FHIRToolingClient { if (profile != null) p.addParameter().setName("profile").setResource(profile); ResourceRequest result = utils.issuePostRequest(resourceAddress.resolveOperationUri(ValueSet.class, "expand"), - utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, 4); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -707,7 +709,7 @@ public class FHIRToolingClient { public Parameters lookupCode(Map params) { - ResourceRequest result = utils.issueGetResourceRequest(resourceAddress.resolveOperationUri(CodeSystem.class, "lookup", params), getPreferredResourceFormat()); + ResourceRequest result = utils.issueGetResourceRequest(resourceAddress.resolveOperationUri(CodeSystem.class, "lookup", params), getPreferredResourceFormat(), TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -728,7 +730,7 @@ public class FHIRToolingClient { for (String n : params.keySet()) p.addParameter().setName(n).setValue(new StringType(params.get(n))); ResourceRequest result = utils.issuePostRequest(resourceAddress.resolveOperationUri(ValueSet.class, "expand", params), - utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, 4); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -767,7 +769,7 @@ public class FHIRToolingClient { params.addParameter().setName("name").setValue(new StringType(name)); List
headers = null; ResourceRequest result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap()), - utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -786,7 +788,7 @@ public class FHIRToolingClient { params.addParameter().setName("concept").setValue(coding); List
headers = null; ResourceRequest result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap()), - utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -825,7 +827,7 @@ public class FHIRToolingClient { public Parameters getTerminologyCapabilities() { - return (Parameters) utils.issueGetResourceRequest(resourceAddress.resolveMetadataTxCaps(), getPreferredResourceFormat()).getReference(); + return (Parameters) utils.issueGetResourceRequest(resourceAddress.resolveMetadataTxCaps(), getPreferredResourceFormat(), TIMEOUT_NORMAL).getReference(); } diff --git a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/ClientUtils.java b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/ClientUtils.java index 87cdc7519..226f158bc 100644 --- a/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/ClientUtils.java +++ b/org.hl7.fhir.r4/src/main/java/org/hl7/fhir/r4/utils/client/ClientUtils.java @@ -96,6 +96,7 @@ public class ClientUtils { public static final String DEFAULT_CHARSET = "UTF-8"; public static final String HEADER_LOCATION = "location"; + private static boolean debugging = false; private HttpHost proxy; private int timeout = 5000; @@ -136,34 +137,34 @@ public class ClientUtils { this.password = password; } - public ResourceRequest issueOptionsRequest(URI optionsUri, String resourceFormat) { + public ResourceRequest issueOptionsRequest(URI optionsUri, String resourceFormat, int timeoutLoading) { HttpOptions options = new HttpOptions(optionsUri); - return issueResourceRequest(resourceFormat, options); + return issueResourceRequest(resourceFormat, options, timeoutLoading); } - public ResourceRequest issueGetResourceRequest(URI resourceUri, String resourceFormat) { + public ResourceRequest issueGetResourceRequest(URI resourceUri, String resourceFormat, int timeoutLoading) { HttpGet httpget = new HttpGet(resourceUri); - return issueResourceRequest(resourceFormat, httpget); + return issueResourceRequest(resourceFormat, httpget, timeoutLoading); } - public ResourceRequest issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, List
headers) { + public ResourceRequest issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, List
headers, int timeoutLoading) { HttpPut httpPut = new HttpPut(resourceUri); - return issueResourceRequest(resourceFormat, httpPut, payload, headers); + return issueResourceRequest(resourceFormat, httpPut, payload, headers, timeoutLoading); } - public ResourceRequest issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat) { + public ResourceRequest issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, int timeoutLoading) { HttpPut httpPut = new HttpPut(resourceUri); - return issueResourceRequest(resourceFormat, httpPut, payload, null); + return issueResourceRequest(resourceFormat, httpPut, payload, null, timeoutLoading); } - public ResourceRequest issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, List
headers) { + public ResourceRequest issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, List
headers, int timeoutLoading) { HttpPost httpPost = new HttpPost(resourceUri); - return issueResourceRequest(resourceFormat, httpPost, payload, headers); + return issueResourceRequest(resourceFormat, httpPost, payload, headers, timeoutLoading); } - public ResourceRequest issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat) { - return issuePostRequest(resourceUri, payload, resourceFormat, null); + public ResourceRequest issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, int timeoutLoading) { + return issuePostRequest(resourceUri, payload, resourceFormat, null, timeoutLoading); } public Bundle issueGetFeedRequest(URI resourceUri, String resourceFormat) { @@ -184,10 +185,10 @@ public class ClientUtils { } } - public Bundle postBatchRequest(URI resourceUri, byte[] payload, String resourceFormat) { + public Bundle postBatchRequest(URI resourceUri, byte[] payload, String resourceFormat, int timeoutLoading) { HttpPost httpPost = new HttpPost(resourceUri); configureFhirRequest(httpPost, resourceFormat); - HttpResponse response = sendPayload(httpPost, payload, proxy); + HttpResponse response = sendPayload(httpPost, payload, proxy, timeoutLoading); return unmarshalFeed(response, resourceFormat); } @@ -206,8 +207,8 @@ public class ClientUtils { * Request/Response Helper methods ***********************************************************/ - protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request) { - return issueResourceRequest(resourceFormat, request, null); + protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request, int timeoutLoading) { + return issueResourceRequest(resourceFormat, request, null, timeoutLoading); } /** @@ -215,8 +216,8 @@ public class ClientUtils { * @param options * @return */ - protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload) { - return issueResourceRequest(resourceFormat, request, payload, null); + protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, int timeoutLoading) { + return issueResourceRequest(resourceFormat, request, payload, null, timeoutLoading); } /** @@ -224,11 +225,11 @@ public class ClientUtils { * @param options * @return */ - protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, List
headers) { + protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, List
headers, int timeoutLoading) { configureFhirRequest(request, resourceFormat, headers); HttpResponse response = null; if(request instanceof HttpEntityEnclosingRequest && payload != null) { - response = sendPayload((HttpEntityEnclosingRequestBase)request, payload, proxy); + response = sendPayload((HttpEntityEnclosingRequestBase)request, payload, proxy, timeoutLoading); } else if (request instanceof HttpEntityEnclosingRequest && payload == null){ throw new EFhirClientException("PUT and POST requests require a non-null payload"); } else { @@ -278,14 +279,20 @@ public class ClientUtils { * @param payload * @return */ - protected HttpResponse sendPayload(HttpEntityEnclosingRequestBase request, byte[] payload, HttpHost proxy) { + @SuppressWarnings({ "resource", "deprecation" }) + protected HttpResponse sendPayload(HttpEntityEnclosingRequestBase request, byte[] payload, HttpHost proxy, int timeoutLoading) { HttpResponse response = null; boolean ok = false; + long t = System.currentTimeMillis(); int tryCount = 0; while (!ok) { try { tryCount++; HttpClient httpclient = new DefaultHttpClient(); + HttpParams params = httpclient.getParams(); + HttpConnectionParams.setConnectionTimeout(params, timeout); + HttpConnectionParams.setSoTimeout(params, timeout * timeoutLoading); + if(proxy != null) { httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } @@ -294,7 +301,8 @@ public class ClientUtils { response = httpclient.execute(request); ok = true; } catch(IOException ioe) { - if (tryCount <= retryCount) { + System.out.println(ioe.getMessage()+" ("+(System.currentTimeMillis()-t)+"ms / "+Utilities.describeSize(payload.length)+")"); + if (tryCount <= retryCount || (tryCount < 3 && ioe instanceof org.apache.http.conn.ConnectTimeoutException)) { ok = false; } else { throw new EFhirClientException("Error sending HTTP Post/Put Payload: "+ioe.getMessage(), ioe); @@ -323,6 +331,9 @@ public class ClientUtils { } response = httpclient.execute(request); } catch(IOException ioe) { + if (ClientUtils.debugging ) { + ioe.printStackTrace(); + } throw new EFhirClientException("Error sending Http Request: "+ioe.getMessage(), ioe); } return response; 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 589903d1c..75ee51863 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 @@ -89,6 +89,9 @@ public class FHIRToolingClient { 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; @@ -165,13 +168,13 @@ public class FHIRToolingClient { } public TerminologyCapabilities getTerminologyCapabilities() { - return (TerminologyCapabilities) utils.issueGetResourceRequest(resourceAddress.resolveMetadataTxCaps(), getPreferredResourceFormat()).getReference(); + return (TerminologyCapabilities) utils.issueGetResourceRequest(resourceAddress.resolveMetadataTxCaps(), getPreferredResourceFormat(), TIMEOUT_NORMAL).getReference(); } public CapabilityStatement getCapabilitiesStatement() { CapabilityStatement conformance = null; try { - conformance = (CapabilityStatement)utils.issueGetResourceRequest(resourceAddress.resolveMetadataUri(false), getPreferredResourceFormat()).getReference(); + conformance = (CapabilityStatement)utils.issueGetResourceRequest(resourceAddress.resolveMetadataUri(false), getPreferredResourceFormat(), TIMEOUT_NORMAL).getReference(); } catch(Exception e) { handleException("An error has occurred while trying to fetch the server's conformance statement", e); } @@ -182,7 +185,7 @@ public class FHIRToolingClient { if (capabilities != null) return capabilities; try { - capabilities = (CapabilityStatement)utils.issueGetResourceRequest(resourceAddress.resolveMetadataUri(true), getPreferredResourceFormat()).getReference(); + capabilities = (CapabilityStatement)utils.issueGetResourceRequest(resourceAddress.resolveMetadataUri(true), getPreferredResourceFormat(), TIMEOUT_NORMAL).getReference(); } catch(Exception e) { handleException("An error has occurred while trying to fetch the server's conformance statement", e); } @@ -192,7 +195,7 @@ public class FHIRToolingClient { public T read(Class resourceClass, String id) {//TODO Change this to AddressableResource ResourceRequest result = null; try { - result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id), getPreferredResourceFormat()); + result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id), getPreferredResourceFormat(), TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addSuccessStatus(200);//Only one for now @@ -208,7 +211,7 @@ public class FHIRToolingClient { public T vread(Class resourceClass, String id, String version) { ResourceRequest result = null; try { - result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndIdAndVersion(resourceClass, id, version), getPreferredResourceFormat()); + result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndIdAndVersion(resourceClass, id, version), getPreferredResourceFormat(), TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405);//unknown @@ -227,7 +230,7 @@ public class FHIRToolingClient { public T getCanonical(Class resourceClass, String canonicalURL) { ResourceRequest result = null; try { - result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndCanonical(resourceClass, canonicalURL), getPreferredResourceFormat()); + result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndCanonical(resourceClass, canonicalURL), getPreferredResourceFormat(), TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405);//unknown @@ -251,7 +254,7 @@ public class FHIRToolingClient { ResourceRequest result = null; try { List
headers = null; - result = utils.issuePutRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resource.getClass(), resource.getId()),utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + result = utils.issuePutRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resource.getClass(), resource.getId()),utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, TIMEOUT_OPERATION); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -280,7 +283,7 @@ public class FHIRToolingClient { ResourceRequest result = null; try { List
headers = null; - result = utils.issuePutRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id),utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + result = utils.issuePutRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id),utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, TIMEOUT_OPERATION); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -484,9 +487,9 @@ public class FHIRToolingClient { ps += p.getName() + "=" + Utilities.encodeUri(((PrimitiveType) p.getValue()).asStringValue())+"&"; ResourceRequest result; if (complex) - result = utils.issuePostRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat()); + result = utils.issuePostRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), TIMEOUT_OPERATION_LONG); else - result = utils.issueGetResourceRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), getPreferredResourceFormat()); + result = utils.issueGetResourceRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), getPreferredResourceFormat(), TIMEOUT_OPERATION_LONG); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addSuccessStatus(200);//Only one for now @@ -509,7 +512,7 @@ public class FHIRToolingClient { public Bundle transaction(Bundle batch) { Bundle transactionResult = null; try { - transactionResult = utils.postBatchRequest(resourceAddress.getBaseServiceUri(), utils.getFeedAsByteArray(batch, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat()); + transactionResult = utils.postBatchRequest(resourceAddress.getBaseServiceUri(), utils.getFeedAsByteArray(batch, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), TIMEOUT_NORMAL+batch.getEntry().size()); } catch (Exception e) { handleException("An error occurred trying to process this transaction request", e); } @@ -517,11 +520,10 @@ public class FHIRToolingClient { } @SuppressWarnings("unchecked") - public OperationOutcome validate(Class resourceClass, T resource, String id) { ResourceRequest result = null; try { - result = utils.issuePostRequest(resourceAddress.resolveValidateUri(resourceClass, id), utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat()); + result = utils.issuePostRequest(resourceAddress.resolveValidateUri(resourceClass, id), utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), 3); result.addErrorStatus(400);//gone result.addErrorStatus(422);//Unprocessable Entity result.addSuccessStatus(200);//OK @@ -693,7 +695,7 @@ public class FHIRToolingClient { Parameters p = expParams == null ? new Parameters() : expParams.copy(); p.addParameter().setName("valueSet").setResource(source); ResourceRequest result = utils.issuePostRequest(resourceAddress.resolveOperationUri(ValueSet.class, "expand"), - utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, 4); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -708,7 +710,7 @@ public class FHIRToolingClient { public Parameters lookupCode(Map params) { - ResourceRequest result = utils.issueGetResourceRequest(resourceAddress.resolveOperationUri(CodeSystem.class, "lookup", params), getPreferredResourceFormat()); + ResourceRequest result = utils.issueGetResourceRequest(resourceAddress.resolveOperationUri(CodeSystem.class, "lookup", params), getPreferredResourceFormat(), TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -727,7 +729,7 @@ public class FHIRToolingClient { for (String n : params.keySet()) p.addParameter().setName(n).setValue(new StringType(params.get(n))); ResourceRequest result = utils.issuePostRequest(resourceAddress.resolveOperationUri(ValueSet.class, "expand", params), - utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, 4); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -766,7 +768,7 @@ public class FHIRToolingClient { params.addParameter().setName("name").setValue(new StringType(name)); List
headers = null; ResourceRequest result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap()), - utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -785,7 +787,7 @@ public class FHIRToolingClient { params.addParameter().setName("concept").setValue(coding); List
headers = null; ResourceRequest result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap()), - utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, TIMEOUT_OPERATION); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/ClientUtils.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/ClientUtils.java index 9b9bc0d07..e085afe3f 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/ClientUtils.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/client/ClientUtils.java @@ -86,6 +86,7 @@ import org.hl7.fhir.r5.model.Resource; import org.hl7.fhir.r5.model.ResourceType; import org.hl7.fhir.r5.utils.ResourceUtilities; import org.hl7.fhir.utilities.ToolingClientLogger; +import org.hl7.fhir.utilities.Utilities; /** * Helper class handling lower level HTTP transport concerns. @@ -137,34 +138,34 @@ public class ClientUtils { this.password = password; } - public ResourceRequest issueOptionsRequest(URI optionsUri, String resourceFormat) { + public ResourceRequest issueOptionsRequest(URI optionsUri, String resourceFormat, int timeoutLoading) { HttpOptions options = new HttpOptions(optionsUri); - return issueResourceRequest(resourceFormat, options); + return issueResourceRequest(resourceFormat, options, timeoutLoading); } - public ResourceRequest issueGetResourceRequest(URI resourceUri, String resourceFormat) { + public ResourceRequest issueGetResourceRequest(URI resourceUri, String resourceFormat, int timeoutLoading) { HttpGet httpget = new HttpGet(resourceUri); - return issueResourceRequest(resourceFormat, httpget); + return issueResourceRequest(resourceFormat, httpget, timeoutLoading); } - public ResourceRequest issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, List
headers) { + public ResourceRequest issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, List
headers, int timeoutLoading) { HttpPut httpPut = new HttpPut(resourceUri); - return issueResourceRequest(resourceFormat, httpPut, payload, headers); + return issueResourceRequest(resourceFormat, httpPut, payload, headers, timeoutLoading); } - public ResourceRequest issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat) { + public ResourceRequest issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, int timeoutLoading) { HttpPut httpPut = new HttpPut(resourceUri); - return issueResourceRequest(resourceFormat, httpPut, payload, null); + return issueResourceRequest(resourceFormat, httpPut, payload, null, timeoutLoading); } - public ResourceRequest issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, List
headers) { + public ResourceRequest issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, List
headers, int timeoutLoading) { HttpPost httpPost = new HttpPost(resourceUri); - return issueResourceRequest(resourceFormat, httpPost, payload, headers); + return issueResourceRequest(resourceFormat, httpPost, payload, headers, timeoutLoading); } - public ResourceRequest issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat) { - return issuePostRequest(resourceUri, payload, resourceFormat, null); + public ResourceRequest issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, int timeoutLoading) { + return issuePostRequest(resourceUri, payload, resourceFormat, null, timeoutLoading); } public Bundle issueGetFeedRequest(URI resourceUri, String resourceFormat) { @@ -185,10 +186,10 @@ public class ClientUtils { } } - public Bundle postBatchRequest(URI resourceUri, byte[] payload, String resourceFormat) { + public Bundle postBatchRequest(URI resourceUri, byte[] payload, String resourceFormat, int timeoutLoading) { HttpPost httpPost = new HttpPost(resourceUri); configureFhirRequest(httpPost, resourceFormat); - HttpResponse response = sendPayload(httpPost, payload, proxy); + HttpResponse response = sendPayload(httpPost, payload, proxy, timeoutLoading); return unmarshalFeed(response, resourceFormat); } @@ -207,8 +208,8 @@ public class ClientUtils { * Request/Response Helper methods ***********************************************************/ - protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request) { - return issueResourceRequest(resourceFormat, request, null); + protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request, int timeoutLoading) { + return issueResourceRequest(resourceFormat, request, null, timeoutLoading); } /** @@ -216,8 +217,8 @@ public class ClientUtils { * @param options * @return */ - protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload) { - return issueResourceRequest(resourceFormat, request, payload, null); + protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, int timeoutLoading) { + return issueResourceRequest(resourceFormat, request, payload, null, timeoutLoading); } /** @@ -225,11 +226,11 @@ public class ClientUtils { * @param options * @return */ - protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, List
headers) { + protected ResourceRequest issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, List
headers, int timeoutLoading) { configureFhirRequest(request, resourceFormat, headers); HttpResponse response = null; if(request instanceof HttpEntityEnclosingRequest && payload != null) { - response = sendPayload((HttpEntityEnclosingRequestBase)request, payload, proxy); + response = sendPayload((HttpEntityEnclosingRequestBase)request, payload, proxy, timeoutLoading); } else if (request instanceof HttpEntityEnclosingRequest && payload == null){ throw new EFhirClientException("PUT and POST requests require a non-null payload"); } else { @@ -279,29 +280,36 @@ public class ClientUtils { * @param payload * @return */ - protected HttpResponse sendPayload(HttpEntityEnclosingRequestBase request, byte[] payload, HttpHost proxy) { + @SuppressWarnings({ "resource", "deprecation" }) + protected HttpResponse sendPayload(HttpEntityEnclosingRequestBase request, byte[] payload, HttpHost proxy, int timeoutLoading) { HttpResponse response = null; - boolean ok = false; - int tryCount = 0; - while (!ok) { - try { - tryCount++; - HttpClient httpclient = new DefaultHttpClient(); - if(proxy != null) { - httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); + boolean ok = false; + long t = System.currentTimeMillis(); + int tryCount = 0; + while (!ok) { + try { + tryCount++; + HttpClient httpclient = new DefaultHttpClient(); + HttpParams params = httpclient.getParams(); + HttpConnectionParams.setConnectionTimeout(params, timeout); + HttpConnectionParams.setSoTimeout(params, timeout * timeoutLoading); + + if(proxy != null) { + httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); + } + request.setEntity(new ByteArrayEntity(payload)); + log(request); + response = httpclient.execute(request); + ok = true; + } catch(IOException ioe) { + System.out.println(ioe.getMessage()+" ("+(System.currentTimeMillis()-t)+"ms / "+Utilities.describeSize(payload.length)+")"); + if (tryCount <= retryCount || (tryCount < 3 && ioe instanceof org.apache.http.conn.ConnectTimeoutException)) { + ok = false; + } else { + throw new EFhirClientException("Error sending HTTP Post/Put Payload: "+ioe.getMessage(), ioe); + } } - request.setEntity(new ByteArrayEntity(payload)); - log(request); - response = httpclient.execute(request); - ok = true; - } catch(IOException ioe) { - if (tryCount <= retryCount) { - ok = false; - } else { - throw new EFhirClientException("Error sending HTTP Post/Put Payload: "+ioe.getMessage(), ioe); } - } - } return response; } 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 56698605c..5e5fcb0de 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 @@ -85,6 +85,9 @@ public class FHIRToolingClient { 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; @@ -161,13 +164,13 @@ public class FHIRToolingClient { } public TerminologyCapabilities getTerminologyCapabilities() { - return (TerminologyCapabilities) utils.issueGetResourceRequest(resourceAddress.resolveMetadataTxCaps(), getPreferredResourceFormat()).getReference(); + return (TerminologyCapabilities) utils.issueGetResourceRequest(resourceAddress.resolveMetadataTxCaps(), getPreferredResourceFormat(), TIMEOUT_NORMAL).getReference(); } public CapabilityStatement getCapabilitiesStatement() { CapabilityStatement conformance = null; try { - conformance = (CapabilityStatement)utils.issueGetResourceRequest(resourceAddress.resolveMetadataUri(false), getPreferredResourceFormat()).getReference(); + conformance = (CapabilityStatement)utils.issueGetResourceRequest(resourceAddress.resolveMetadataUri(false), getPreferredResourceFormat(), TIMEOUT_NORMAL).getReference(); } catch(Exception e) { handleException("An error has occurred while trying to fetch the server's conformance statement", e); } @@ -178,7 +181,7 @@ public class FHIRToolingClient { if (capabilities != null) return capabilities; try { - capabilities = (CapabilityStatement)utils.issueGetResourceRequest(resourceAddress.resolveMetadataUri(true), getPreferredResourceFormat()).getReference(); + capabilities = (CapabilityStatement)utils.issueGetResourceRequest(resourceAddress.resolveMetadataUri(true), getPreferredResourceFormat(), TIMEOUT_NORMAL).getReference(); } catch(Exception e) { handleException("An error has occurred while trying to fetch the server's conformance statement", e); } @@ -188,7 +191,7 @@ public class FHIRToolingClient { public T read(Class resourceClass, String id) {//TODO Change this to AddressableResource ResourceRequest result = null; try { - result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id), getPreferredResourceFormat()); + result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id), getPreferredResourceFormat(), TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addSuccessStatus(200);//Only one for now @@ -204,7 +207,7 @@ public class FHIRToolingClient { public T vread(Class resourceClass, String id, String version) { ResourceRequest result = null; try { - result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndIdAndVersion(resourceClass, id, version), getPreferredResourceFormat()); + result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndIdAndVersion(resourceClass, id, version), getPreferredResourceFormat(), TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405);//unknown @@ -223,7 +226,7 @@ public class FHIRToolingClient { public T getCanonical(Class resourceClass, String canonicalURL) { ResourceRequest result = null; try { - result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndCanonical(resourceClass, canonicalURL), getPreferredResourceFormat()); + result = utils.issueGetResourceRequest(resourceAddress.resolveGetUriFromResourceClassAndCanonical(resourceClass, canonicalURL), getPreferredResourceFormat(), TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405);//unknown @@ -247,7 +250,7 @@ public class FHIRToolingClient { ResourceRequest result = null; try { List
headers = null; - result = utils.issuePutRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resource.getClass(), resource.getId()),utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + result = utils.issuePutRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resource.getClass(), resource.getId()),utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, TIMEOUT_OPERATION); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -276,7 +279,7 @@ public class FHIRToolingClient { ResourceRequest result = null; try { List
headers = null; - result = utils.issuePutRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id),utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + result = utils.issuePutRequest(resourceAddress.resolveGetUriFromResourceClassAndId(resourceClass, id),utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, TIMEOUT_OPERATION); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -480,9 +483,9 @@ public class FHIRToolingClient { ps += p.getName() + "=" + Utilities.encodeUri(((PrimitiveType) p.getValue()).asStringValue())+"&"; ResourceRequest result; if (complex) - result = utils.issuePostRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat()); + result = utils.issuePostRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), TIMEOUT_OPERATION_LONG); else - result = utils.issueGetResourceRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), getPreferredResourceFormat()); + result = utils.issueGetResourceRequest(resourceAddress.resolveOperationURLFromClass(resourceClass, name, ps), getPreferredResourceFormat(), TIMEOUT_OPERATION_LONG); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addSuccessStatus(200);//Only one for now @@ -505,7 +508,7 @@ public class FHIRToolingClient { public Bundle transaction(Bundle batch) { Bundle transactionResult = null; try { - transactionResult = utils.postBatchRequest(resourceAddress.getBaseServiceUri(), utils.getFeedAsByteArray(batch, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat()); + transactionResult = utils.postBatchRequest(resourceAddress.getBaseServiceUri(), utils.getFeedAsByteArray(batch, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), TIMEOUT_NORMAL+batch.getEntry().size()); } catch (Exception e) { handleException("An error occurred trying to process this transaction request", e); } @@ -516,7 +519,7 @@ public class FHIRToolingClient { public OperationOutcome validate(Class resourceClass, T resource, String id) { ResourceRequest result = null; try { - result = utils.issuePostRequest(resourceAddress.resolveValidateUri(resourceClass, id), utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat()); + result = utils.issuePostRequest(resourceAddress.resolveValidateUri(resourceClass, id), utils.getResourceAsByteArray(resource, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), 3); result.addErrorStatus(400);//gone result.addErrorStatus(422);//Unprocessable Entity result.addSuccessStatus(200);//OK @@ -688,7 +691,7 @@ public class FHIRToolingClient { Parameters p = expParams == null ? new Parameters() : expParams.copy(); p.addParameter().setName("valueSet").setResource(source); ResourceRequest result = utils.issuePostRequest(resourceAddress.resolveOperationUri(ValueSet.class, "expand"), - utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, 4); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -703,7 +706,7 @@ public class FHIRToolingClient { public Parameters lookupCode(Map params) { - ResourceRequest result = utils.issueGetResourceRequest(resourceAddress.resolveOperationUri(CodeSystem.class, "lookup", params), getPreferredResourceFormat()); + ResourceRequest result = utils.issueGetResourceRequest(resourceAddress.resolveOperationUri(CodeSystem.class, "lookup", params), getPreferredResourceFormat(), TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -722,7 +725,7 @@ public class FHIRToolingClient { for (String n : params.keySet()) p.addParameter().setName(n).setValue(new StringType(params.get(n))); ResourceRequest result = utils.issuePostRequest(resourceAddress.resolveOperationUri(ValueSet.class, "expand", params), - utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + utils.getResourceAsByteArray(p, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, 4); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -761,7 +764,7 @@ public class FHIRToolingClient { params.addParameter().setName("name").setValue(new StringType(name)); List
headers = null; ResourceRequest result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap()), - utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, TIMEOUT_NORMAL); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405); @@ -780,7 +783,7 @@ public class FHIRToolingClient { params.addParameter().setName("concept").setValue(coding); List
headers = null; ResourceRequest result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap()), - utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers); + utils.getResourceAsByteArray(params, false, isJson(getPreferredResourceFormat())), getPreferredResourceFormat(), headers, TIMEOUT_OPERATION); result.addErrorStatus(410);//gone result.addErrorStatus(404);//unknown result.addErrorStatus(405);