Skip to content

Commit 777c1fb

Browse files
committed
Refactoring a duplicated function
1 parent 10dcbbb commit 777c1fb

2 files changed

Lines changed: 3 additions & 41 deletions

File tree

vcell-client/src/main/java/org/vcell/util/network/ClientDownloader.java renamed to vcell-core/src/main/java/org/vcell/util/network/ClientDownloader.java

File renamed without changes.

vcell-core/src/test/java/cbit/vcell/pathway/PathwaySearchTest.java

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import java.util.stream.Collectors;
3434

3535
import static org.junit.jupiter.api.Assertions.*;
36-
36+
import static org.vcell.util.network.ClientDownloader.downloadBytes;
3737

3838

3939
@Tag("Fast")
@@ -55,6 +55,8 @@ public static void tearDown() {
5555
}
5656

5757
/*
58+
Given a reactome pathway id, it downloads a pathway as xml document
59+
5860
pathway = {Pathway@14156} "[Pathway: primaryId="http://bioregistry.io/reactome:R-HSA-5683177"; name="Defective ABCC8 can cause hypo- and hyper-glycemias";\ndataSource=[DataSource: primaryId="pc14:reactome"; name="pc14:reactome"]]"
5961
primaryId = "http://bioregistry.io/reactome:R-HSA-5683177"
6062
name = "Defective ABCC8 can cause hypo- and hyper-glycemias"
@@ -108,46 +110,6 @@ public void searchTest() throws IOException {
108110

109111
// --- Utilities ---------------------------------------------------------------------------------------------------
110112

111-
private static String downloadBytes(final URL url, Duration timeout) {
112-
try {
113-
boolean bIgnoreHostMismatch = PropertyLoader.getBooleanProperty(PropertyLoader.sslIgnoreHostMismatch, false);
114-
boolean bIgnoreCertProblems = PropertyLoader.getBooleanProperty(PropertyLoader.sslIgnoreCertProblems, false);
115-
boolean ignoreCertProblems = bIgnoreCertProblems || bIgnoreHostMismatch;
116-
117-
HttpClient client;
118-
if (ignoreCertProblems) {
119-
// create a trust manager that does not validate certificate chains
120-
TrustManager[] trustAllCerts = new TrustManager[] {
121-
new X509TrustManager() {
122-
public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }
123-
public void checkClientTrusted(X509Certificate[] certs, String authType) { }
124-
public void checkServerTrusted(X509Certificate[] certs, String authType) { }
125-
}
126-
};
127-
128-
// Install the all-trusting trust manager
129-
SSLContext sslContext = SSLContext.getInstance("SSL");
130-
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
131-
132-
// Create an HttpClient that uses the custom SSL context
133-
client = HttpClient.newBuilder()
134-
.sslContext(sslContext)
135-
.build();
136-
} else {
137-
// Use default SSL verification
138-
client = HttpClient.newHttpClient();
139-
}
140-
141-
// Send a GET request
142-
java.net.http.HttpRequest request = java.net.http.HttpRequest.newBuilder().uri(url.toURI()).timeout(timeout).GET().build();
143-
java.net.http.HttpResponse<String> response = client.send(request, java.net.http.HttpResponse.BodyHandlers.ofString());
144-
145-
return response.body();
146-
} catch (NoSuchAlgorithmException | KeyManagementException | URISyntaxException | IOException | InterruptedException e) {
147-
throw new RuntimeException(e);
148-
}
149-
}
150-
151113
// wrapper to get a jdom2 Document
152114
private static org.jdom2.Document downloadAndParseXml(URL url, Duration timeout) {
153115
String xmlContent = downloadBytes(url, timeout);

0 commit comments

Comments
 (0)