work on no-network-access mode
This commit is contained in:
parent
6644d9bd6d
commit
81d26c5160
|
@ -85,6 +85,8 @@ import org.hl7.fhir.dstu2.model.OperationOutcome.OperationOutcomeIssueComponent;
|
||||||
import org.hl7.fhir.dstu2.model.Resource;
|
import org.hl7.fhir.dstu2.model.Resource;
|
||||||
import org.hl7.fhir.dstu2.model.ResourceType;
|
import org.hl7.fhir.dstu2.model.ResourceType;
|
||||||
import org.hl7.fhir.dstu2.utils.ResourceUtilities;
|
import org.hl7.fhir.dstu2.utils.ResourceUtilities;
|
||||||
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
|
import org.hl7.fhir.utilities.ToolGlobalSettings;
|
||||||
import org.hl7.fhir.utilities.ToolingClientLogger;
|
import org.hl7.fhir.utilities.ToolingClientLogger;
|
||||||
import org.hl7.fhir.utilities.Utilities;
|
import org.hl7.fhir.utilities.Utilities;
|
||||||
|
|
||||||
|
@ -140,26 +142,42 @@ public class ClientUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Resource> ResourceRequest<T> issueOptionsRequest(URI optionsUri, String resourceFormat, int timeoutLoading) {
|
public <T extends Resource> ResourceRequest<T> issueOptionsRequest(URI optionsUri, String resourceFormat, int timeoutLoading) {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
|
|
||||||
HttpOptions options = new HttpOptions(optionsUri);
|
HttpOptions options = new HttpOptions(optionsUri);
|
||||||
return issueResourceRequest(resourceFormat, options, timeoutLoading);
|
return issueResourceRequest(resourceFormat, options, timeoutLoading);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Resource> ResourceRequest<T> issueGetResourceRequest(URI resourceUri, String resourceFormat, int timeoutLoading) {
|
public <T extends Resource> ResourceRequest<T> issueGetResourceRequest(URI resourceUri, String resourceFormat, int timeoutLoading) {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
HttpGet httpget = new HttpGet(resourceUri);
|
HttpGet httpget = new HttpGet(resourceUri);
|
||||||
return issueResourceRequest(resourceFormat, httpget, timeoutLoading);
|
return issueResourceRequest(resourceFormat, httpget, timeoutLoading);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Resource> ResourceRequest<T> issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers, int timeoutLoading) {
|
public <T extends Resource> ResourceRequest<T> issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers, int timeoutLoading) {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
HttpPut httpPut = new HttpPut(resourceUri);
|
HttpPut httpPut = new HttpPut(resourceUri);
|
||||||
return issueResourceRequest(resourceFormat, httpPut, payload, headers, timeoutLoading);
|
return issueResourceRequest(resourceFormat, httpPut, payload, headers, timeoutLoading);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Resource> ResourceRequest<T> issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, int timeoutLoading) {
|
public <T extends Resource> ResourceRequest<T> issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, int timeoutLoading) {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
HttpPut httpPut = new HttpPut(resourceUri);
|
HttpPut httpPut = new HttpPut(resourceUri);
|
||||||
return issueResourceRequest(resourceFormat, httpPut, payload, null, timeoutLoading);
|
return issueResourceRequest(resourceFormat, httpPut, payload, null, timeoutLoading);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Resource> ResourceRequest<T> issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers, int timeoutLoading) {
|
public <T extends Resource> ResourceRequest<T> issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, List<Header> headers, int timeoutLoading) {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
HttpPost httpPost = new HttpPost(resourceUri);
|
HttpPost httpPost = new HttpPost(resourceUri);
|
||||||
return issueResourceRequest(resourceFormat, httpPost, payload, headers, timeoutLoading);
|
return issueResourceRequest(resourceFormat, httpPost, payload, headers, timeoutLoading);
|
||||||
}
|
}
|
||||||
|
@ -170,6 +188,9 @@ public class ClientUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bundle issueGetFeedRequest(URI resourceUri, String resourceFormat) {
|
public Bundle issueGetFeedRequest(URI resourceUri, String resourceFormat) {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
HttpGet httpget = new HttpGet(resourceUri);
|
HttpGet httpget = new HttpGet(resourceUri);
|
||||||
configureFhirRequest(httpget, resourceFormat);
|
configureFhirRequest(httpget, resourceFormat);
|
||||||
HttpResponse response = sendRequest(httpget);
|
HttpResponse response = sendRequest(httpget);
|
||||||
|
@ -188,6 +209,9 @@ public class ClientUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bundle postBatchRequest(URI resourceUri, byte[] payload, String resourceFormat, int timeoutLoading) {
|
public Bundle postBatchRequest(URI resourceUri, byte[] payload, String resourceFormat, int timeoutLoading) {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
HttpPost httpPost = new HttpPost(resourceUri);
|
HttpPost httpPost = new HttpPost(resourceUri);
|
||||||
configureFhirRequest(httpPost, resourceFormat);
|
configureFhirRequest(httpPost, resourceFormat);
|
||||||
HttpResponse response = sendPayload(httpPost, payload, proxy, timeoutLoading);
|
HttpResponse response = sendPayload(httpPost, payload, proxy, timeoutLoading);
|
||||||
|
@ -195,6 +219,9 @@ public class ClientUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean issueDeleteRequest(URI resourceUri) {
|
public boolean issueDeleteRequest(URI resourceUri) {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
HttpDelete deleteRequest = new HttpDelete(resourceUri);
|
HttpDelete deleteRequest = new HttpDelete(resourceUri);
|
||||||
HttpResponse response = sendRequest(deleteRequest);
|
HttpResponse response = sendRequest(deleteRequest);
|
||||||
int responseStatusCode = response.getStatusLine().getStatusCode();
|
int responseStatusCode = response.getStatusLine().getStatusCode();
|
||||||
|
@ -228,6 +255,9 @@ public class ClientUtils {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, List<Header> headers, int timeoutLoading) {
|
protected <T extends Resource> ResourceRequest<T> issueResourceRequest(String resourceFormat, HttpUriRequest request, byte[] payload, List<Header> headers, int timeoutLoading) {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
configureFhirRequest(request, resourceFormat, headers);
|
configureFhirRequest(request, resourceFormat, headers);
|
||||||
HttpResponse response = null;
|
HttpResponse response = null;
|
||||||
if(request instanceof HttpEntityEnclosingRequest && payload != null) {
|
if(request instanceof HttpEntityEnclosingRequest && payload != null) {
|
||||||
|
@ -285,6 +315,9 @@ public class ClientUtils {
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "resource", "deprecation" })
|
@SuppressWarnings({ "resource", "deprecation" })
|
||||||
protected HttpResponse sendPayload(HttpEntityEnclosingRequestBase request, byte[] payload, HttpHost proxy, int timeoutLoading) {
|
protected HttpResponse sendPayload(HttpEntityEnclosingRequestBase request, byte[] payload, HttpHost proxy, int timeoutLoading) {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
HttpResponse response = null;
|
HttpResponse response = null;
|
||||||
boolean ok = false;
|
boolean ok = false;
|
||||||
long t = System.currentTimeMillis();
|
long t = System.currentTimeMillis();
|
||||||
|
@ -309,7 +342,7 @@ public class ClientUtils {
|
||||||
if (tryCount <= retryCount || (tryCount < 3 && ioe instanceof org.apache.http.conn.ConnectTimeoutException)) {
|
if (tryCount <= retryCount || (tryCount < 3 && ioe instanceof org.apache.http.conn.ConnectTimeoutException)) {
|
||||||
ok = false;
|
ok = false;
|
||||||
} else {
|
} else {
|
||||||
throw new EFhirClientException("Error sending HTTP Post/Put Payload: "+ioe.getMessage(), ioe);
|
throw new EFhirClientException("Error sending HTTP Post/Put Payload to "+"??"+": "+ioe.getMessage(), ioe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -323,6 +356,9 @@ public class ClientUtils {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected HttpResponse sendRequest(HttpUriRequest request) {
|
protected HttpResponse sendRequest(HttpUriRequest request) {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
HttpResponse response = null;
|
HttpResponse response = null;
|
||||||
try {
|
try {
|
||||||
HttpClient httpclient = new DefaultHttpClient();
|
HttpClient httpclient = new DefaultHttpClient();
|
||||||
|
@ -430,6 +466,10 @@ public class ClientUtils {
|
||||||
* ***************************************************************/
|
* ***************************************************************/
|
||||||
|
|
||||||
public HttpURLConnection buildConnection(URI baseServiceUri, String tail) {
|
public HttpURLConnection buildConnection(URI baseServiceUri, String tail) {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HttpURLConnection client = (HttpURLConnection) baseServiceUri.resolve(tail).toURL().openConnection();
|
HttpURLConnection client = (HttpURLConnection) baseServiceUri.resolve(tail).toURL().openConnection();
|
||||||
return client;
|
return client;
|
||||||
|
|
|
@ -11,6 +11,8 @@ import org.hl7.fhir.dstu3.model.Resource;
|
||||||
import org.hl7.fhir.dstu3.utils.ResourceUtilities;
|
import org.hl7.fhir.dstu3.utils.ResourceUtilities;
|
||||||
import org.hl7.fhir.dstu3.utils.client.EFhirClientException;
|
import org.hl7.fhir.dstu3.utils.client.EFhirClientException;
|
||||||
import org.hl7.fhir.dstu3.utils.client.ResourceFormat;
|
import org.hl7.fhir.dstu3.utils.client.ResourceFormat;
|
||||||
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
|
import org.hl7.fhir.utilities.ToolGlobalSettings;
|
||||||
import org.hl7.fhir.utilities.ToolingClientLogger;
|
import org.hl7.fhir.utilities.ToolingClientLogger;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
@ -150,6 +152,10 @@ public class FhirRequestBuilder {
|
||||||
* @return {@link OkHttpClient} instance
|
* @return {@link OkHttpClient} instance
|
||||||
*/
|
*/
|
||||||
protected OkHttpClient getHttpClient() {
|
protected OkHttpClient getHttpClient() {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
|
|
||||||
if (okHttpClient == null) {
|
if (okHttpClient == null) {
|
||||||
okHttpClient = new OkHttpClient();
|
okHttpClient = new OkHttpClient();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.hl7.fhir.r4.utils.client.network;
|
||||||
|
|
||||||
import okhttp3.*;
|
import okhttp3.*;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
import org.hl7.fhir.r4.formats.IParser;
|
import org.hl7.fhir.r4.formats.IParser;
|
||||||
import org.hl7.fhir.r4.formats.JsonParser;
|
import org.hl7.fhir.r4.formats.JsonParser;
|
||||||
import org.hl7.fhir.r4.formats.XmlParser;
|
import org.hl7.fhir.r4.formats.XmlParser;
|
||||||
|
@ -11,6 +12,7 @@ import org.hl7.fhir.r4.model.Resource;
|
||||||
import org.hl7.fhir.r4.utils.ResourceUtilities;
|
import org.hl7.fhir.r4.utils.ResourceUtilities;
|
||||||
import org.hl7.fhir.r4.utils.client.EFhirClientException;
|
import org.hl7.fhir.r4.utils.client.EFhirClientException;
|
||||||
import org.hl7.fhir.r4.utils.client.ResourceFormat;
|
import org.hl7.fhir.r4.utils.client.ResourceFormat;
|
||||||
|
import org.hl7.fhir.utilities.ToolGlobalSettings;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -148,6 +150,10 @@ public class FhirRequestBuilder {
|
||||||
* @return {@link OkHttpClient} instance
|
* @return {@link OkHttpClient} instance
|
||||||
*/
|
*/
|
||||||
protected OkHttpClient getHttpClient() {
|
protected OkHttpClient getHttpClient() {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
|
|
||||||
if (okHttpClient == null) {
|
if (okHttpClient == null) {
|
||||||
okHttpClient = new OkHttpClient();
|
okHttpClient = new OkHttpClient();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.hl7.fhir.r5.utils.client.network;
|
||||||
|
|
||||||
import okhttp3.*;
|
import okhttp3.*;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
import org.hl7.fhir.r5.formats.IParser;
|
import org.hl7.fhir.r5.formats.IParser;
|
||||||
import org.hl7.fhir.r5.formats.JsonParser;
|
import org.hl7.fhir.r5.formats.JsonParser;
|
||||||
import org.hl7.fhir.r5.formats.XmlParser;
|
import org.hl7.fhir.r5.formats.XmlParser;
|
||||||
|
@ -11,6 +12,7 @@ import org.hl7.fhir.r5.model.Resource;
|
||||||
import org.hl7.fhir.r5.utils.ResourceUtilities;
|
import org.hl7.fhir.r5.utils.ResourceUtilities;
|
||||||
import org.hl7.fhir.r5.utils.client.EFhirClientException;
|
import org.hl7.fhir.r5.utils.client.EFhirClientException;
|
||||||
import org.hl7.fhir.r5.utils.client.ResourceFormat;
|
import org.hl7.fhir.r5.utils.client.ResourceFormat;
|
||||||
|
import org.hl7.fhir.utilities.ToolGlobalSettings;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -148,6 +150,10 @@ public class FhirRequestBuilder {
|
||||||
* @return {@link OkHttpClient} instance
|
* @return {@link OkHttpClient} instance
|
||||||
*/
|
*/
|
||||||
protected OkHttpClient getHttpClient() {
|
protected OkHttpClient getHttpClient() {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
|
|
||||||
if (okHttpClient == null) {
|
if (okHttpClient == null) {
|
||||||
okHttpClient = new OkHttpClient();
|
okHttpClient = new OkHttpClient();
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,10 @@ public class FTPClient {
|
||||||
* Connect to the server, throw an exception if it fails
|
* Connect to the server, throw an exception if it fails
|
||||||
*/
|
*/
|
||||||
public void connect() throws IOException {
|
public void connect() throws IOException {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
|
|
||||||
if (port != -1) {
|
if (port != -1) {
|
||||||
logger.debug("Connecting to : " + server + ":" + port);
|
logger.debug("Connecting to : " + server + ":" + port);
|
||||||
clientImpl.connect(server, port);
|
clientImpl.connect(server, port);
|
||||||
|
|
|
@ -12,6 +12,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
import org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult;
|
import org.hl7.fhir.utilities.SimpleHTTPClient.HTTPResult;
|
||||||
import org.hl7.fhir.utilities.SimpleHTTPClient.Header;
|
import org.hl7.fhir.utilities.SimpleHTTPClient.Header;
|
||||||
import org.hl7.fhir.utilities.npm.SSLCertTruster;
|
import org.hl7.fhir.utilities.npm.SSLCertTruster;
|
||||||
|
@ -122,6 +123,10 @@ public class SimpleHTTPClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public HTTPResult get(String url, String accept) throws IOException {
|
public HTTPResult get(String url, String accept) throws IOException {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
|
|
||||||
URL u = new URL(url);
|
URL u = new URL(url);
|
||||||
// boolean isSSL = url.startsWith("https://");
|
// boolean isSSL = url.startsWith("https://");
|
||||||
|
|
||||||
|
@ -180,6 +185,9 @@ public class SimpleHTTPClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public HTTPResult post(String url, String contentType, byte[] content, String accept) throws IOException {
|
public HTTPResult post(String url, String contentType, byte[] content, String accept) throws IOException {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
URL u = new URL(url);
|
URL u = new URL(url);
|
||||||
HttpURLConnection c = (HttpURLConnection) u.openConnection();
|
HttpURLConnection c = (HttpURLConnection) u.openConnection();
|
||||||
c.setDoOutput(true);
|
c.setDoOutput(true);
|
||||||
|
@ -197,6 +205,9 @@ public class SimpleHTTPClient {
|
||||||
|
|
||||||
|
|
||||||
public HTTPResult put(String url, String contentType, byte[] content, String accept) throws IOException {
|
public HTTPResult put(String url, String contentType, byte[] content, String accept) throws IOException {
|
||||||
|
if (ToolGlobalSettings.isNoNetwork()) {
|
||||||
|
throw new FHIRException("Network Access is prohibited in this context");
|
||||||
|
}
|
||||||
URL u = new URL(url);
|
URL u = new URL(url);
|
||||||
HttpURLConnection c = (HttpURLConnection) u.openConnection();
|
HttpURLConnection c = (HttpURLConnection) u.openConnection();
|
||||||
c.setDoOutput(true);
|
c.setDoOutput(true);
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
||||||
|
|
||||||
public class ToolGlobalSettings {
|
public class ToolGlobalSettings {
|
||||||
|
|
||||||
|
private static Boolean noNetwork = null;
|
||||||
private static boolean inited = false;
|
private static boolean inited = false;
|
||||||
|
|
||||||
private static String npmPath;
|
private static String npmPath;
|
||||||
|
@ -67,6 +68,17 @@ public class ToolGlobalSettings {
|
||||||
return testIgsPath != null;
|
return testIgsPath != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean isNoNetwork() {
|
||||||
|
init();
|
||||||
|
return noNetwork;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setNoNetwork(boolean value) {
|
||||||
|
init();
|
||||||
|
noNetwork = value;
|
||||||
|
}
|
||||||
|
|
||||||
private static void init() {
|
private static void init() {
|
||||||
if (!inited) {
|
if (!inited) {
|
||||||
inited = true;
|
inited = true;
|
||||||
|
@ -80,6 +92,7 @@ public class ToolGlobalSettings {
|
||||||
comparePath = ini.getStringProperty("paths", "compare");
|
comparePath = ini.getStringProperty("paths", "compare");
|
||||||
tempPath = ini.getStringProperty("paths", "temp");
|
tempPath = ini.getStringProperty("paths", "temp");
|
||||||
testIgsPath = ini.getStringProperty("paths", "test-igs");
|
testIgsPath = ini.getStringProperty("paths", "test-igs");
|
||||||
|
noNetwork = ini.getBooleanProperty("network", "no-access");
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
|
|
|
@ -269,8 +269,32 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
return fetchVersionTheOldWay(id);
|
||||||
|
} catch (Exception e) {
|
||||||
|
ourLog.info("Failed to determine latest version of package {} from server: {}", id, "build.fhir.org");
|
||||||
|
}
|
||||||
|
// still here? use the latest version we previously found or at least, is in the cache
|
||||||
|
|
||||||
return fetchVersionTheOldWay(id);
|
String version = getLatestVersionFromCache(id);
|
||||||
|
if (version != null) {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
throw new FHIRException("Unable to find the last version for package "+id+": no local copy, and no network access");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLatestVersionFromCache(String id) throws IOException {
|
||||||
|
for (String f : reverseSorted(new File(cacheFolder).list())) {
|
||||||
|
File cf = new File(Utilities.path(cacheFolder, f));
|
||||||
|
if (cf.isDirectory()) {
|
||||||
|
if (f.startsWith(id + "#")) {
|
||||||
|
String ver = f.substring(f.indexOf("#")+1);
|
||||||
|
ourLog.info("Latest version of package {} found locally is {} - using that", id, ver);
|
||||||
|
return ver;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private NpmPackage loadPackageFromFile(String id, String folder) throws IOException {
|
private NpmPackage loadPackageFromFile(String id, String folder) throws IOException {
|
||||||
|
@ -685,20 +709,26 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
|
||||||
return null; // nup, we need a new copy
|
return null; // nup, we need a new copy
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
log("Unable to check package currency: "+id+": "+id);
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkBuildLoaded() {
|
private void checkBuildLoaded() {
|
||||||
if (buildLoaded)
|
if (!buildLoaded) {
|
||||||
return true;
|
try {
|
||||||
try {
|
loadFromBuildServer();
|
||||||
loadFromBuildServer();
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
try {
|
||||||
log("Error connecting to build server - running without build (" + e.getMessage() + ")");
|
// we always pause a second and try again - the most common reason to be here is that the file was being changed on the server
|
||||||
e.printStackTrace();
|
Thread.sleep(1000);
|
||||||
|
loadFromBuildServer();
|
||||||
|
} catch (Exception e2) {
|
||||||
|
log("Error connecting to build server - running without build (" + e2.getMessage() + ")");
|
||||||
|
// e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadFromBuildServer() throws IOException {
|
private void loadFromBuildServer() throws IOException {
|
||||||
|
@ -726,7 +756,7 @@ public class FilesystemPackageCacheManager extends BasePackageCacheManager imple
|
||||||
ciList.put(bld.getPackageId(), "https://build.fhir.org/ig/" + bld.getRepo());
|
ciList.put(bld.getPackageId(), "https://build.fhir.org/ig/" + bld.getRepo());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buildLoaded = true; // whether it succeeds or not
|
buildLoaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getRepo(String path) {
|
private String getRepo(String path) {
|
||||||
|
|
Loading…
Reference in New Issue