Merge pull request #292 from hapifhir/gg-v5019

v5.0.19 work
This commit is contained in:
Grahame Grieve 2020-08-06 08:26:13 +10:00 committed by GitHub
commit 566b17c240
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 251 additions and 156 deletions

View File

@ -0,0 +1,5 @@
Validator:
* Improved handling of terminology timeout issues
Other code changes:
* fix questionnaire rendering to create valid resources

View File

@ -86,6 +86,7 @@ import org.hl7.fhir.dstu3.model.Resource;
import org.hl7.fhir.dstu3.model.ResourceType;
import org.hl7.fhir.dstu3.utils.ResourceUtilities;
import org.hl7.fhir.utilities.ToolingClientLogger;
import org.hl7.fhir.utilities.Utilities;
/**
* Helper class handling lower level HTTP transport concerns.
@ -96,6 +97,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 +138,34 @@ public class ClientUtils {
this.password = password;
}
public <T extends Resource> ResourceRequest<T> issueOptionsRequest(URI optionsUri, String resourceFormat) {
public <T extends Resource> ResourceRequest<T> issueOptionsRequest(URI optionsUri, String resourceFormat, int timeoutLoading) {
HttpOptions options = new HttpOptions(optionsUri);
return issueResourceRequest(resourceFormat, options);
return issueResourceRequest(resourceFormat, options, timeoutLoading);
}
public <T extends Resource> ResourceRequest<T> issueGetResourceRequest(URI resourceUri, String resourceFormat) {
public <T extends Resource> ResourceRequest<T> issueGetResourceRequest(URI resourceUri, String resourceFormat, int timeoutLoading) {
HttpGet httpget = new HttpGet(resourceUri);
return issueResourceRequest(resourceFormat, httpget);
return issueResourceRequest(resourceFormat, httpget, timeoutLoading);
}
public <T extends Resource> ResourceRequest<T> issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers) {
public <T extends Resource> ResourceRequest<T> issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers, int timeoutLoading) {
HttpPut httpPut = new HttpPut(resourceUri);
return issueResourceRequest(resourceFormat, httpPut, payload, headers);
return issueResourceRequest(resourceFormat, httpPut, payload, headers, timeoutLoading);
}
public <T extends Resource> ResourceRequest<T> issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat) {
public <T extends Resource> ResourceRequest<T> 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 <T extends Resource> ResourceRequest<T> issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers) {
public <T extends Resource> ResourceRequest<T> issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers, int timeoutLoading) {
HttpPost httpPost = new HttpPost(resourceUri);
return issueResourceRequest(resourceFormat, httpPost, payload, headers);
return issueResourceRequest(resourceFormat, httpPost, payload, headers, timeoutLoading);
}
public <T extends Resource> ResourceRequest<T> issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat) {
return issuePostRequest(resourceUri, payload, resourceFormat, null);
public <T extends Resource> ResourceRequest<T> 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 +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);
}
@ -206,8 +208,8 @@ public class ClientUtils {
* Request/Response Helper methods
***********************************************************/
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request) {
return issueResourceRequest(resourceFormat, request, null);
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request, int timeoutLoading) {
return issueResourceRequest(resourceFormat, request, null, timeoutLoading);
}
/**
@ -215,8 +217,8 @@ public class ClientUtils {
* @param options
* @return
*/
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload) {
return issueResourceRequest(resourceFormat, request, payload, null);
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, int timeoutLoading) {
return issueResourceRequest(resourceFormat, request, payload, null, timeoutLoading);
}
/**
@ -224,11 +226,11 @@ public class ClientUtils {
* @param options
* @return
*/
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, List<Header> headers) {
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, List<Header> 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 +280,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 +302,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 +332,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;

View File

@ -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 extends Resource> T read(Class<T> resourceClass, String id) {//TODO Change this to AddressableResource
ResourceRequest<T> 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 extends Resource> T vread(Class<T> resourceClass, String id, String version) {
ResourceRequest<T> 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 extends Resource> T getCanonical(Class<T> resourceClass, String canonicalURL) {
ResourceRequest<T> 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<Resource> result = null;
try {
List<Header> 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<T> result = null;
try {
List<Header> 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<T> 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 <T extends Resource> OperationOutcome validate(Class<T> resourceClass, T resource, String id) {
ResourceRequest<T> 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<Resource> 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<String, String> params) {
ResourceRequest<Resource> result = utils.issueGetResourceRequest(resourceAddress.resolveOperationUri(CodeSystem.class, "lookup", params), getPreferredResourceFormat());
ResourceRequest<Resource> 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<Resource> 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<Header> headers = null;
ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap<String, String>()),
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<Header> headers = null;
ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap<String, String>()),
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();
}

View File

@ -86,6 +86,7 @@ import org.hl7.fhir.r4.model.Resource;
import org.hl7.fhir.r4.model.ResourceType;
import org.hl7.fhir.r4.utils.ResourceUtilities;
import org.hl7.fhir.utilities.ToolingClientLogger;
import org.hl7.fhir.utilities.Utilities;
/**
* Helper class handling lower level HTTP transport concerns.
@ -96,6 +97,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 +138,34 @@ public class ClientUtils {
this.password = password;
}
public <T extends Resource> ResourceRequest<T> issueOptionsRequest(URI optionsUri, String resourceFormat) {
public <T extends Resource> ResourceRequest<T> issueOptionsRequest(URI optionsUri, String resourceFormat, int timeoutLoading) {
HttpOptions options = new HttpOptions(optionsUri);
return issueResourceRequest(resourceFormat, options);
return issueResourceRequest(resourceFormat, options, timeoutLoading);
}
public <T extends Resource> ResourceRequest<T> issueGetResourceRequest(URI resourceUri, String resourceFormat) {
public <T extends Resource> ResourceRequest<T> issueGetResourceRequest(URI resourceUri, String resourceFormat, int timeoutLoading) {
HttpGet httpget = new HttpGet(resourceUri);
return issueResourceRequest(resourceFormat, httpget);
return issueResourceRequest(resourceFormat, httpget, timeoutLoading);
}
public <T extends Resource> ResourceRequest<T> issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers) {
public <T extends Resource> ResourceRequest<T> issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers, int timeoutLoading) {
HttpPut httpPut = new HttpPut(resourceUri);
return issueResourceRequest(resourceFormat, httpPut, payload, headers);
return issueResourceRequest(resourceFormat, httpPut, payload, headers, timeoutLoading);
}
public <T extends Resource> ResourceRequest<T> issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat) {
public <T extends Resource> ResourceRequest<T> 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 <T extends Resource> ResourceRequest<T> issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers) {
public <T extends Resource> ResourceRequest<T> issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers, int timeoutLoading) {
HttpPost httpPost = new HttpPost(resourceUri);
return issueResourceRequest(resourceFormat, httpPost, payload, headers);
return issueResourceRequest(resourceFormat, httpPost, payload, headers, timeoutLoading);
}
public <T extends Resource> ResourceRequest<T> issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat) {
return issuePostRequest(resourceUri, payload, resourceFormat, null);
public <T extends Resource> ResourceRequest<T> 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 +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);
}
@ -206,8 +208,8 @@ public class ClientUtils {
* Request/Response Helper methods
***********************************************************/
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request) {
return issueResourceRequest(resourceFormat, request, null);
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request, int timeoutLoading) {
return issueResourceRequest(resourceFormat, request, null, timeoutLoading);
}
/**
@ -215,8 +217,8 @@ public class ClientUtils {
* @param options
* @return
*/
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload) {
return issueResourceRequest(resourceFormat, request, payload, null);
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, int timeoutLoading) {
return issueResourceRequest(resourceFormat, request, payload, null, timeoutLoading);
}
/**
@ -224,11 +226,11 @@ public class ClientUtils {
* @param options
* @return
*/
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, List<Header> headers) {
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, List<Header> 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 +280,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 +302,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 +332,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;

View File

@ -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 extends Resource> T read(Class<T> resourceClass, String id) {//TODO Change this to AddressableResource
ResourceRequest<T> 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 extends Resource> T vread(Class<T> resourceClass, String id, String version) {
ResourceRequest<T> 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 extends Resource> T getCanonical(Class<T> resourceClass, String canonicalURL) {
ResourceRequest<T> 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<Resource> result = null;
try {
List<Header> 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<T> result = null;
try {
List<Header> 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<T> 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 <T extends Resource> OperationOutcome validate(Class<T> resourceClass, T resource, String id) {
ResourceRequest<T> 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<Resource> 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<String, String> params) {
ResourceRequest<Resource> result = utils.issueGetResourceRequest(resourceAddress.resolveOperationUri(CodeSystem.class, "lookup", params), getPreferredResourceFormat());
ResourceRequest<Resource> 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<Resource> 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<Header> headers = null;
ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap<String, String>()),
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<Header> headers = null;
ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap<String, String>()),
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);

View File

@ -85,7 +85,12 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
this.resource = resource;
}
public abstract CanonicalResource loadResource() throws FHIRException;
public abstract CanonicalResource loadResource() throws FHIRException;
@Override
public String toString() {
return type+"/"+id+": "+url+"|"+version;
}
}
public class CanonicalListSorter implements Comparator<CanonicalResource> {
@ -142,6 +147,12 @@ public class CanonicalResourceManager<T extends CanonicalResource> {
public boolean hasVersion() {
return resource != null ? resource.hasVersion() : proxy.getVersion() != null;
}
@Override
public String toString() {
return resource != null ? resource.fhirType()+"/"+resource.getId()+": "+resource.getUrl()+"|"+resource.getVersion() : proxy.toString();
}
}
public class MetadataResourceVersionComparator<T1 extends CachedCanonicalResource<T>> implements Comparator<T1> {

View File

@ -523,7 +523,7 @@ public class TypeConvertor {
if (b instanceof Element) {
return ((Element) b).getXhtml();
} else if (b instanceof XhtmlType) {
return ((XhtmlType) b).getValue();
return ((XhtmlType) b).getXhtml();
} else if (b instanceof StringType) {
try {
return new XhtmlParser().parseFragment(((StringType) b).asStringValue());
@ -539,7 +539,7 @@ public class TypeConvertor {
return ((Element) b).getValue();
} else if (b instanceof XhtmlType) {
try {
return new XhtmlComposer(true).compose(((XhtmlType) b).getValue());
return new XhtmlComposer(true).compose(((XhtmlType) b).getXhtml());
} catch (IOException e) {
return null;
}

View File

@ -40,7 +40,7 @@ import org.hl7.fhir.utilities.xhtml.XhtmlComposer;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
public class XhtmlType extends Element {
public class XhtmlType extends PrimitiveType<String> {
private Narrative place;
@ -72,11 +72,15 @@ public class XhtmlType extends Element {
}
@Override
public Element copy() {
public PrimitiveType<String> copy() {
return null;
}
public XhtmlNode getValue() {
public String getValue() {
return primitiveValue();
}
public XhtmlNode getXhtml() {
return place == null ? new XhtmlNode(NodeType.Element, "div") : place.getDiv();
}
@ -104,7 +108,7 @@ public class XhtmlType extends Element {
@Override
public String primitiveValue() {
try {
return new XhtmlComposer(false).compose(getValue());
return new XhtmlComposer(false).compose(getXhtml());
} catch (IOException e) {
}
return null;
@ -121,8 +125,13 @@ public class XhtmlType extends Element {
}
@Override
public XhtmlNode getXhtml() {
return getValue();
protected String encode(String theValue) {
return theValue;
}
@Override
protected String parse(String theValue) {
return theValue;
}

View File

@ -62,7 +62,7 @@ public class QuestionnaireRenderer extends TerminologyRenderer {
boolean hasFlags = checkForFlags(q.getItem());
HierarchicalTableGenerator gen = new HierarchicalTableGenerator(context.getDestDir(), context.isInlineGraphics(), true);
TableModel model = gen.new TableModel("qtree="+q.getId(), true);
TableModel model = gen.new TableModel("qtree="+q.getId(), !forResource);
model.setAlternating(true);
model.setDocoImg(context.getSpecificationLink() +"help16.png");
model.setDocoRef(context.getSpecificationLink()+"formats.html#table");

View File

@ -38,6 +38,7 @@ public abstract class ResourceRenderer extends DataRenderer {
protected ResourceContext rcontext;
protected XVerExtensionManager xverManager;
protected boolean forResource;
public ResourceRenderer(RenderingContext context) {
@ -53,7 +54,6 @@ public abstract class ResourceRenderer extends DataRenderer {
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
render(x, dr);
return x;
}
/**
* given a resource, update it's narrative with the best rendering available
@ -67,7 +67,14 @@ public abstract class ResourceRenderer extends DataRenderer {
public void render(DomainResource r) throws IOException, FHIRException, EOperationOutcome {
XhtmlNode x = new XhtmlNode(NodeType.Element, "div");
boolean hasExtensions = render(x, r);
boolean ofr = forResource;
boolean hasExtensions;
try {
forResource = true;
hasExtensions = render(x, r);
} finally {
forResource = ofr;
}
inject(r, x, hasExtensions ? NarrativeStatus.EXTENSIONS : NarrativeStatus.GENERATED);
}

View File

@ -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 <T extends Resource> ResourceRequest<T> issueOptionsRequest(URI optionsUri, String resourceFormat) {
public <T extends Resource> ResourceRequest<T> issueOptionsRequest(URI optionsUri, String resourceFormat, int timeoutLoading) {
HttpOptions options = new HttpOptions(optionsUri);
return issueResourceRequest(resourceFormat, options);
return issueResourceRequest(resourceFormat, options, timeoutLoading);
}
public <T extends Resource> ResourceRequest<T> issueGetResourceRequest(URI resourceUri, String resourceFormat) {
public <T extends Resource> ResourceRequest<T> issueGetResourceRequest(URI resourceUri, String resourceFormat, int timeoutLoading) {
HttpGet httpget = new HttpGet(resourceUri);
return issueResourceRequest(resourceFormat, httpget);
return issueResourceRequest(resourceFormat, httpget, timeoutLoading);
}
public <T extends Resource> ResourceRequest<T> issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers) {
public <T extends Resource> ResourceRequest<T> issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers, int timeoutLoading) {
HttpPut httpPut = new HttpPut(resourceUri);
return issueResourceRequest(resourceFormat, httpPut, payload, headers);
return issueResourceRequest(resourceFormat, httpPut, payload, headers, timeoutLoading);
}
public <T extends Resource> ResourceRequest<T> issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat) {
public <T extends Resource> ResourceRequest<T> 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 <T extends Resource> ResourceRequest<T> issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers) {
public <T extends Resource> ResourceRequest<T> issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers, int timeoutLoading) {
HttpPost httpPost = new HttpPost(resourceUri);
return issueResourceRequest(resourceFormat, httpPost, payload, headers);
return issueResourceRequest(resourceFormat, httpPost, payload, headers, timeoutLoading);
}
public <T extends Resource> ResourceRequest<T> issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat) {
return issuePostRequest(resourceUri, payload, resourceFormat, null);
public <T extends Resource> ResourceRequest<T> 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 <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request) {
return issueResourceRequest(resourceFormat, request, null);
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request, int timeoutLoading) {
return issueResourceRequest(resourceFormat, request, null, timeoutLoading);
}
/**
@ -216,8 +217,8 @@ public class ClientUtils {
* @param options
* @return
*/
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload) {
return issueResourceRequest(resourceFormat, request, payload, null);
protected <T extends Resource> ResourceRequest<T> 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 <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, List<Header> headers) {
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, List<Header> 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;
}

View File

@ -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 extends Resource> T read(Class<T> resourceClass, String id) {//TODO Change this to AddressableResource
ResourceRequest<T> 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 extends Resource> T vread(Class<T> resourceClass, String id, String version) {
ResourceRequest<T> 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 extends Resource> T getCanonical(Class<T> resourceClass, String canonicalURL) {
ResourceRequest<T> 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<Resource> result = null;
try {
List<Header> 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<T> result = null;
try {
List<Header> 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<T> 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 <T extends Resource> OperationOutcome validate(Class<T> resourceClass, T resource, String id) {
ResourceRequest<T> 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<Resource> 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<String, String> params) {
ResourceRequest<Resource> result = utils.issueGetResourceRequest(resourceAddress.resolveOperationUri(CodeSystem.class, "lookup", params), getPreferredResourceFormat());
ResourceRequest<Resource> 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<Resource> 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<Header> headers = null;
ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap<String, String>()),
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<Header> headers = null;
ResourceRequest<Resource> result = utils.issuePostRequest(resourceAddress.resolveOperationUri(null, "closure", new HashMap<String, String>()),
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);

View File

@ -14,6 +14,7 @@ import org.apache.commons.lang3.SystemUtils;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.formats.JsonParser;
import org.hl7.fhir.r5.formats.XmlParser;
import org.hl7.fhir.r5.model.DomainResource;
import org.hl7.fhir.r5.model.Questionnaire;
@ -107,7 +108,12 @@ public class NarrativeGenerationTests {
rc.setDefinitionsTarget("test.html");
rc.setTerminologyServiceOptions(TerminologyServiceOptions.defaults());
IOUtils.copy(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + "-expected.xml"), new FileOutputStream(TestingUtilities.tempFile("narrative", test.getId() + "-expected.xml")));
DomainResource source = (DomainResource) new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + "-input.xml"));
DomainResource source;
if (TestingUtilities.findTestResource("r5", "narrative", test.getId() + "-input.json")) {
source = (DomainResource) new JsonParser().parse(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + "-input.json"));
} else {
source = (DomainResource) new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + "-input.xml"));
}
DomainResource target = (DomainResource) new XmlParser().parse(TestingUtilities.loadTestResourceStream("r5", "narrative", test.getId() + "-expected.xml"));
RendererFactory.factory(source, rc).render(source);
new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(TestingUtilities.tempFile("narrative", test.getId() + "-actual.xml")), source);

View File

@ -1308,6 +1308,19 @@ public class Utilities {
return false;
}
public static String describeSize(int length) {
if (length > 1024 * 1024 * 1024) {
return ""+length / (1024 * 1024 * 1024)+"Gb";
}
if (length > 1024 * 1024) {
return ""+length / (1024 * 1024)+"Mb";
}
if (length > 1024) {
return ""+length / (1024)+"kb";
}
return ""+length +"b";
}

View File

@ -122,6 +122,9 @@ public class PackageHacker {
if (webref.equals("file://C:\\GitHub\\hl7.fhir.us.cqfmeasures#2.0.0\\output")) {
return "http://hl7.org/fhir/us/cqfmeasures/STU2";
}
if (webref.equals("file://C:\\GitHub\\hl7.fhir.uv.ips#1.0.0\\output")) {
return "http://hl7.org/fhir/uv/ips/STU1";
}
return webref;
}

View File

@ -161,11 +161,13 @@ public class Validator {
System.out.println("Specified destination (-dest parameter) is not valid: \"" + dest + "\")");
else {
// first, prepare the context
String txLog = Params.getTerminologyServerLog(args);
String v = Common.getVersion(args);
String definitions = VersionUtilities.packageForVersion(v) + "#" + v;
ValidationEngine validator = Common.getValidationEngine(v, definitions, txLog);
Params.checkIGFileReferences(args);
cliContext = Params.loadCliContext(args);
if (cliContext.getSv() == null) {
cliContext.setSv(determineVersion(cliContext));
}
String v = VersionUtilities.getCurrentVersion(cliContext.getSv());
String definitions = VersionUtilities.packageForVersion(v) + "#" + v;
ValidationEngine validator = ValidationService.getValidator(cliContext, definitions);
ComparisonService.doLeftRightComparison(args, dest, validator);
}
} else {