У меня есть HTTPRepository
, инициализированный URL-адресом в репозитории. Я использую RepositoryConnection
для извлечения и добавления (погоды) данных в репозиторий. Данные извлекаются из веб-службы, затем преобразуются в операторы RDF и добавляются в репозиторий. Это делается периодически с помощью отдельного приложения.RDF4J RIO UnsupportedRDFormatException при добавлении данных в HTTPRepository с использованием автономного приложения
Когда я запускаю это приложение в IntelliJ, все работает нормально.
Чтобы запустить это приложение на сервере, я создал файл jar (содержащий все зависимости). Приложение запускается как ожидалось и может получить данные из репозитория.
Однако, когда приложение пытается записи данных в хранилище я получаю UnsupportedRDFormatException
:
org.eclipse.rdf4j.rio.UnsupportedRDFormatException: Did not recognise RDF format object BinaryRDF (mimeTypes=application/x-binary-rdf; ext=brf)
at org.eclipse.rdf4j.rio.Rio.lambda$unsupportedFormat$0(Rio.java:568) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at java.util.Optional.orElseThrow(Optional.java:290) ~[na:1.8.0_111]
at org.eclipse.rdf4j.rio.Rio.createWriter(Rio.java:134) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.eclipse.rdf4j.rio.Rio.write(Rio.java:371) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.eclipse.rdf4j.rio.Rio.write(Rio.java:324) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.eclipse.rdf4j.repository.http.HTTPRepositoryConnection.addModel(HTTPRepositoryConnection.java:588) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.eclipse.rdf4j.repository.http.HTTPRepositoryConnection.flushTransactionState(HTTPRepositoryConnection.java:662) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.eclipse.rdf4j.repository.http.HTTPRepositoryConnection.commit(HTTPRepositoryConnection.java:326) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.eclipse.rdf4j.repository.base.AbstractRepositoryConnection.conditionalCommit(AbstractRepositoryConnection.java:366) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at org.eclipse.rdf4j.repository.base.AbstractRepositoryConnection.add(AbstractRepositoryConnection.java:431) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at nl.wur.fbr.data.weather.WeatherApp.retrieveData(WeatherApp.java:122) ~[weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at nl.wur.fbr.data.weather.WeatherData$WeatherTask.run(WeatherData.java:105) [weatherData-1.0-SNAPSHOT-jar-with-dependencies.jar:na]
at java.util.TimerThread.mainLoop(Timer.java:555) [na:1.8.0_111]
at java.util.TimerThread.run(Timer.java:505) [na:1.8.0_111]
Исходный код, в котором происходит ошибка:
public void retrieveData(){
logger.info("Retrieving data for weather for app: "+ID+" ");
RepositoryConnection connection = null;
ValueFactory vf = SimpleValueFactory.getInstance();
try {
connection = repository.getConnection();
// Retrieving the locations from the repository (no problem here).
List<Location> locations = this.retrieveLocations(connection);
List<Statement> statements = new ArrayList<>();
// Retrieving weather data from each location and transforming it to statements.
for(Location location : locations){
List<Weather> retrievedWeather = weatherService.retrieveWeatherData(location.name,location.latitude,location.longitude);
for(Weather weather : retrievedWeather){
BNode phenomenon = vf.createBNode();
statements.add(vf.createStatement(location.ID,WEATHER.HAS_WEATHER,phenomenon,rdfStoreGraph));
statements.addAll(weather.getStatements(phenomenon,vf,rdfStoreGraph));
statements = this.correctOMIRIs(statements,vf);
}
}
// Adding data retrieved from the weather API
// This is where the exception happens.
connection.add(statements,rdfStoreGraph);
} catch (Exception e) {
logger.error("Could not retrievedata for weather app: '"+ID+"' because no monitor locations could be found.",e);
} finally {
if(connection != null){
connection.close();
}
}
}
HTTPRespository
является инициализируется следующим образом:
repository = new HTTPRepository(rdfStore.toString());
((HTTPRepository)repository).setPreferredRDFFormat(RDFFormat.BINARY);
((HTTPRepository)repository).setPreferredTupleQueryResultFormat(TupleQueryResultFormat.BINARY);
Я попытался изменить форматы на TURTLE
. Но это не имеет значения.
Можете ли вы рассказать мне, как это решить?
NB. Оба сервера и библиотеки RDF4J имеют версию 2.0.1 (rdf4j).
Я решил пойти другим путем и создал «сухую» банку и вывел зависимости в отдельный каталог 'lib'. Путь к классам, содержащий все зависимости, включен в манифест (как в [этом вопросе] (http://stackoverflow.com/questions/8325819/how-can-i-create-an-executable-jar-without-dependencies-using- Maven)). Благодаря! –