Skip to content

Commit ed88bf6

Browse files
committed
Add timeouts to Match and isLive reads
Fixes #230 Also ups the timeout values to minimize the errors. Add simple logging to the classpath. This will make the utility much more chatty. Log level default is set to INFO. See https://www.slf4j.org/api/org/slf4j/simple/SimpleLogger.html to change the logging level.
1 parent 1c03db9 commit ed88bf6

4 files changed

Lines changed: 12 additions & 5 deletions

File tree

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141
<dependency-check-maven.version>12.1.8</dependency-check-maven.version>
4242
</properties>
4343
<dependencies>
44+
<dependency>
45+
<groupId>org.slf4j</groupId>
46+
<artifactId>slf4j-simple</artifactId>
47+
<version>2.0.17</version>
48+
</dependency>
4449
<dependency>
4550
<groupId>junit</groupId>
4651
<artifactId>junit</artifactId>

src/org/spdx/crossref/Live.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,15 @@ public static boolean urlLinkExists(String URLName){
5151
// fake request coming from browser
5252
con.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36");
5353
con.setRequestMethod("HEAD");
54-
con.setConnectTimeout(8500);
54+
con.setConnectTimeout(30000);
55+
con.setReadTimeout(30000);
5556
int responseCode = con.getResponseCode();
5657
return (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_NOT_MODIFIED
5758
|| responseCode == HttpURLConnection.HTTP_MOVED_PERM || responseCode == HttpURLConnection.HTTP_MOVED_TEMP);
5859
} catch (UnknownHostException e) {
5960
return false;
6061
} catch (Exception e) {
61-
logger.warn("Failed checking live status.",e.getMessage());
62+
logger.warn("Failed checking live status for URL {}: {}", URLName, e.getMessage());
6263
return false;
6364
}
6465
}

src/org/spdx/crossref/Match.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ public Match(String url, SpdxListedLicense license) {
4646
*/
4747
public static String checkMatch(String url, SpdxListedLicense license){
4848
try {
49-
Document doc = Jsoup.connect(url).get();
49+
Document doc = Jsoup.connect(url).timeout(30000).get();
5050
String bodyText = doc.body().text();
5151
return String.valueOf(LicenseCompareHelper.isStandardLicenseWithinText(bodyText, license));
5252
} catch (IOException e) {
53-
logger.warn("IO exception comparing license text for license ID "+license.getLicenseId()+" and URL "+url);
53+
logger.warn("IO exception comparing license text for license ID {} and URL {}: {}", url,
54+
license.getLicenseId(), e.getMessage());
5455
return String.valueOf(false);
5556
}
5657
}

src/org/spdx/licensexml/XmlLicenseProviderWithCrossRefDetails.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public synchronized ListedLicenseContainer next() {
9494

9595
ListedLicenseContainer retval = readyLicense.getKey();
9696
try {
97-
for (CrossRef crossRef:readyLicense.getValue().get(2, TimeUnit.MINUTES)) {
97+
for (CrossRef crossRef:readyLicense.getValue().get(5, TimeUnit.MINUTES)) {
9898
retval.getV2ListedLicense().getCrossRef().add(crossRef);
9999
}
100100

0 commit comments

Comments
 (0)