Skip to content

Commit

Permalink
Added support for catching JSON-LD download errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav committed Mar 24, 2024
1 parent e0424a2 commit e2c198d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 10 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,25 @@
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-rio-jsonld</artifactId>
<version>5.0.0-M2</version>
<version>4.3.10</version>
<scope>runtime</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.eclipse.rdf4j/rdf4j-rio-api -->
<dependency>
<groupId>org.eclipse.rdf4j</groupId>
<artifactId>rdf4j-rio-api</artifactId>
<version>5.0.0-M2</version>
<version>4.3.10</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient-cache -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient-cache</artifactId>
<version>4.5.14</version>
</dependency>


<!-- REASONERS -->

<!-- Elk is an OWL 2 EL reasoner -->
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/org/phyloref/jphyloref/helpers/JSONLDHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.github.jsonldjava.core.DocumentLoader;
import com.github.jsonldjava.core.JsonLdError;
import com.github.jsonldjava.core.RemoteDocument;
import com.github.jsonldjava.utils.JsonUtils;
import java.net.URL;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.RDFParser;
import org.eclipse.rdf4j.rio.Rio;
Expand Down Expand Up @@ -70,17 +72,18 @@ public boolean isAnonymousNode(IRI iri) {

// We get some indistinct errors if any of the context URLs in the JSON-LD file are
// incorrect or inaccessible. However, we can set up our own document loader so we
// can detect when this occurs.
// can detect when this occurs.)
parser.set(
JSONLDSettings.DOCUMENT_LOADER,
new DocumentLoader() {
@Override
public RemoteDocument loadDocument(String url) throws JsonLdError {
try {
return super.loadDocument(url);
} catch (JsonLdError err) {
return new RemoteDocument(
url, JsonUtils.fromURL(new URL(url), JsonUtils.createDefaultHttpClient()));
} catch (Exception err) {
logger.error("Error occurred while loading document " + url + ": " + err);
throw err;
throw new JsonLdError(JsonLdError.Error.LOADING_REMOTE_CONTEXT_FAILED, url, err);
}
}
});
Expand Down

0 comments on commit e2c198d

Please sign in to comment.