Skip to content

Commit

Permalink
- major bug fixes
Browse files Browse the repository at this point in the history
- URLs update - now the URLs of the serveces is RESTful compliant
- Rsp services offer the query results on websocket and produce self consumable results (sGraph + ws)
  • Loading branch information
mbalduini committed May 31, 2016
1 parent 7424429 commit 0291a09
Show file tree
Hide file tree
Showing 16 changed files with 692 additions and 454 deletions.
50 changes: 35 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ This work was partially supported by the European project LarKC (FP7-215535) and
<repositories>
<repository>
<id>maven-restlet</id>
<name>Public online Restlet repository</name>
<url>http://maven.restlet.org</url>
<name>Restlet repository</name>
<url>https://maven.restlet.com</url>
</repository>
<repository>
<id>streamreasoning_repository</id>
Expand All @@ -41,7 +41,6 @@ This work was partially supported by the European project LarKC (FP7-215535) and
<layout>default</layout>
</repository>
</repositories>

<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
Expand All @@ -54,6 +53,7 @@ This work was partially supported by the European project LarKC (FP7-215535) and
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<docker.image.prefix>streamreasoning</docker.image.prefix>
<restlet-version>2.3.6</restlet-version>
</properties>

<dependencies>
Expand Down Expand Up @@ -87,19 +87,39 @@ This work was partially supported by the European project LarKC (FP7-215535) and
<dependency>
<groupId>org.restlet.jse</groupId>
<artifactId>org.restlet</artifactId>
<version>2.2.0</version>
<version>${restlet-version}</version>
</dependency>
<dependency>
<groupId>org.restlet.jse</groupId>
<artifactId>org.restlet.ext.jackson</artifactId>
<version>${restlet-version}</version>
</dependency>
<dependency>
<groupId>org.restlet.jee</groupId>
<artifactId>org.restlet.ext.slf4j</artifactId>
<version>2.2.2</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
<version>2.3.2</version>
</dependency>
<!-- http://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.4</version>
</dependency>
<!-- http://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.4</version>
</dependency>

<!-- http://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-annotations -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.4</version>
</dependency>


<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-core</artifactId>
Expand Down Expand Up @@ -157,22 +177,22 @@ This work was partially supported by the European project LarKC (FP7-215535) and
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-server</artifactId>
<version>1.11</version>
<version>1.12</version>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-client</artifactId>
<version>1.11</version>
<version>1.12</version>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-container-grizzly-server</artifactId>
<version>1.11</version>
<version>1.12</version>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-container-grizzly-client</artifactId>
<version>1.11</version>
<version>1.12</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@

