Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Migrate to the new oslc4j-client #32

Merged
merged 5 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@

<dependency>
<groupId>org.eclipse.lyo.clients</groupId>
<artifactId>oslc-java-client</artifactId>
<artifactId>oslc4j-client</artifactId>
<version>${lyo.version}</version>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
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.trs.client.util.SparqlUtil;
import org.eclipse.lyo.oslc4j.trs.client.util.TrsBasicAuthOslcClient;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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 ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
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;
Expand Down Expand Up @@ -72,7 +71,7 @@ public ConcurrentTrsProviderHandler(String trsUriBase, String sparqlQueryService
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

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 org.slf4j.Logger;
Expand Down Expand Up @@ -76,7 +75,7 @@ public abstract class TRSTaskHandler implements Runnable {
* @throws IOException
*/
protected Object fetchTRSRemoteResource(String url, Class<?> objClass)
throws IOException, OAuthException, URISyntaxException {
throws IOException, URISyntaxException {
try {
return oslcClient.fetchResourceUsingBaseAuth(
url, objClass, baseAuth_userName, baseAuth_pwd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@
import java.util.Set;
import java.util.stream.Collectors;
import javax.xml.datatype.DatatypeConfigurationException;
import net.oauth.OAuthException;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.vocabulary.RDF;
import org.apache.wink.client.ClientRuntimeException;
import org.eclipse.lyo.core.trs.Base;
import org.eclipse.lyo.core.trs.ChangeEvent;
import org.eclipse.lyo.core.trs.ChangeLog;
Expand Down Expand Up @@ -138,7 +136,7 @@ protected void processTRSTask() {
* @return the pages of the base of this trs provider
*/
public List<Base> updateBases(TrackedResourceSet updatedTrs)
throws JenaModelException, IOException, OAuthException, URISyntaxException {
throws JenaModelException, IOException, URISyntaxException {
List<Base> bases = new ArrayList<>();
URI firstBasePageUri = updatedTrs.getBase();
Base currentBase = fetchRemoteBase(firstBasePageUri.toString());
Expand Down Expand Up @@ -168,7 +166,7 @@ public List<Base> updateBases(TrackedResourceSet updatedTrs)
* @return the pages of the change log of this trs provider
*/
public List<ChangeLog> fetchUpdatedChangeLogs(TrackedResourceSet updatedTrs)
throws ServerRollBackException, IOException, JenaModelException, OAuthException,
throws ServerRollBackException, IOException, JenaModelException,
URISyntaxException {

ChangeLog firstChangeLog = updatedTrs.getChangeLog();
Expand Down Expand Up @@ -201,7 +199,7 @@ public List<ChangeLog> fetchUpdatedChangeLogs(TrackedResourceSet updatedTrs)
* @return true if the last processed change event is found, false otherwise
*/
public boolean fetchRemoteChangeLogs(ChangeLog currentChangeLog, List<ChangeLog> changeLogs)
throws JenaModelException, IOException, OAuthException, URISyntaxException {
throws JenaModelException, IOException, URISyntaxException {
boolean foundChangeEvent = false;
URI previousChangeLog;
do {
Expand Down Expand Up @@ -274,17 +272,11 @@ protected void baseChangeEventsOptimization(List<ChangeEvent> compressedChangesL
*/
public void pollAndProcessChanges()
throws URISyntaxException, JenaModelException, IOException, ServerRollBackException,
RepresentationRetrievalException, OAuthException {
RepresentationRetrievalException {

log.info("started dealing with TRS Provider: " + trsUriBase);

TrackedResourceSet updatedTrs = null;
try {
updatedTrs = extractRemoteTrs();
} catch (ClientRuntimeException e) {
log.warn("Failed to connect to {}", trsUriBase);
return;
}
TrackedResourceSet updatedTrs = extractRemoteTrs();
boolean indexingStage = false;
List<URI> baseMembers = new ArrayList<>();

Expand Down Expand Up @@ -379,7 +371,7 @@ concurrent handler does it first (though the change handlers don't wait for the
* @param changeEvent the change event to be processed
*/
public void processChangeEvent(ChangeEvent changeEvent)
throws IOException, OAuthException, URISyntaxException {
throws IOException, URISyntaxException {
URI changed = changeEvent.getChanged();
log.info("processing resource " + changed.toString() + " change event ");

Expand Down Expand Up @@ -667,7 +659,7 @@ private Base extractBaseFromRdfModel(Model rdFModel) throws JenaModelException {
* @return trs pojo
*/
TrackedResourceSet extractRemoteTrs()
throws IOException, JenaModelException, URISyntaxException, OAuthException {
throws IOException, JenaModelException, URISyntaxException {
Model rdfModel = (Model) fetchTRSRemoteResource(trsUriBase, Model.class);
return extractTrsFromRdfModel(rdfModel);
}
Expand All @@ -682,7 +674,7 @@ TrackedResourceSet extractRemoteTrs()
*/
private ChangeLog fetchRemoteChangeLog(String changeLogURl)
throws IOException, IllegalArgumentException, SecurityException, JenaModelException,
OAuthException, URISyntaxException {
URISyntaxException {
Model rdfModel = (Model) fetchTRSRemoteResource(changeLogURl, Model.class);
return extractChangeLogFromRdfModel(rdfModel);
}
Expand All @@ -696,7 +688,7 @@ private ChangeLog fetchRemoteChangeLog(String changeLogURl)
* @return base pojo
*/
private Base fetchRemoteBase(String baseUrl)
throws IOException, JenaModelException, OAuthException, URISyntaxException {
throws IOException, JenaModelException, URISyntaxException {
final Model rdFModel = (Model) fetchTRSRemoteResource(baseUrl, Model.class);
return extractBaseFromRdfModel(rdFModel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@
import java.util.HashMap;
import java.util.Map;
import javax.ws.rs.core.Response;
import net.oauth.OAuthException;
import org.apache.commons.codec.binary.Base64;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.wink.client.ClientResponse;
import org.eclipse.lyo.client.oslc.jazz.JazzFormAuthClient;
import org.eclipse.lyo.oslc4j.client.OslcClient;
import org.eclipse.lyo.oslc4j.core.model.AbstractResource;
import org.eclipse.lyo.oslc4j.trs.client.exceptions.TrsEndpointConfigException;
import org.eclipse.lyo.oslc4j.trs.client.exceptions.TrsEndpointErrorExpection;
Expand All @@ -45,7 +43,7 @@
*
* @author Omar
*/
public class TrsBasicAuthOslcClient extends JazzFormAuthClient {
public class TrsBasicAuthOslcClient extends OslcClient {

private static Logger log = LoggerFactory.getLogger(TrsBasicAuthOslcClient.class);

Expand All @@ -65,14 +63,15 @@ public TrsBasicAuthOslcClient() {
*/
public Object fetchResourceUsingBaseAuth(String url, Class<?> objClass, String userName,
String pwd)
throws IOException, OAuthException, URISyntaxException, TrsEndpointException {
ClientResponse clResp = fetchResourceUsingBasicAuth(url, userName, pwd);
throws IOException, URISyntaxException, TrsEndpointException {
Response clResp = fetchResourceUsingBasicAuth(url, userName, pwd);

final Response.Status.Family httpCodeType = clResp.getStatusType().getFamily();
final Response.StatusType responseInfo = clResp.getStatusInfo();
final Response.Status.Family httpCodeType = responseInfo.getFamily();
if (httpCodeType.equals(Response.Status.Family.CLIENT_ERROR)) {
throw new TrsEndpointConfigException(clResp);
throw new TrsEndpointConfigException("Error " + responseInfo.getReasonPhrase());
} else if (httpCodeType.equals(Response.Status.Family.SERVER_ERROR)) {
throw new TrsEndpointErrorExpection(clResp);
throw new TrsEndpointErrorExpection("Error " + responseInfo.getReasonPhrase());
}
// TODO Andrew@2018-02-28: split into 2 methods: unmarshalling a resource and for a model
if (AbstractResource.class.isAssignableFrom(objClass)) {
Expand All @@ -81,12 +80,13 @@ public Object fetchResourceUsingBaseAuth(String url, Class<?> objClass, String u
"Getting entity of type '{}' for server response for resource '{}'",
objClass.getName(),
url);
objToRet = clResp.getEntity(objClass);
objToRet = clResp.readEntity(objClass);
log.debug(
"Getting entity of type '{}' for server response for resource '{}'",
objClass.getName(),
url);
clResp.consumeContent();
// TODO decide if consumeEntity() shall be replaced with close()
// clResp.close();
log.trace("Finished consuming content from server response");
return objToRet;
} else if (Model.class.isAssignableFrom(objClass)) {
Expand All @@ -107,11 +107,11 @@ public Object fetchResourceUsingBaseAuth(String url, Class<?> objClass, String u
*
* @return the http response from the server
*/
public ClientResponse fetchResourceUsingBasicAuth(String url, String userName, String pwd)
throws OAuthException, IOException, URISyntaxException {
public Response fetchResourceUsingBasicAuth(String url, String userName, String pwd)
throws IOException, URISyntaxException {
log.debug("sending GET request to retrieve: " + url + " using basic credentials, user: "
+ userName);
ClientResponse response = null;
Response response = null;
Map<String, String> requestHeaders = new HashMap<String, String>();
// requestHeaders.put("Accept", "application/rdf+xml, application/xml;q=0.6, text/xml;
// q=0.6");
Expand Down Expand Up @@ -142,14 +142,14 @@ public ClientResponse fetchResourceUsingBasicAuth(String url, String userName, S
* @throws IOException thrown while reading from the response
*/
public static Model extractModelFromResponse(String absoluteUrl,
final ClientResponse clientResponse) throws IOException {
final Response clientResponse) throws IOException {

if (clientResponse == null) {
log.debug("The server response for url: " + absoluteUrl + " is null. Returning null");
return null;
}

final String responseAsString = clientResponse.getEntity(String.class);
final String responseAsString = clientResponse.readEntity(String.class);
log.trace("Response for {}:\n{}\n", absoluteUrl, responseAsString);

if (responseAsString == null) {
Expand Down