Skip to content

Commit

Permalink
Upgrade to Jena 4.3.2 (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
berezovskyi committed Jan 31, 2022
1 parent 150b1da commit c80e0cd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 49 deletions.
16 changes: 5 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
<v.kotlin>1.5.32</v.kotlin>
<v.dokka>1.5.31</v.dokka>

<v.jena>4.2.0</v.jena>
<v.jena>4.3.2</v.jena>
<v.jersey>2.35</v.jersey>
<v.slf4j>1.7.32</v.slf4j>
<v.servlet>3.1.0</v.servlet>
<v.httpclient>4.5.13</v.httpclient>
<v.guava>30.1.1-jre</v.guava>
<v.jackson-core>2.12.6</v.jackson-core>
<v.jackson>2.13.0</v.jackson>
</properties>


Expand Down Expand Up @@ -296,12 +296,12 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${v.jackson-core}</version>
<version>${v.jackson}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${v.jackson-core}</version>
<version>${v.jackson}</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -364,17 +364,11 @@
<artifactId>oauth-consumer</artifactId>
<version>20100527</version>
</dependency>
<dependency>
<!-- https://snyk.io/vuln/SNYK-JAVA-ORGAPACHETHRIFT-1074898 -->
<groupId>org.apache.thrift</groupId>
<artifactId>libthrift</artifactId>
<version>0.14.2</version>
</dependency>
<!-- https://app.snyk.io/vuln/SNYK-JAVA-ORGAPACHETOMCATEMBED-1080637 -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>8.5.73</version>
<version>8.5.75</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.eclipse.lyo.store.internals.query;

/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -14,29 +14,21 @@
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.sparql.exec.http.QueryExecutionHTTPBuilder;
import org.apache.jena.sparql.exec.http.UpdateExecutionHTTPBuilder;
import org.apache.jena.update.Update;
import org.apache.jena.update.UpdateExecutionFactory;
import org.apache.jena.update.UpdateFactory;
import org.apache.jena.update.UpdateProcessor;
import org.apache.jena.update.UpdateRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
import static org.apache.jena.http.HttpLib.basicAuth;

/**
* SparqlQueryExecutorImpl is a SPARQL endpoint-based implementation of {@link JenaQueryExecutor}.
*
* @author Andrew Berezovskyi (andriib@kth.se)
* @version $version-stub$
* @since 0.14.0
*/
Expand All @@ -45,38 +37,33 @@ public class SparqlQueryExecutorBasicAuthImpl implements JenaQueryExecutor {

private final String queryEndpoint;
private final String updateEndpoint;
private final CloseableHttpClient client;
private volatile boolean released = false;
private final String login;
private final String password;

public SparqlQueryExecutorBasicAuthImpl(final String sparqlEndpoint,
final String updateEndpoint, final String login, final String password) {
this.queryEndpoint = sparqlEndpoint;
this.updateEndpoint = updateEndpoint;
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(login, password);
provider.setCredentials(AuthScope.ANY, credentials);

client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
this.login = login;
this.password = password;
}

@Override
public QueryExecution prepareSparqlQuery(final String query) {
if (released) {
throw new IllegalStateException("Cannot execute queries after releasing the connection");
}
return QueryExecutionFactory.sparqlService(queryEndpoint, query, client);
return QueryExecutionHTTPBuilder.create()
.endpoint(queryEndpoint)
.httpHeader("Authorization", basicAuth(login, password))
.query(query)
.build();
}

@Override
public UpdateProcessor prepareSparqlUpdate(final UpdateRequest updateRequest) {
if (released) {
throw new IllegalStateException("Cannot execute queries after releasing the connection");
}
return UpdateExecutionFactory.createRemote(
updateRequest,
updateEndpoint,
client
);
return UpdateExecutionHTTPBuilder.create()
.endpoint(updateEndpoint)
.httpHeader("Authorization", basicAuth(login, password))
.update(updateRequest)
.build();
}

@Override
Expand All @@ -91,12 +78,6 @@ public UpdateProcessor prepareSparqlUpdate(final String query) {

@Override
public void release() {
try {
released = true;
client.close();
} catch (IOException e) {
log.warn("Failed to close the HTTP client cleanly");
log.debug("Failed to close the HTTP client cleanly", e);
}
log.trace("No resources to release");
}
}

0 comments on commit c80e0cd

Please sign in to comment.