public class Csparql_RDF_Stream implements RDF_Stream_Interface{

private RdfStream stream;
private String id;
private String iri;
private RdfStream stream;
private Rsp_services_Component_Status status;
private Model tBox;
private Model staticAbox;
Expand All @@ -44,11 +46,29 @@ public Csparql_RDF_Stream() {
super();
}

public Csparql_RDF_Stream(RdfStream stream, Rsp_services_Component_Status status) {
public Csparql_RDF_Stream(String id, String iri, RdfStream stream, Rsp_services_Component_Status status) {
this.id = id;
this.iri = iri;
this.stream = stream;
this.status = status;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getIri() {
return iri;
}

public void setIri(String iri) {
this.iri = iri;
}

public RdfStream getStream() {
return stream;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@
package it.polimi.deib.rsp_services_csparql.observers;

import it.polimi.deib.rsp_services_csparql.commons.Csparql_Query;
import it.polimi.deib.rsp_services_csparql.observers.utilities.ObserverDescriptorForGet;
import it.polimi.deib.rsp_services_csparql.queries.SingleQueryDataServer;
import it.polimi.deib.rsp_services_csparql.queries.utilities.Csparql_Observer_Descriptor;

import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.Map.Entry;
import java.util.Set;

import org.restlet.data.Header;
import org.restlet.data.MediaType;
import org.restlet.data.Status;
import org.restlet.engine.header.Header;
import org.restlet.resource.Get;
import org.restlet.resource.Options;
import org.restlet.resource.ServerResource;
Expand All @@ -48,7 +50,8 @@ public class MultipleObserversDataServer extends ServerResource {

private Logger logger = LoggerFactory.getLogger(SingleQueryDataServer.class.getName());

@SuppressWarnings("unchecked")

@SuppressWarnings("unchecked")
@Options
public void optionsRequestHandler(){
String origin = getRequest().getClientInfo().getAddress();
Expand All @@ -60,12 +63,11 @@ public void optionsRequestHandler(){
responseHeaders.add(new Header("Access-Control-Allow-Origin", origin));
}

@SuppressWarnings({ "unchecked" })
@Get
public void getObserversInfo(){

csparqlQueryTable = (Hashtable<String, Csparql_Query>) getContext().getAttributes().get("csaprqlQueryTable");
ArrayList<Csparql_Observer_Descriptor> observers = new ArrayList<Csparql_Observer_Descriptor>();
ArrayList<ObserverDescriptorForGet> observers = new ArrayList<ObserverDescriptorForGet>();

String queryName = (String) this.getRequest().getAttributes().get("queryname");

Expand All @@ -78,17 +80,19 @@ public void getObserversInfo(){
responseHeaders.add(new Header("Access-Control-Allow-Origin", origin));

try{
if(queryName.contains(queryName)){
if(csparqlQueryTable.containsKey(queryName)){
Csparql_Query csparqlQuery = csparqlQueryTable.get(queryName);
Set<Entry<String, Csparql_Observer_Descriptor>> obsSet = csparqlQuery.getObservers().entrySet();
for(Entry<String, Csparql_Observer_Descriptor> eObserver : obsSet){
observers.add(eObserver.getValue());
observers.add(new ObserverDescriptorForGet(eObserver.getValue().getId(),
eObserver.getValue().getType(),
"/queries/" + csparqlQuery.getName() + "/observers/" + eObserver.getValue().getId()));
}
this.getResponse().setStatus(Status.SUCCESS_OK,"Observers informations succesfully extracted");
this.getResponse().setEntity(gson.toJson(observers), MediaType.APPLICATION_JSON);
} else {
this.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, queryName + " ID is not associated to any registered query");
this.getResponse().setEntity(gson.toJson(queryName + " ID is not associated to any registered query"), MediaType.APPLICATION_JSON);
this.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, queryName + " is not associated to any registered query");
this.getResponse().setEntity(gson.toJson(queryName + " is not associated to any registered query"), MediaType.APPLICATION_JSON);
}
} catch (Exception e) {
logger.error("Error while getting observers information");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,15 @@
import it.polimi.deib.rsp_services_csparql.commons.Csparql_Query;
import it.polimi.deib.rsp_services_csparql.configuration.Config;

import java.util.Hashtable;
import java.io.StringWriter;
import java.util.*;

import it.polimi.deib.rsp_services_csparql.queries.utilities.Csparql_Observer_Descriptor;
import org.restlet.data.Form;
import org.restlet.data.Header;
import org.restlet.data.MediaType;
import org.restlet.data.Status;
import org.restlet.engine.header.Header;
import org.restlet.representation.Representation;
import org.restlet.resource.Delete;
import org.restlet.resource.Get;
import org.restlet.resource.Options;
Expand Down Expand Up @@ -57,6 +61,53 @@ public void optionsRequestHandler(){
responseHeaders.add(new Header("Access-Control-Allow-Origin", origin));
}

@SuppressWarnings({ "unchecked" })
@Get
public void getObserversInfo(){

csparqlQueryTable = (Hashtable<String, Csparql_Query>) getContext().getAttributes().get("csaprqlQueryTable");

String queryName = (String) this.getRequest().getAttributes().get("queryname");
String obsId = (String) this.getRequest().getAttributes().get("id");

String origin = getRequest().getClientInfo().getAddress();
Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers");
if (responseHeaders == null) {
responseHeaders = new Series<Header>(Header.class);
getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
}
responseHeaders.add(new Header("Access-Control-Allow-Origin", origin));

try{
if(csparqlQueryTable.containsKey(queryName)){
Csparql_Query csparqlQuery = csparqlQueryTable.get(queryName);
HashMap<String, Csparql_Observer_Descriptor> obsMap = csparqlQuery.getObservers();
if(obsMap.containsKey(obsId)) {
Csparql_Observer_Descriptor cso = obsMap.get(obsId);
StringWriter sw = new StringWriter();
cso.getsGraph().write(sw, "JSON-LD");
this.getResponse().setStatus(Status.SUCCESS_OK, "Observers informations succesfully extracted");
this.getResponse().setEntity(sw.toString(), MediaType.APPLICATION_JSON);
} else {
this.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, obsId + " is not associated to any registered observer");
this.getResponse().setEntity(gson.toJson(obsId + " is not associated to any registered observer"), MediaType.APPLICATION_JSON);
}
} else {
this.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, queryName + " is not associated to any registered query");
this.getResponse().setEntity(gson.toJson(queryName + " is not associated to any registered query"), MediaType.APPLICATION_JSON);
}
} catch (Exception e) {
logger.error("Error while getting observers information");
this.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL,"Error while getting observers information");
this.getResponse().setEntity(gson.toJson("Error while getting observers information"), MediaType.APPLICATION_JSON);
} finally{
this.getResponse().commit();
this.commit();
this.release();
}

}

@SuppressWarnings({ "unchecked" })
@Delete
public void unregisterObserver(){
Expand All @@ -66,10 +117,8 @@ public void unregisterObserver(){
csparqlQueryTable = (Hashtable<String, Csparql_Query>) getContext().getAttributes().get("csaprqlQueryTable");
String hostName = Config.getInstance().getHostName();

String queryURI = (String) this.getRequest().getAttributes().get("queryname");
String queryName = queryURI.replace(hostName + "/queries/", "");
String observerURI = (String) this.getRequest().getAttributes().get("id");
String observerId = observerURI.replace(queryURI + "/observers/", "");
String queryName = (String) this.getRequest().getAttributes().get("queryname");
String observerId = (String) this.getRequest().getAttributes().get("id");

String origin = getRequest().getClientInfo().getAddress();
Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers");
Expand All @@ -88,17 +137,17 @@ public void unregisterObserver(){
this.getResponse().setStatus(Status.SUCCESS_OK,"Observer succesfully unregistered");
this.getResponse().setEntity(gson.toJson("Observer succesfully unregistered"), MediaType.APPLICATION_JSON);
} else {
this.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, queryURI + " ID is not associated to any registered query");
this.getResponse().setEntity(gson.toJson(queryURI + " ID is not associated to any registered query"), MediaType.APPLICATION_JSON);
this.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, queryName + " ID is not associated to any registered query");
this.getResponse().setEntity(gson.toJson(queryName + " ID is not associated to any registered query"), MediaType.APPLICATION_JSON);
}
} else {
this.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, queryURI + " ID is not associated to any registered query");
this.getResponse().setEntity(gson.toJson(queryURI + " ID is not associated to any registered query"), MediaType.APPLICATION_JSON);
this.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, queryName + " ID is not associated to any registered query");
this.getResponse().setEntity(gson.toJson(queryName + " ID is not associated to any registered query"), MediaType.APPLICATION_JSON);
}
} catch (Exception e) {
logger.error("Error while unregistering observer " + observerURI);
this.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL,"Error while unregistering observer " + observerURI);
this.getResponse().setEntity(gson.toJson("Error while unregistering observer " + observerURI), MediaType.APPLICATION_JSON);
logger.error("Error while unregistering observer " + observerId);
this.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL,"Error while unregistering observer " + observerId);
this.getResponse().setEntity(gson.toJson("Error while unregistering observer " + observerId), MediaType.APPLICATION_JSON);
} finally{
this.getResponse().commit();
this.commit();
Expand All @@ -115,50 +164,4 @@ public void unregisterObserver(){
}
}

