diff --git a/pom.xml b/pom.xml
index 655133a..c793918 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,8 +10,10 @@
UTF-8
1.8
1.8
- ${project.version}
- 3.6.0
+
+ ${project.version}
+ 3.6.0
+ 2.25.1
@@ -53,13 +55,7 @@
-
- com.j2bugzilla
- j2bugzilla
- 2.2.1
-
-
-
+
org.openrdf.sesame
sesame-repository-sparql
4.1.1
@@ -67,17 +63,17 @@
org.eclipse.lyo
oslc-trs
- ${lyo.version}
+ ${version.lyo}
org.eclipse.lyo.oslc4j.core
oslc4j-core
- ${lyo.version}
+ ${version.lyo}
org.apache.jena
jena-arq
- ${jena.version}
+ ${version.jena}
org.slf4j
@@ -103,12 +99,11 @@
org.eclipse.lyo.clients
- oslc-java-client
- ${lyo.version}
+ oslc4j-client
+ ${version.lyo}
-
junit
junit
@@ -118,7 +113,7 @@
org.apache.jena
jena-tdb
- ${jena.version}
+ ${version.jena}
test
@@ -127,7 +122,17 @@
1.7.25
test
-
+
+ org.glassfish.jersey.core
+ jersey-client
+ ${version.jersey}
+
+
+ com.j2bugzilla
+ j2bugzilla
+ 2.2.1
+ test
+
diff --git a/src/main/java/org/eclipse/lyo/oslc4j/trs/client/config/TrsConsumerConfiguration.java b/src/main/java/org/eclipse/lyo/oslc4j/trs/client/config/TrsConsumerConfiguration.java
index ebfeb69..d74e579 100644
--- a/src/main/java/org/eclipse/lyo/oslc4j/trs/client/config/TrsConsumerConfiguration.java
+++ b/src/main/java/org/eclipse/lyo/oslc4j/trs/client/config/TrsConsumerConfiguration.java
@@ -14,8 +14,11 @@
package org.eclipse.lyo.oslc4j.trs.client.config;
+import com.google.common.base.Strings;
import java.util.concurrent.ScheduledExecutorService;
-import org.eclipse.lyo.oslc4j.trs.client.util.TrsBasicAuthOslcClient;
+import javax.ws.rs.client.ClientBuilder;
+import org.eclipse.lyo.oslc4j.client.OslcClient;
+import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
/**
* Created on 2018-02-27
@@ -29,20 +32,24 @@ public class TrsConsumerConfiguration {
private final String sparqlUpdateUrl;
private final String sparqlUsername;
private final String sparqlPassword;
- private final TrsBasicAuthOslcClient httpClient;
private final String mqttClientId;
private final ScheduledExecutorService scheduler;
+ private final String basicUsername;
+ private final String basicPassword;
+ private OslcClient httpClient;
public TrsConsumerConfiguration(final String sparqlQueryUrl, final String sparqlUpdateUrl,
- final String sparqlUsername, final String sparqlPassword, final TrsBasicAuthOslcClient httpClient,
- final String mqttClientId, final ScheduledExecutorService scheduler) {
+ final String sparqlUsername, final String sparqlPassword, final String mqttClientId,
+ final ScheduledExecutorService scheduler, final String basicUsername,
+ final String basicPassword) {
this.sparqlQueryUrl = sparqlQueryUrl;
this.sparqlUpdateUrl = sparqlUpdateUrl;
this.sparqlUsername = sparqlUsername;
this.sparqlPassword = sparqlPassword;
- this.httpClient = httpClient;
this.mqttClientId = mqttClientId;
this.scheduler = scheduler;
+ this.basicUsername = basicUsername;
+ this.basicPassword = basicPassword;
}
public ScheduledExecutorService getScheduler() {
@@ -69,7 +76,14 @@ public String getSparqlPassword() {
return sparqlPassword;
}
- public TrsBasicAuthOslcClient getHttpClient() {
+ public OslcClient getHttpClient() {
+ if (httpClient == null) {
+ final ClientBuilder builder = ClientBuilder.newBuilder();
+ if (!Strings.isNullOrEmpty(basicUsername)) {
+ builder.register(HttpAuthenticationFeature.basic(basicUsername, basicPassword));
+ }
+ new OslcClient(builder);
+ }
return httpClient;
}
}
diff --git a/src/main/java/org/eclipse/lyo/oslc4j/trs/client/exceptions/TrsEndpointConfigException.java b/src/main/java/org/eclipse/lyo/oslc4j/trs/client/exceptions/TrsEndpointConfigException.java
index 755b351..c0017ef 100644
--- a/src/main/java/org/eclipse/lyo/oslc4j/trs/client/exceptions/TrsEndpointConfigException.java
+++ b/src/main/java/org/eclipse/lyo/oslc4j/trs/client/exceptions/TrsEndpointConfigException.java
@@ -1,6 +1,5 @@
package org.eclipse.lyo.oslc4j.trs.client.exceptions;
-import org.apache.wink.client.ClientResponse;
/**
* TRS Client has a wrong configuration of a TRS Server endpoint.
@@ -25,10 +24,6 @@ public TrsEndpointConfigException(final Throwable cause) {
super(cause);
}
- public TrsEndpointConfigException(final ClientResponse response) {
- super(response);
- }
-
protected TrsEndpointConfigException(final String message, final Throwable cause,
final boolean enableSuppression, final boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
diff --git a/src/main/java/org/eclipse/lyo/oslc4j/trs/client/exceptions/TrsEndpointErrorExpection.java b/src/main/java/org/eclipse/lyo/oslc4j/trs/client/exceptions/TrsEndpointErrorExpection.java
index 553d18c..988c386 100644
--- a/src/main/java/org/eclipse/lyo/oslc4j/trs/client/exceptions/TrsEndpointErrorExpection.java
+++ b/src/main/java/org/eclipse/lyo/oslc4j/trs/client/exceptions/TrsEndpointErrorExpection.java
@@ -1,6 +1,5 @@
package org.eclipse.lyo.oslc4j.trs.client.exceptions;
-import org.apache.wink.client.ClientResponse;
/**
* TRS Server endpoint returns a server error.
@@ -25,10 +24,6 @@ public TrsEndpointErrorExpection(final Throwable cause) {
super(cause);
}
- public TrsEndpointErrorExpection(final ClientResponse response) {
- super(response);
- }
-
protected TrsEndpointErrorExpection(final String message, final Throwable cause,
final boolean enableSuppression, final boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
diff --git a/src/main/java/org/eclipse/lyo/oslc4j/trs/client/exceptions/TrsEndpointException.java b/src/main/java/org/eclipse/lyo/oslc4j/trs/client/exceptions/TrsEndpointException.java
index 209a59d..a091ec9 100644
--- a/src/main/java/org/eclipse/lyo/oslc4j/trs/client/exceptions/TrsEndpointException.java
+++ b/src/main/java/org/eclipse/lyo/oslc4j/trs/client/exceptions/TrsEndpointException.java
@@ -1,6 +1,6 @@
package org.eclipse.lyo.oslc4j.trs.client.exceptions;
-import org.apache.wink.client.ClientResponse;
+import javax.xml.ws.Response;
/**
* High-level exception for connection problems to the TRS Server endpoints.
@@ -10,40 +10,25 @@
*/
public class TrsEndpointException extends Exception {
- private final ClientResponse response;
-
public TrsEndpointException() {
super();
- response = null;
}
public TrsEndpointException(final String message) {
super(message);
- response = null;
}
public TrsEndpointException(final String message, final Throwable cause) {
super(message, cause);
- response = null;
}
public TrsEndpointException(final Throwable cause) {
super(cause);
- response = null;
- }
-
- public TrsEndpointException(final ClientResponse response) {
- super();
- this.response = response;
}
protected TrsEndpointException(final String message, final Throwable cause,
final boolean enableSuppression, final boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
- response = null;
}
- public ClientResponse getResponse() {
- return response;
- }
}
diff --git a/src/main/java/org/eclipse/lyo/oslc4j/trs/client/handlers/BaseMemberHandler.java b/src/main/java/org/eclipse/lyo/oslc4j/trs/client/handlers/BaseMemberHandler.java
index 9894dae..79e7330 100644
--- a/src/main/java/org/eclipse/lyo/oslc4j/trs/client/handlers/BaseMemberHandler.java
+++ b/src/main/java/org/eclipse/lyo/oslc4j/trs/client/handlers/BaseMemberHandler.java
@@ -20,10 +20,9 @@
import java.net.URISyntaxException;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
-import net.oauth.OAuthException;
import org.apache.jena.rdf.model.Model;
+import org.eclipse.lyo.oslc4j.client.OslcClient;
import org.eclipse.lyo.oslc4j.trs.client.util.SparqlUtil;
-import org.eclipse.lyo.oslc4j.trs.client.util.TrsBasicAuthOslcClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,7 +34,7 @@
*/
public class BaseMemberHandler extends TRSTaskHandler {
- final static Logger logger = LoggerFactory.getLogger(BaseMemberHandler.class);
+ private final static Logger logger = LoggerFactory.getLogger(BaseMemberHandler.class);
/*
* the uri of the base member to be processed
*/ String baseMemberUri;
@@ -47,9 +46,9 @@ public class BaseMemberHandler extends TRSTaskHandler {
* the size of the rdf representation of the rdf member
*/ AtomicLong modelSize;
- public BaseMemberHandler(TrsBasicAuthOslcClient oslcClient, String sparqlQueryService,
- String sparqlUpdateService, String baseAuth_userName, String baseAuth_pwd,
- String baseMemberUri, List queries, AtomicLong modelSize) {
+ public BaseMemberHandler(String baseMemberUri, List queries, AtomicLong modelSize,
+ OslcClient oslcClient, String sparqlQueryService, String sparqlUpdateService, String baseAuth_userName,
+ String baseAuth_pwd) {
// TODO Andrew@2018-03-01: use a common SPARQL interface
super(oslcClient,
sparqlQueryService,
@@ -69,7 +68,7 @@ public BaseMemberHandler(TrsBasicAuthOslcClient oslcClient, String sparqlQuerySe
protected void processTRSTask() {
try {
processBaseMemberAddition();
- } catch (IOException | OAuthException | URISyntaxException e) {
+ } catch (IOException | URISyntaxException e) {
logger.error("Error processing TRS task", e);
}
}
@@ -78,7 +77,7 @@ protected void processTRSTask() {
* create the necessary sparql update for processing the base member
*/
private void processBaseMemberAddition()
- throws IOException, OAuthException, URISyntaxException {
+ throws IOException, URISyntaxException {
logger.debug("processing base member " + baseMemberUri + " addition. Creating necessary " +
"" + "" + "sparql update query ");
diff --git a/src/main/java/org/eclipse/lyo/oslc4j/trs/client/handlers/ChangeEventHandler.java b/src/main/java/org/eclipse/lyo/oslc4j/trs/client/handlers/ChangeEventHandler.java
index 4859ac6..df1bdb5 100644
--- a/src/main/java/org/eclipse/lyo/oslc4j/trs/client/handlers/ChangeEventHandler.java
+++ b/src/main/java/org/eclipse/lyo/oslc4j/trs/client/handlers/ChangeEventHandler.java
@@ -21,12 +21,11 @@
import java.net.URISyntaxException;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
-import net.oauth.OAuthException;
import org.apache.jena.rdf.model.Model;
import org.eclipse.lyo.core.trs.ChangeEvent;
import org.eclipse.lyo.core.trs.Deletion;
+import org.eclipse.lyo.oslc4j.client.OslcClient;
import org.eclipse.lyo.oslc4j.trs.client.util.SparqlUtil;
-import org.eclipse.lyo.oslc4j.trs.client.util.TrsBasicAuthOslcClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -53,9 +52,9 @@ public class ChangeEventHandler extends TRSTaskHandler {
*/
AtomicLong modelSize;
- public ChangeEventHandler(TrsBasicAuthOslcClient oslcClient, String sparqlQueryService,
- String sparqlUpdateService, String basicAuthUsername, String basicAuthPassword,
- ChangeEvent handledChangeEvent, List queries, AtomicLong modelSize) {
+ public ChangeEventHandler(ChangeEvent handledChangeEvent, List queries,
+ AtomicLong modelSize, OslcClient oslcClient, String sparqlUpdateService, String sparqlQueryService,
+ String basicAuthUsername, String basicAuthPassword) {
// here we assume the triplestore is not auth-protected, hence nulls
super(oslcClient,
sparqlUpdateService,
@@ -73,7 +72,7 @@ public ChangeEventHandler(TrsBasicAuthOslcClient oslcClient, String sparqlQueryS
this.modelSize = modelSize;
}
- private void processChangeEvent() throws IOException, OAuthException, URISyntaxException {
+ private void processChangeEvent() throws IOException, URISyntaxException {
URI changed = handledChangeEvent.getChanged();
logger.debug("creating query for resource " + changed.toString() + " change event ");
String query;
@@ -105,7 +104,7 @@ private void processChangeEvent() throws IOException, OAuthException, URISyntaxE
protected void processTRSTask() {
try {
processChangeEvent();
- } catch (IOException | OAuthException | URISyntaxException e) {
+ } catch (IOException | URISyntaxException e) {
logger.error("Error processing Change Events", e);
}
}
diff --git a/src/main/java/org/eclipse/lyo/oslc4j/trs/client/handlers/ConcurrentTrsProviderHandler.java b/src/main/java/org/eclipse/lyo/oslc4j/trs/client/handlers/ConcurrentTrsProviderHandler.java
index 1e3ea39..a2b736e 100644
--- a/src/main/java/org/eclipse/lyo/oslc4j/trs/client/handlers/ConcurrentTrsProviderHandler.java
+++ b/src/main/java/org/eclipse/lyo/oslc4j/trs/client/handlers/ConcurrentTrsProviderHandler.java
@@ -28,16 +28,15 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
-import net.oauth.OAuthException;
import org.eclipse.lyo.core.trs.Base;
import org.eclipse.lyo.core.trs.ChangeEvent;
import org.eclipse.lyo.core.trs.ChangeLog;
import org.eclipse.lyo.core.trs.TrackedResourceSet;
+import org.eclipse.lyo.oslc4j.client.OslcClient;
import org.eclipse.lyo.oslc4j.trs.client.exceptions.JenaModelException;
import org.eclipse.lyo.oslc4j.trs.client.exceptions.ServerRollBackException;
import org.eclipse.lyo.oslc4j.trs.client.exceptions.RepresentationRetrievalException;
import org.eclipse.lyo.oslc4j.trs.client.util.SparqlUtil;
-import org.eclipse.lyo.oslc4j.trs.client.util.TrsBasicAuthOslcClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,25 +53,19 @@ public class ConcurrentTrsProviderHandler extends TrsProviderHandler {
private final static Logger log = LoggerFactory.getLogger(ConcurrentTrsProviderHandler.class);
public ConcurrentTrsProviderHandler(String trsUriBase, String sparqlQueryService,
- String sparqlUpdateService, TrsBasicAuthOslcClient trsHttpClient, String userName,
+ String sparqlUpdateService, OslcClient client, String userName,
String pwd, String sparql_user, String sparql_pwd) {
super(
- trsUriBase,
- sparqlQueryService,
- sparqlUpdateService,
- trsHttpClient,
- userName,
- pwd,
- sparql_user,
- sparql_pwd
- );
+ trsUriBase, client, sparqlUpdateService, sparqlQueryService, sparql_user,
+ sparql_pwd, userName,
+ pwd);
}
@Override
public void pollAndProcessChanges()
throws URISyntaxException, JenaModelException, IOException, ServerRollBackException,
- RepresentationRetrievalException, OAuthException {
+ RepresentationRetrievalException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
Date processingDateStart = new Date();
log.info("started dealing with TRS Provider: " + trsUriBase);
@@ -123,30 +116,20 @@ COMMON CODE END (with TRS provider handler)
for (URI baseMemberUri : baseMembers) {
BaseMemberHandler baseMemberHandler = new BaseMemberHandler(
- oslcClient,
+ baseMemberUri.toString(), queries, modelSize, oslcClient,
sparqlQueryService,
sparqlUpdateService,
baseAuth_userName,
- baseAuth_pwd,
- baseMemberUri.toString(),
- queries,
- modelSize
- );
+ baseAuth_pwd);
changeHandlerExecutor.execute(baseMemberHandler);
}
}
for (ChangeEvent compressedChangeEvent : compressedChanges) {
- ChangeEventHandler changeEventHandler = new ChangeEventHandler(
- oslcClient,
- sparqlQueryService,
- sparqlUpdateService,
+ ChangeEventHandler changeEventHandler = new ChangeEventHandler(compressedChangeEvent,
+ queries, modelSize, oslcClient, sparqlUpdateService, sparqlQueryService,
baseAuth_userName,
- baseAuth_pwd,
- compressedChangeEvent,
- queries,
- modelSize
- );
+ baseAuth_pwd);
changeHandlerExecutor.execute(changeEventHandler);
lastProcessedChangeEventUri = compressedChangeEvent.getAbout();
}
diff --git a/src/main/java/org/eclipse/lyo/oslc4j/trs/client/handlers/TRSTaskHandler.java b/src/main/java/org/eclipse/lyo/oslc4j/trs/client/handlers/TRSTaskHandler.java
index 32fe007..21ca645 100644
--- a/src/main/java/org/eclipse/lyo/oslc4j/trs/client/handlers/TRSTaskHandler.java
+++ b/src/main/java/org/eclipse/lyo/oslc4j/trs/client/handlers/TRSTaskHandler.java
@@ -18,9 +18,11 @@
import java.io.IOException;
import java.net.URISyntaxException;
-import net.oauth.OAuthException;
-import org.eclipse.lyo.oslc4j.trs.client.exceptions.TrsEndpointException;
-import org.eclipse.lyo.oslc4j.trs.client.util.TrsBasicAuthOslcClient;
+import javax.ws.rs.core.Response;
+import org.eclipse.lyo.oslc4j.client.OslcClient;
+import org.eclipse.lyo.oslc4j.trs.client.exceptions.TrsEndpointConfigException;
+import org.eclipse.lyo.oslc4j.trs.client.exceptions.TrsEndpointErrorExpection;
+import org.eclipse.lyo.oslc4j.trs.client.util.ClientUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,7 +41,7 @@ public abstract class TRSTaskHandler implements Runnable {
* instance of the http client used by this TRS Task handler to communicate
* with the TRS providers
*/
- protected TrsBasicAuthOslcClient oslcClient;
+ protected OslcClient oslcClient;
/**
* http sparql endpoints of the triplestore used to store the data
*/
@@ -76,19 +78,24 @@ public abstract class TRSTaskHandler implements Runnable {
* @throws IOException
*/
protected Object fetchTRSRemoteResource(String url, Class> objClass)
- throws IOException, OAuthException, URISyntaxException {
+ throws IOException, URISyntaxException {
+ final Response response = oslcClient.getResource(url);
+ final Object resource;
try {
- return oslcClient.fetchResourceUsingBaseAuth(
- url, objClass, baseAuth_userName, baseAuth_pwd);
- } catch (TrsEndpointException e) {
- log.error("The TRS endpoint {} is unreachable", url);
- log.trace("TRS endpoint exception: {}", e);
- // TODO Andrew@2018-06-19: propagate the exception correctly to callers.
- return null;
+ resource = ClientUtil.extractResourceFromResponse(response, objClass);
+ response.close();
+ return resource;
+ } catch (TrsEndpointConfigException e) {
+ log.error("TRS Provider configuration is wrong: ", e);
+ } catch (TrsEndpointErrorExpection e) {
+ log.warn("The TRS endpoint {} is unreachable", url);
+ log.debug("TRS endpoint exception", e);
}
+ // TODO Andrew@2019-04-18: convert return type into Optional