@SuppressWarnings({ "unchecked" })
@Get
public void getObserverInfo(){
String observerURI = new String();
try{
csparqlQueryTable = (Hashtable<String, Csparql_Query>) getContext().getAttributes().get("csaprqlQueryTable");
String hostName = Config.getInstance().getHostName();

String queryURI = (String) this.getRequest().getAttributes().get("queryname");
String queryName = queryURI.replace(hostName + "/queries/", "");
observerURI = (String) this.getRequest().getAttributes().get("id");
String observerId = observerURI.replace(queryURI + "/observers/", "");

String origin = getRequest().getClientInfo().getAddress();
Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers");
if (responseHeaders == null) {
responseHeaders = new Series<Header>(Header.class);
getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
}
responseHeaders.add(new Header("Access-Control-Allow-Origin", origin));

if(csparqlQueryTable.containsKey(queryName)){
Csparql_Query csparqlQuery = csparqlQueryTable.get(queryName);
if(csparqlQuery.getObservers().containsKey(observerId)){
getContext().getAttributes().put("csaprqlQueryTable", csparqlQueryTable);
this.getResponse().setStatus(Status.SUCCESS_OK,"Observer informations succesfully extracted");
this.getResponse().setEntity(gson.toJson(csparqlQuery.getObservers().get(observerId)), MediaType.APPLICATION_JSON);
} else {
this.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, observerURI + " ID is not associated to any registered observer");
this.getResponse().setEntity(gson.toJson(observerURI + " ID is not associated to any registered observer"), MediaType.APPLICATION_JSON);
}
} else {
this.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL, queryURI + " ID is not associated to any registered query");
this.getResponse().setEntity(gson.toJson(queryURI + " ID is not associated to any registered query"), MediaType.APPLICATION_JSON);
}
} catch (Exception e) {
logger.error("Error while unregistering observer " + observerURI);
this.getResponse().setStatus(Status.SERVER_ERROR_INTERNAL,"Error while unregistering observer " + observerURI);
this.getResponse().setEntity(gson.toJson("Error while unregistering observer " + observerURI), MediaType.APPLICATION_JSON);
} finally{
this.getResponse().commit();
this.commit();
this.release();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* This work was partially supported by the European project LarKC (FP7-215535) and by the European project MODAClouds (FP7-318484)
******************************************************************************/
package it.polimi.deib.rsp_services_csparql.observers.utilities;
package it.polimi.deib.rsp_services_csparql.observers.utilities.HTTP;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
Expand Down
Loading

0 comments on commit 0291a09

Please sign in to comment.