diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/api/protocols/websocket/WebsocketSubscriptionProtocol.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/api/protocols/websocket/WebsocketSubscriptionProtocol.java index 18ecf70c..7f6b4951 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/api/protocols/websocket/WebsocketSubscriptionProtocol.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/api/protocols/websocket/WebsocketSubscriptionProtocol.java @@ -27,6 +27,7 @@ import it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException; import it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException; import it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException; +import it.unibo.arces.wot.sepa.commons.properties.SubscriptionProtocolProperties; import it.unibo.arces.wot.sepa.commons.request.Request; import it.unibo.arces.wot.sepa.commons.request.SubscribeRequest; import it.unibo.arces.wot.sepa.commons.request.UnsubscribeRequest; @@ -44,27 +45,31 @@ public class WebsocketSubscriptionProtocol extends SubscriptionProtocol implemen private final Object mutex; - public WebsocketSubscriptionProtocol(String host, int port, String path, ISubscriptionHandler handler) - throws SEPASecurityException, SEPAProtocolException { - this(host, port, path, handler, null); - } +// public WebsocketSubscriptionProtocol(String host, int port, String path, ISubscriptionHandler handler) +// throws SEPASecurityException, SEPAProtocolException { +// this(host, port, path, handler, null); +// } - public WebsocketSubscriptionProtocol(String scheme, String host, int port, String path, - ISubscriptionHandler handler) throws SEPASecurityException, SEPAProtocolException { - this(scheme, host, port, path, handler, null); - } +// public WebsocketSubscriptionProtocol(String scheme, String host, int port, String path, +// ISubscriptionHandler handler) throws SEPASecurityException, SEPAProtocolException { +// this(scheme, host, port, path, handler, null); +// } - public WebsocketSubscriptionProtocol(String host, int port, String path, ISubscriptionHandler handler, - ClientSecurityManager sm) throws SEPASecurityException, SEPAProtocolException { - this("ws", host, port, path, handler, sm); - } +// public WebsocketSubscriptionProtocol(String host, int port, String path, ISubscriptionHandler handler, +// ClientSecurityManager sm) throws SEPASecurityException, SEPAProtocolException { +// this("ws", host, port, path, handler, sm); +// } - public WebsocketSubscriptionProtocol(String scheme, String host, int port, String path, - ISubscriptionHandler handler, ClientSecurityManager sm) + public WebsocketSubscriptionProtocol(String host, SubscriptionProtocolProperties properties, + ISubscriptionHandler handler, ClientSecurityManager sm) throws SEPASecurityException, SEPAProtocolException { super(handler, sm); mutex = new Object(); + + String scheme = properties.getScheme(); + String path = properties.getPath(); + int port = properties.getPort(); if (!scheme.equals("ws") && !scheme.equals("wss")) throw new SEPAProtocolException("Scheme must be 'ws' or 'wss'"); @@ -87,6 +92,10 @@ public WebsocketSubscriptionProtocol(String scheme, String host, int port, Strin client = new WebsocketClientEndpoint(sm, this); } + { + // TODO Auto-generated constructor stub + } + private void connect() throws SEPASecurityException { Logging.logger.trace("connect"); diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/QueryProperties.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/QueryProperties.java index b7b2edf9..1ba6e307 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/QueryProperties.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/QueryProperties.java @@ -47,13 +47,37 @@ public String getQueryAcceptHeader() { }; - public String path = "/sparql"; - public QueryHTTPMethod method = QueryHTTPMethod.URL_ENCODED_POST; - public QueryResultsFormat format = QueryResultsFormat.JSON; + private String path = "/sparql"; + private QueryHTTPMethod method = QueryHTTPMethod.URL_ENCODED_POST; + private QueryResultsFormat format = QueryResultsFormat.JSON; public void merge(QueryProperties query) { - if (query.path != null) this.path = query.path; - if (query.method != null) this.method = query.method; - if (query.format != null) this.format = query.format; + if (query.getPath() != null) this.setPath(query.getPath()); + if (query.getMethod() != null) this.setMethod(query.getMethod()); + if (query.getFormat() != null) this.setFormat(query.getFormat()); + } + + public QueryHTTPMethod getMethod() { + return method; + } + + public void setMethod(QueryHTTPMethod method) { + this.method = method; + } + + public QueryResultsFormat getFormat() { + return format; + } + + public void setFormat(QueryResultsFormat format) { + this.format = format; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; } } diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11Properties.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11Properties.java index 5764cdb2..d3d351b6 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11Properties.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11Properties.java @@ -84,11 +84,10 @@ public class SPARQL11Properties { // Members. - protected String host; protected SPARQL11ProtocolProperties sparql11protocol; protected GraphsProperties graphs = null; - protected String filename = null; + protected URI uri = null; /** * The Enum SPARQLPrimitive (QUERY, UPDATE). @@ -123,9 +122,8 @@ public String getProtocolScheme() { }; public SPARQL11Properties() { - this.host = "localhost"; this.sparql11protocol = new SPARQL11ProtocolProperties(); - this.sparql11protocol.protocol = ProtocolScheme.http; + this.sparql11protocol.setProtocol(ProtocolScheme.http); override(null); } @@ -136,7 +134,7 @@ public SPARQL11Properties(String args[]) { override(args); } - public SPARQL11Properties(String uri,String[] args) throws SEPAPropertiesException { + public SPARQL11Properties(URI uri,String[] args) throws SEPAPropertiesException { this(); Reader in = getReaderFromUri(uri); @@ -149,44 +147,32 @@ public SPARQL11Properties(String uri,String[] args) throws SEPAPropertiesExcepti override(args); - filename = uri; + this.uri = uri; } - public SPARQL11Properties(String jsapFile) throws SEPAPropertiesException { - this(); - - Reader in = getReaderFromUri(jsapFile); - parseJSAP(in); - try { - in.close(); - } catch (IOException e) { - throw new SEPAPropertiesException(e); - } - - override(null); - - filename = jsapFile; + public SPARQL11Properties(URI uri) throws SEPAPropertiesException { + this(uri,null); } public SPARQL11Properties(String host,ProtocolScheme scheme) { - this.host = host; this.sparql11protocol = new SPARQL11ProtocolProperties(); - this.sparql11protocol.protocol = scheme; + this.sparql11protocol.setHost(host); + this.sparql11protocol.setProtocol(scheme); override(null); } - public SPARQL11Properties(Reader in,String[] args) throws SEPAPropertiesException { - this(); - - parseJSAP(in); - - override(args); - } - - public SPARQL11Properties(Reader in) throws SEPAPropertiesException { - this(in,null); - } +// public SPARQL11Properties(Reader in,String[] args) throws SEPAPropertiesException { +// this(); +// +// parseJSAP(in); +// +// override(args); +// } +// +// public SPARQL11Properties(Reader in) throws SEPAPropertiesException { +// this(in,null); +// } protected void override(String[] args) { Map envs = System.getenv(); @@ -211,7 +197,6 @@ private void parseJSAP(Reader in) throws SEPAPropertiesException { throw new SEPAPropertiesException(e); } - this.host = jsap.host; this.sparql11protocol = jsap.sparql11protocol; this.graphs = jsap.graphs; } @@ -226,26 +211,29 @@ private void parseJSAP(Reader in) throws SEPAPropertiesException { * try to construct or parse a URL from the direct string representation * of a File or Path instance * */ - protected Reader getReaderFromUri(String uri) throws SEPAPropertiesException { + protected Reader getReaderFromUri(URI uri) throws SEPAPropertiesException { Reader in; - Logging.logger.debug("Get stream reader from URI: "+uri); + Logging.logger.debug("Get reader from URI, trying STREAM: "+uri); try { in = new BufferedReader( - new InputStreamReader(URI.create(uri).toURL().openStream())); + new InputStreamReader(uri.toURL().openStream())); + Logging.logger.debug("Success"); } catch (IOException | IllegalArgumentException e) { Logging.logger.debug("Failed to get input stream: "+e.getMessage()); try { - Logging.logger.debug("Get file reader from URI: "+uri); - in = new FileReader(Path.of(uri).toFile()); + Logging.logger.debug("Get reader from URI, trying FILE: "+uri); + in = new FileReader(Path.of(uri.toASCIIString()).toFile()); + Logging.logger.debug("Success"); } catch (FileNotFoundException ex) { - Logging.logger.warn("Failed to get file reader: "+ex.getMessage()); - Logging.logger.info("Get resource from URI: "+uri); - if (getClass().getClassLoader().getResourceAsStream(uri) == null) { + Logging.logger.debug("Failed to get file reader: "+ex.getMessage()); + Logging.logger.debug("Get reader from URI, trying RESOURCE: "+uri); + if (getClass().getClassLoader().getResourceAsStream(uri.toASCIIString()) == null) { Logging.logger.fatal("Resource not found: "+uri); throw new SEPAPropertiesException("Resource not found: "+uri); } - in = new InputStreamReader(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(uri))); + in = new InputStreamReader(Objects.requireNonNull(getClass().getClassLoader().getResourceAsStream(uri.toASCIIString()))); + Logging.logger.debug("Success"); } } @@ -254,35 +242,32 @@ protected Reader getReaderFromUri(String uri) throws SEPAPropertiesException { protected void setParameter(String key,String value) { switch (key) { - case "-host" : - this.host = value; - break; case "-sparql11protocol.port": - this.sparql11protocol.port = Integer.valueOf(value); + this.sparql11protocol.setPort(Integer.valueOf(value)); break; case "-sparql11protocol.host": - this.sparql11protocol.host = host; + this.sparql11protocol.setHost(value); break; case "-sparql11protocol.protocol": - this.sparql11protocol.protocol = (value == "http" ? ProtocolScheme.http : ProtocolScheme.https); + this.sparql11protocol.setProtocol((value == "http" ? ProtocolScheme.http : ProtocolScheme.https)); break; case "-sparql11protocol.update.method": - this.sparql11protocol.update.method = (value == "post" ? UpdateHTTPMethod.POST : UpdateHTTPMethod.URL_ENCODED_POST); + this.sparql11protocol.getUpdate().setMethod((value == "post" ? UpdateHTTPMethod.POST : UpdateHTTPMethod.URL_ENCODED_POST)); break; case "-sparql11protocol.update.format": - this.sparql11protocol.update.format = (value == "json" ? UpdateResultsFormat.JSON : UpdateResultsFormat.HTML); + this.sparql11protocol.getUpdate().setFormat((value == "json" ? UpdateResultsFormat.JSON : UpdateResultsFormat.HTML)); break; case "-sparql11protocol.update.path": - this.sparql11protocol.update.path = value; + this.sparql11protocol.getUpdate().setPath(value); break; case "-sparql11protocol.query.method": - this.sparql11protocol.query.method = (value == "get" ? QueryHTTPMethod.GET : (value == "post" ? QueryHTTPMethod.POST : QueryHTTPMethod.URL_ENCODED_POST)); + this.sparql11protocol.getQuery().setMethod((value == "get" ? QueryHTTPMethod.GET : (value == "post" ? QueryHTTPMethod.POST : QueryHTTPMethod.URL_ENCODED_POST))); break; case "-sparql11protocol.query.format": - this.sparql11protocol.query.format = (value == "json" ? QueryResultsFormat.JSON : (value == "xml" ? QueryResultsFormat.XML : QueryResultsFormat.CSV)); + this.sparql11protocol.getQuery().setFormat((value == "json" ? QueryResultsFormat.JSON : (value == "xml" ? QueryResultsFormat.XML : QueryResultsFormat.CSV))); break; case "-sparql11protocol.query.path": - this.sparql11protocol.query.path = value; + this.sparql11protocol.getQuery().setPath(value); break; } } @@ -291,28 +276,13 @@ public String toString() { return new Gson().toJson(this); } - public void write() throws SEPAPropertiesException { - FileWriter out; - try { - out = new FileWriter(filename); - out.write(this.toString()); - out.close(); - } catch (IOException e) { - if (Logging.logger.isTraceEnabled()) - e.printStackTrace(); - throw new SEPAPropertiesException(e.getMessage()); - } - } - /** * Gets the host. * * @return the host (default is localhost) */ public String getHost() { - if (sparql11protocol == null) return host; - if (sparql11protocol.host == null) return host; - return sparql11protocol.host; + return sparql11protocol.getHost(); } /** @@ -320,7 +290,7 @@ public String getHost() { * */ public void setHost(String host) { - this.host = host; + sparql11protocol.setHost(host); } /** @@ -329,7 +299,7 @@ public void setHost(String host) { * @return the update port */ public int getPort() { - return sparql11protocol.port; + return sparql11protocol.getPort(); } /** @@ -338,7 +308,7 @@ public int getPort() { * @return the update port */ public void setPort(int port) { - sparql11protocol.port = port; + sparql11protocol.setPort(port); } /** @@ -448,11 +418,11 @@ public void setUsingNamedGraphURI(Set graph) { * @return the update path (default is /sparql) */ public String getUpdatePath() { - return sparql11protocol.update.path; + return sparql11protocol.getUpdate().getPath(); } public void setUpdatePath(String path) { - sparql11protocol.update.path = path; + sparql11protocol.getUpdate().setPath(path); } /** @@ -463,11 +433,11 @@ public void setUpdatePath(String path) { * @see QueryHTTPMethod */ public UpdateHTTPMethod getUpdateMethod() { - return sparql11protocol.update.method; + return sparql11protocol.getUpdate().getMethod(); } public void setUpdateMethod(UpdateHTTPMethod method) { - sparql11protocol.update.method = method; + sparql11protocol.getUpdate().setMethod(method); } /** @@ -476,11 +446,11 @@ public void setUpdateMethod(UpdateHTTPMethod method) { * @return the update HTTP Accept header string */ public String getUpdateAcceptHeader() { - return sparql11protocol.update.format.getUpdateAcceptHeader(); + return sparql11protocol.getUpdate().getFormat().getUpdateAcceptHeader(); } public void setUpdateAcceptHeader(UpdateResultsFormat format) { - sparql11protocol.update.format = format; + sparql11protocol.getUpdate().setFormat(format); } /** @@ -489,11 +459,11 @@ public void setUpdateAcceptHeader(UpdateResultsFormat format) { * @return the query path (default is /sparql) */ public String getQueryPath() { - return sparql11protocol.query.path; + return sparql11protocol.getQuery().getPath(); } public void setQueryPath(String path) { - sparql11protocol.query.path = path; + sparql11protocol.getQuery().setPath(path); } /** @@ -504,11 +474,11 @@ public void setQueryPath(String path) { * @see QueryHTTPMethod */ public QueryHTTPMethod getQueryMethod() { - return sparql11protocol.query.method; + return sparql11protocol.getQuery().getMethod(); } public void setQueryMethod(QueryHTTPMethod method) { - sparql11protocol.query.method = method; + sparql11protocol.getQuery().setMethod(method); } /** @@ -518,27 +488,27 @@ public void setQueryMethod(QueryHTTPMethod method) { * */ public String getQueryAcceptHeader() { - return sparql11protocol.query.format.getQueryAcceptHeader(); + return sparql11protocol.getQuery().getFormat().getQueryAcceptHeader(); } public void setQueryAcceptHeader(QueryResultsFormat format) { - sparql11protocol.query.format = format; + sparql11protocol.getQuery().setFormat(format); } public String getUpdateContentTypeHeader() { - return sparql11protocol.update.method.getUpdateContentTypeHeader(); + return sparql11protocol.getUpdate().getMethod().getUpdateContentTypeHeader(); } public String getQueryContentTypeHeader() { - return sparql11protocol.query.method.getQueryContentTypeHeader(); + return sparql11protocol.getQuery().getMethod().getQueryContentTypeHeader(); } public String getProtocolScheme() { - return (sparql11protocol.protocol == null ? null : sparql11protocol.protocol.getProtocolScheme()); + return (sparql11protocol.getProtocol() == null ? null : sparql11protocol.getProtocol().getProtocolScheme()); } public void setProtocolScheme(ProtocolScheme scheme) { - sparql11protocol.protocol = scheme; + sparql11protocol.setProtocol(scheme); } diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11ProtocolProperties.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11ProtocolProperties.java index 68ca9162..94f68731 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11ProtocolProperties.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11ProtocolProperties.java @@ -3,38 +3,62 @@ import it.unibo.arces.wot.sepa.commons.properties.SPARQL11Properties.ProtocolScheme; public class SPARQL11ProtocolProperties { - public String host = null; - public ProtocolScheme protocol = null; - public int port = -1; - public QueryProperties query = null; - public UpdateProperties update = null; + private String host = null; + private ProtocolScheme protocol = null; + private int port = -1; + private QueryProperties query = new QueryProperties(); + private UpdateProperties update = new UpdateProperties(); public SPARQL11ProtocolProperties merge(SPARQL11ProtocolProperties temp) { if (temp != null) { - this.host = (temp.host != null ? temp.host : this.host); - this.protocol = (temp.protocol != null ? temp.protocol : this.protocol); - this.port = (temp.port != -1 ? temp.port : this.port); - this.query.merge(temp.query); - this.update.merge(temp.update); + this.setHost((temp.getHost() != null ? temp.getHost() : this.getHost())); + this.setProtocol((temp.getProtocol() != null ? temp.getProtocol() : this.getProtocol())); + this.setPort((temp.getPort() != -1 ? temp.getPort() : this.getPort())); + this.getQuery().merge(temp.getQuery()); + this.getUpdate().merge(temp.getUpdate()); } return this; } -// public String getUpdateAcceptHeader() { -// return update.format.getUpdateAcceptHeader(); -// } -// -// public UpdateHTTPMethod getUpdateMethod() { -// return update.method; -// } -// -// public String getProtocolScheme() { -// return protocol.getProtocolScheme(); -// } -// -// public String getUpdatePath() { -// return update.path; -// } + public ProtocolScheme getProtocol() { + return protocol; + } + + public void setProtocol(ProtocolScheme protocol) { + this.protocol = protocol; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public UpdateProperties getUpdate() { + return update; + } + + public void setUpdate(UpdateProperties update) { + this.update = update; + } + + public QueryProperties getQuery() { + return query; + } + + public void setQuery(QueryProperties query) { + this.query = query; + } } diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProperties.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProperties.java index 90a31a12..b8189724 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProperties.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/SPARQL11SEProperties.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.Reader; +import java.net.URI; import java.util.HashMap; import com.google.gson.Gson; @@ -87,33 +88,29 @@ public SPARQL11SEProperties() { override(null); } - - /** - * Instantiates a new SPARQL 11 SE properties. - * - * @param in where to read the JSAP from - * @throws SEPAPropertiesException - */ - public SPARQL11SEProperties(Reader in) throws SEPAPropertiesException { - super(in); - - parseJSAP(in); - - override(null); - } - - public SPARQL11SEProperties(Reader in,String[] args) throws SEPAPropertiesException { - super(in,args); - - parseJSAP(in); - - override(args); - } - - public SPARQL11SEProperties(String propertiesFile,String[] args) throws SEPAPropertiesException { - super(propertiesFile); - - Reader in = getReaderFromUri(propertiesFile); +// +// /** +// * Instantiates a new SPARQL 11 SE properties. +// * +// * @param in where to read the JSAP from +// * @throws SEPAPropertiesException +// */ +// public SPARQL11SEProperties(Reader in) throws SEPAPropertiesException { +// this(in,null); +// } +// +// public SPARQL11SEProperties(Reader in,String[] args) throws SEPAPropertiesException { +// super(in,args); +// +// parseJSAP(in); +// +// override(args); +// } + + public SPARQL11SEProperties(URI uri,String[] args) throws SEPAPropertiesException { + super(uri); + + Reader in = getReaderFromUri(uri); parseJSAP(in); try { in.close(); @@ -124,18 +121,8 @@ public SPARQL11SEProperties(String propertiesFile,String[] args) throws SEPAProp override(args); } - public SPARQL11SEProperties(String propertiesFile) throws SEPAPropertiesException { - super(propertiesFile); - - Reader in = getReaderFromUri(propertiesFile); - parseJSAP(in); - try { - in.close(); - } catch (IOException e) { - throw new SEPAPropertiesException(e); - } - - override(null); + public SPARQL11SEProperties(URI uri) throws SEPAPropertiesException { + super(uri,null); } private void parseJSAP(Reader in) throws SEPAPropertiesException { @@ -150,40 +137,10 @@ private void parseJSAP(Reader in) throws SEPAPropertiesException { } } - protected final void setParameter(String key,String value) { + protected void setParameter(String key,String value) { super.setParameter(key, value); switch (key) { -// case "-host" : -// this.host = value; -// break; -// case "-sparql11protocol.port": -// this.sparql11protocol.port = Integer.valueOf(value); -// break; -// case "-sparql11protocol.host": -// this.sparql11protocol.host = host; -// break; -// case "-sparql11protocol.protocol": -// this.sparql11protocol.protocol = (value == "http" ? ProtocolScheme.http : ProtocolScheme.https); -// break; -// case "-sparql11protocol.update.method": -// this.sparql11protocol.update.method = (value == "post" ? UpdateProperties.UpdateHTTPMethod.POST : UpdateProperties.UpdateHTTPMethod.URL_ENCODED_POST); -// break; -// case "-sparql11protocol.update.format": -// this.sparql11protocol.update.format = (value == "json" ? UpdateProperties.UpdateResultsFormat.JSON : UpdateProperties.UpdateResultsFormat.HTML); -// break; -// case "-sparql11protocol.update.path": -// this.sparql11protocol.update.path = value; -// break; -// case "-sparql11protocol.query.method": -// this.sparql11protocol.query.method = (value == "get" ? QueryProperties.QueryHTTPMethod.GET : (value == "post" ? QueryProperties.QueryHTTPMethod.POST : QueryProperties.QueryHTTPMethod.URL_ENCODED_POST)); -// break; -// case "-sparql11protocol.query.format": -// this.sparql11protocol.query.format = (value == "json" ? QueryProperties.QueryResultsFormat.JSON : (value == "xml" ? QueryProperties.QueryResultsFormat.XML : QueryProperties.QueryResultsFormat.CSV)); -// break; -// case "-sparql11protocol.query.path": -// this.sparql11protocol.query.path = value; -// break; case "-sparql11seprotocol.host": this.sparql11seprotocol.setHost(value); break; @@ -213,7 +170,7 @@ public String toString() { } public String getSubscribeHost() { - return (sparql11seprotocol.getHost() != null ? sparql11seprotocol.getHost() : super.host); + return sparql11seprotocol.getHost(); } public void setHost(String host) { diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/UpdateProperties.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/UpdateProperties.java index e7c0d392..ee463ce2 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/UpdateProperties.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/commons/properties/UpdateProperties.java @@ -42,15 +42,39 @@ public String getUpdateAcceptHeader() { } }; - public String path = "/sparql"; - public UpdateHTTPMethod method = UpdateHTTPMethod.URL_ENCODED_POST; - public UpdateResultsFormat format = UpdateResultsFormat.JSON; + private String path = "/sparql"; + private UpdateHTTPMethod method = UpdateHTTPMethod.URL_ENCODED_POST; + private UpdateResultsFormat format = UpdateResultsFormat.JSON; public void merge(UpdateProperties update) { - if (update.path != null) this.path = update.path; - if (update.method != null) this.method = update.method; - if (update.format != null) this.format = update.format; + if (update.getPath() != null) this.setPath(update.getPath()); + if (update.getMethod() != null) this.setMethod(update.getMethod()); + if (update.getFormat() != null) this.setFormat(update.getFormat()); } + public UpdateHTTPMethod getMethod() { + return method; + } + + public void setMethod(UpdateHTTPMethod method) { + this.method = method; + } + + public UpdateResultsFormat getFormat() { + return format; + } + + public void setFormat(UpdateResultsFormat format) { + this.format = format; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + } diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/Consumer.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/Consumer.java index 2efc6a03..b9887164 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/Consumer.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/Consumer.java @@ -31,6 +31,7 @@ import it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException; import it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException; import it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException; +import it.unibo.arces.wot.sepa.commons.properties.SubscriptionProtocolProperties; import it.unibo.arces.wot.sepa.commons.request.SubscribeRequest; import it.unibo.arces.wot.sepa.commons.request.UnsubscribeRequest; import it.unibo.arces.wot.sepa.commons.response.ErrorResponse; @@ -72,9 +73,8 @@ public Consumer(JSAP appProfile, String subscribeID) } // Subscription protocol - - protocol = new WebsocketSubscriptionProtocol(appProfile.getSubscribeHost(subID), - appProfile.getSubscribePort(subID), appProfile.getSubscribePath(subID),this,sm); + SubscriptionProtocolProperties properties = appProfile.getSubscribeProtocol(subID); + protocol = new WebsocketSubscriptionProtocol(appProfile.getSubscribeHost(subID),properties,this,sm); client = new SPARQL11SEProtocol(protocol,sm); } @@ -157,8 +157,8 @@ public void onBrokenConnection(ErrorResponse errorResponse) { // Auto reconnection mechanism if (appProfile.reconnect()) { try { - protocol = new WebsocketSubscriptionProtocol(appProfile.getSubscribeHost(subID), - appProfile.getSubscribePort(subID), appProfile.getSubscribePath(subID),this,sm); + SubscriptionProtocolProperties properties = appProfile.getSubscribeProtocol(subID); + protocol = new WebsocketSubscriptionProtocol(appProfile.getSubscribeHost(subID),properties,this,sm); client = new SPARQL11SEProtocol(protocol,sm); } catch (SEPASecurityException | SEPAProtocolException e1) { Logging.logger.error(e1.getMessage()); diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/GenericClient.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/GenericClient.java index 1805a301..4e92ee94 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/GenericClient.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/GenericClient.java @@ -32,6 +32,7 @@ import it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException; import it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException; import it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException; +import it.unibo.arces.wot.sepa.commons.properties.SubscriptionProtocolProperties; import it.unibo.arces.wot.sepa.commons.request.QueryRequest; import it.unibo.arces.wot.sepa.commons.request.Request; import it.unibo.arces.wot.sepa.commons.request.SubscribeRequest; @@ -418,8 +419,8 @@ private void _subscribe(String ID, String sparql, Bindings forced, String alias, if (activeClients.containsKey(url)) { subscription = activeClients.get(url); } else { - protocol = new WebsocketSubscriptionProtocol(appProfile.getSubscribeProtocol(ID).getScheme(),appProfile.getSubscribeHost(ID), - appProfile.getSubscribePort(ID), appProfile.getSubscribePath(ID), this, sm); + SubscriptionProtocolProperties properties = appProfile.getSubscribeProtocol(ID); + protocol = new WebsocketSubscriptionProtocol(appProfile.getSubscribeHost(ID),properties,this,sm); subscription = new SPARQL11SEProtocol(protocol); } diff --git a/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/JSAP.java b/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/JSAP.java index a3f2f3ad..75e40870 100644 --- a/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/JSAP.java +++ b/client-api/src/main/java/it/unibo/arces/wot/sepa/pattern/JSAP.java @@ -21,8 +21,6 @@ import java.io.*; import java.net.URI; import java.net.URISyntaxException; -import java.nio.file.InvalidPathException; -import java.nio.file.Path; import java.util.*; import java.util.Map.Entry; @@ -194,9 +192,9 @@ public class JSAP extends SPARQL11SEProperties { private static Set numbersOrBoolean = new HashSet(); private PrefixMappingMem prefixes; - // private String prefixes = ""; // Members + protected String host = "localhost"; protected HashMap queries = null;// new HashMap(); protected HashMap updates = null;// new HashMap(); protected HashMap namespaces = new HashMap(); @@ -225,11 +223,18 @@ private void defaultNamespaces() { namespaces.put("xsd", "http://www.w3.org/2001/XMLSchema#"); } - public JSAP(String uri) throws SEPAPropertiesException, SEPASecurityException { + public JSAP(URI uri) throws SEPAPropertiesException, SEPASecurityException { this(uri, null); } + + public JSAP(String uri) throws SEPAPropertiesException, SEPASecurityException { + this(URI.create(uri), null); + } public JSAP(String uri, String[] args) throws SEPAPropertiesException, SEPASecurityException { + this(URI.create(uri),args); + } + public JSAP(URI uri, String[] args) throws SEPAPropertiesException, SEPASecurityException { super(uri); prefixes = new PrefixMappingMem(); @@ -242,40 +247,29 @@ public JSAP(String uri, String[] args) throws SEPAPropertiesException, SEPASecur buildSPARQLPrefixes(); } - - private void load(String uri, boolean replace) throws SEPAPropertiesException, SEPASecurityException { - read(uri, replace); - - // Include - ArrayList uriList = new ArrayList<>(); - - if (include != null) { - for (JsonElement element : include) - uriList.add(element.getAsString()); - - include = new JsonArray(); + + protected void override(String[] args) { + Map envs = System.getenv(); + for(String var : envs.keySet()) { + Logging.logger.trace("Environmental variable "+var+" : "+envs.get(var)); + setParameter("-"+var, envs.get(var)); } - for (String child : uriList) { - Path path; - try { - path = Path.of(child); - } catch (InvalidPathException e) { - load(child, false); - continue; - } - - if (path.isAbsolute()) - load(child, false); - else { - Path childPath = Path.of(uri); - if (childPath.getParent() != null) - load(childPath.getParent().toString() + File.separator + child, false); - else - load(child, false); + if (args != null) + for (int i = 0; i < args.length; i = i + 2) { + Logging.logger.trace("Argument "+args[i]+" : "+args[i+1]); + setParameter(args[i], args[i+1]); } + } + + protected void setParameter(String key,String value) { + super.setParameter(key, value); + + switch (key) { + case "-host" : + this.host = value; + break; } - } public void read(Reader in, boolean replace) { @@ -305,6 +299,10 @@ public void read(Reader in, boolean replace) { * @throws SEPAPropertiesException */ public void read(String uri, boolean replace) throws SEPAPropertiesException { + read(URI.create(uri), replace); + } + + public void read(URI uri, boolean replace) throws SEPAPropertiesException { Reader in = getReaderFromUri(uri); read(in, replace); try { @@ -314,9 +312,30 @@ public void read(String uri, boolean replace) throws SEPAPropertiesException { } } - public void read(String filename) throws SEPAPropertiesException, SEPASecurityException { - read(filename, true); + public void read(String uri) throws SEPAPropertiesException, SEPASecurityException { + read(URI.create(uri)); } + public void read(URI uri) throws SEPAPropertiesException, SEPASecurityException { + read(uri, true); + } + + private void load(URI uri, boolean replace) throws SEPAPropertiesException, SEPASecurityException { + read(uri, replace); + + // Include + ArrayList uriList = new ArrayList<>(); + + if (include != null) { + for (JsonElement element : include) + uriList.add(element.getAsString()); + + include = new JsonArray(); + } + + for (String child : uriList) load(URI.create(child), false); + } + + private void merge(JSAP temp) { host = (temp.host != null ? temp.host : this.host); @@ -449,51 +468,67 @@ public String getSPARQLUpdate(String id) { } public String getUpdateHost(String id) { + String ret = null; try { - return updates.get(id).sparql11protocol.host; + ret = updates.get(id).sparql11protocol.getHost(); } catch (Exception e) { - return host; } + if (ret == null) { + ret = sparql11protocol.getHost(); + if (ret == null) ret = host; + } + + return ret; } public String getUpdateAcceptHeader(String id) { + String ret = null; try { - return updates.get(id).sparql11protocol.update.format.getUpdateAcceptHeader(); + ret = updates.get(id).sparql11protocol.getUpdate().getFormat().getUpdateAcceptHeader(); } catch (Exception e) { - return sparql11protocol.update.format.getUpdateAcceptHeader(); + } + return (ret == null ? sparql11protocol.getUpdate().getFormat().getUpdateAcceptHeader() : ret); } public UpdateProperties.UpdateHTTPMethod getUpdateMethod(String id) { + UpdateProperties.UpdateHTTPMethod ret = null; try { - return updates.get(id).sparql11protocol.update.method; + ret = updates.get(id).sparql11protocol.getUpdate().getMethod(); } catch (Exception e) { - return sparql11protocol.update.method; + } + return (ret == null ? sparql11protocol.getUpdate().getMethod() : ret); } public String getUpdateProtocolScheme(String id) { + String ret = null; try { - return updates.get(id).sparql11protocol.protocol.getProtocolScheme(); + ret = updates.get(id).sparql11protocol.getProtocol().getProtocolScheme(); } catch (Exception e) { - return sparql11protocol.protocol.getProtocolScheme(); + } + return (ret == null ? sparql11protocol.getProtocol().getProtocolScheme() : ret); } public String getUpdatePath(String id) { + String ret = null; try { - return updates.get(id).sparql11protocol.update.path; + return updates.get(id).sparql11protocol.getUpdate().getPath(); } catch (Exception e) { - return sparql11protocol.update.path; + } + return (ret == null ? sparql11protocol.getUpdate().getPath() : ret); } public int getUpdatePort(String id) { + int ret = -1; try { - return updates.get(id).sparql11protocol.port; + ret = updates.get(id).sparql11protocol.getPort(); } catch (Exception e) { - return sparql11protocol.port; + } + return (ret == -1 ? sparql11protocol.getPort() : ret); } public Set getUsingNamedGraphURI(String id) { @@ -524,37 +559,37 @@ public void setSPARQLUpdate(String id, String sparql) { public void setUpdateHost(String id, String host) { if (updates.get(id) == null) return; - updates.get(id).sparql11protocol.host = host; + updates.get(id).sparql11protocol.setHost(host); } public void setUpdateAcceptHeader(String id, UpdateResultsFormat format) { if (updates.get(id) == null) return; - updates.get(id).sparql11protocol.update.format = format; + updates.get(id).sparql11protocol.getUpdate().setFormat(format); } public void setUpdateMethod(String id, UpdateHTTPMethod method) { if (updates.get(id) == null) return; - updates.get(id).sparql11protocol.update.method = method; + updates.get(id).sparql11protocol.getUpdate().setMethod(method); } public void setUpdateProtocolScheme(String id, ProtocolScheme scheme) { if (updates.get(id) == null) return; - updates.get(id).sparql11protocol.protocol = scheme; + updates.get(id).sparql11protocol.setProtocol(scheme); } public void setUpdatePath(String id, String path) { if (updates.get(id) == null) return; - updates.get(id).sparql11protocol.update.path = path; + updates.get(id).sparql11protocol.getUpdate().setPath(path); } public void setUpdatePort(String id, int port) { if (updates.get(id) == null) return; - updates.get(id).sparql11protocol.port = port; + updates.get(id).sparql11protocol.setPort(port); } public void setUsingNamedGraphUri(String id, Set graph) { @@ -577,51 +612,65 @@ public String getSPARQLQuery(String id) { } public String getQueryHost(String id) { + String ret = null; try { - return queries.get(id).sparql11protocol.host; + ret = queries.get(id).sparql11protocol.getHost(); } catch (Exception e) { - return host; + } + if (ret == null) { + ret = sparql11protocol.getHost(); + if (ret == null) ret = host; + } + + return ret; } public String getQueryProtocolScheme(String id) { try { - return queries.get(id).sparql11protocol.protocol.getProtocolScheme(); + return queries.get(id).sparql11protocol.getProtocol().getProtocolScheme(); } catch (Exception e) { - return sparql11protocol.protocol.getProtocolScheme(); + return sparql11protocol.getProtocol().getProtocolScheme(); } } public int getQueryPort(String id) { + int ret = -1; try { - return queries.get(id).sparql11protocol.port; + ret = queries.get(id).sparql11protocol.getPort(); } catch (Exception e) { - return sparql11protocol.port; + } + return (ret == -1 ? sparql11protocol.getPort() : ret); } public String getQueryPath(String id) { + String ret = null; try { - return queries.get(id).sparql11protocol.query.path; + ret = queries.get(id).sparql11protocol.getQuery().getPath(); } catch (Exception e) { - return sparql11protocol.query.path; + } + return (ret == null ?sparql11protocol.getQuery().getPath() : ret); } public QueryHTTPMethod getQueryMethod(String id) { + QueryHTTPMethod ret = null; try { - return queries.get(id).sparql11protocol.query.method; + ret = queries.get(id).sparql11protocol.getQuery().getMethod(); } catch (Exception e) { - return sparql11protocol.query.method; + } + return (ret == null ? sparql11protocol.getQuery().getMethod() : ret); } public String getQueryAcceptHeader(String id) { + String ret= null; try { - return queries.get(id).sparql11protocol.query.format.getQueryAcceptHeader(); + ret = queries.get(id).sparql11protocol.getQuery().getFormat().getQueryAcceptHeader(); } catch (Exception e) { - return sparql11protocol.query.format.getQueryAcceptHeader(); } + return (ret == null ? sparql11protocol.getQuery().getFormat().getQueryAcceptHeader(): ret); } public Set getNamedGraphURI(String id) { @@ -652,37 +701,37 @@ public void setSPARQLQuery(String id, String sparql) { public void setQueryHost(String id, String host) { if (queries.get(id) == null) return; - queries.get(id).sparql11protocol.host = host; + queries.get(id).sparql11protocol.setHost(host); } public void setQueryAcceptHeader(String id, QueryResultsFormat format) { if (queries.get(id) == null) return; - queries.get(id).sparql11protocol.query.format = format; + queries.get(id).sparql11protocol.getQuery().setFormat(format); } public void setQueryMethod(String id, QueryHTTPMethod method) { if (queries.get(id) == null) return; - queries.get(id).sparql11protocol.query.method = method; + queries.get(id).sparql11protocol.getQuery().setMethod(method); } public void setQueryProtocolScheme(String id, ProtocolScheme scheme) { if (queries.get(id) == null) return; - queries.get(id).sparql11protocol.protocol = scheme; + queries.get(id).sparql11protocol.setProtocol(scheme); } public void setQueryPath(String id, String path) { if (queries.get(id) == null) return; - queries.get(id).sparql11protocol.query.path = path; + queries.get(id).sparql11protocol.getQuery().setPath(path); } public void setQueryPort(String id, int port) { if (queries.get(id) == null) return; - queries.get(id).sparql11protocol.port = port; + queries.get(id).sparql11protocol.setPort(port); } public void setNamedGraphUri(String id, Set graph) { @@ -702,11 +751,17 @@ public void setDefaultGraphURI(String id, Set graph) { */ public String getSubscribeHost(String id) { + String ret=null; try { - return queries.get(id).sparql11seprotocol.getHost(); + ret = queries.get(id).sparql11seprotocol.getHost(); } catch (Exception e) { - return sparql11seprotocol.getHost(); + } + if(ret == null) { + ret = sparql11seprotocol.getHost(); + if (ret == null) ret = host; + } + return ret; } public void setSubscribeHost(String id, String host) { @@ -718,12 +773,13 @@ public void setSubscribeHost(String id, String host) { } public int getSubscribePort(String id) { + int ret = -1; try { - return queries.get(id).sparql11seprotocol.getAvailableProtocols() + ret = queries.get(id).sparql11seprotocol.getAvailableProtocols() .get(queries.get(id).sparql11seprotocol.getProtocol()).getPort(); } catch (Exception e) { - return sparql11seprotocol.getPort(); } + return (ret == -1 ? sparql11seprotocol.getPort() : ret); } public void setSubscribePort(String id, int port) { @@ -736,12 +792,13 @@ public void setSubscribePort(String id, int port) { } public String getSubscribePath(String id) { + String ret=null; try { - return queries.get(id).sparql11seprotocol.getAvailableProtocols() + ret= queries.get(id).sparql11seprotocol.getAvailableProtocols() .get(queries.get(id).sparql11seprotocol.getProtocol()).getPath(); } catch (Exception e) { - return sparql11seprotocol.getPath(); } + return (ret == null ? sparql11seprotocol.getPath() : ret); } public void setSubscribePath(String id, String path) { @@ -754,11 +811,16 @@ public void setSubscribePath(String id, String path) { } public SubscriptionProtocolProperties getSubscribeProtocol(String id) { + SubscriptionProtocolProperties ret = null; try { - return queries.get(id).sparql11seprotocol.getSubscriptionProtocol(); + ret= queries.get(id).sparql11seprotocol.getSubscriptionProtocol(); } catch (Exception e) { - return sparql11seprotocol.getSubscriptionProtocol(); } + return (ret == null ? sparql11seprotocol.getSubscriptionProtocol() : ret); + } + + public SubscriptionProtocolProperties getSubscribeProtocol() { + return sparql11seprotocol.getSubscriptionProtocol(); } public void setSubscribeProtocol(String id, SubscriptionProtocolProperties sp) { @@ -1022,7 +1084,7 @@ else if (upd instanceof UpdateCreate) else if (upd instanceof UpdateModify) visitor.visit((UpdateModify) upd); - if (upd instanceof UpdateAdd || upd instanceof UpdateDataDelete || upd instanceof UpdateDataInsert + if (upd instanceof UpdateModify || upd instanceof UpdateAdd || upd instanceof UpdateDataDelete || upd instanceof UpdateDataInsert || upd instanceof UpdateDeleteWhere) { prologue = extractPrologue(null); } diff --git a/client-api/src/test/java/it/unibo/arces/wot/sepa/ConfigurationProvider.java b/client-api/src/test/java/it/unibo/arces/wot/sepa/ConfigurationProvider.java index f6fe6c9d..8b467a2b 100644 --- a/client-api/src/test/java/it/unibo/arces/wot/sepa/ConfigurationProvider.java +++ b/client-api/src/test/java/it/unibo/arces/wot/sepa/ConfigurationProvider.java @@ -16,6 +16,7 @@ import java.io.Closeable; import java.io.File; import java.io.IOException; +import java.net.URI; import java.util.UUID; public class ConfigurationProvider implements Closeable { @@ -51,7 +52,7 @@ public ConfigurationProvider() throws SEPAPropertiesException, SEPASecurityExcep Logging.logger.debug("Loading JSAP from: " + f.getPath()); try { - appProfile = new JSAP(f.getPath()); + appProfile = new JSAP(URI.create(f.getPath())); } catch (SEPAPropertiesException e) { Logging.logger.error(e.getMessage()); throw new RuntimeException(e); diff --git a/client-api/src/test/java/it/unibo/arces/wot/sepa/Subscriber.java b/client-api/src/test/java/it/unibo/arces/wot/sepa/Subscriber.java index 6ba31180..8f86e728 100644 --- a/client-api/src/test/java/it/unibo/arces/wot/sepa/Subscriber.java +++ b/client-api/src/test/java/it/unibo/arces/wot/sepa/Subscriber.java @@ -11,6 +11,7 @@ import it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException; import it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException; import it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException; +import it.unibo.arces.wot.sepa.commons.properties.SubscriptionProtocolProperties; import it.unibo.arces.wot.sepa.commons.response.ErrorResponse; import it.unibo.arces.wot.sepa.commons.response.Notification; import it.unibo.arces.wot.sepa.logging.Logging; @@ -31,8 +32,8 @@ public Subscriber(ConfigurationProvider provider, String id, ISubscriptionHandle this.id = id; this.handler = sync; - protocol = new WebsocketSubscriptionProtocol(provider.getJsap().getSubscribeHost(), - provider.getJsap().getSubscribePort(), provider.getJsap().getSubscribePath(), this, provider.getClientSecurityManager()); + SubscriptionProtocolProperties properties = provider.getJsap().getSubscribeProtocol(); + protocol = new WebsocketSubscriptionProtocol(provider.getJsap().getSubscribeHost(),properties,this,null); client = new SPARQL11SEProtocol(protocol); } diff --git a/client-api/src/test/java/it/unibo/arces/wot/sepa/api/ITSPARQL11SEProtocol.java b/client-api/src/test/java/it/unibo/arces/wot/sepa/api/ITSPARQL11SEProtocol.java index 0dc97c7c..a74a6640 100644 --- a/client-api/src/test/java/it/unibo/arces/wot/sepa/api/ITSPARQL11SEProtocol.java +++ b/client-api/src/test/java/it/unibo/arces/wot/sepa/api/ITSPARQL11SEProtocol.java @@ -6,7 +6,7 @@ import it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException; import it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException; import it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException; - +import it.unibo.arces.wot.sepa.commons.properties.SubscriptionProtocolProperties; import it.unibo.arces.wot.sepa.commons.response.QueryResponse; import it.unibo.arces.wot.sepa.commons.response.Response; import it.unibo.arces.wot.sepa.commons.sparql.Bindings; @@ -38,9 +38,8 @@ public void beginTest() throws IOException, SEPAProtocolException, SEPAPropertie handler = new Sync(); - protocol = new WebsocketSubscriptionProtocol(provider.getJsap().getSubscribeHost(), - provider.getJsap().getSubscribePort(), provider.getJsap().getSubscribePath(),handler, - provider.getClientSecurityManager()); + SubscriptionProtocolProperties properties = provider.getJsap().getSubscribeProtocol(); + protocol = new WebsocketSubscriptionProtocol(provider.getJsap().getSubscribeHost(),properties,handler,provider.getClientSecurityManager()); client = new SPARQL11SEProtocol(protocol,provider.getClientSecurityManager()); diff --git a/client-api/src/test/java/it/unibo/arces/wot/sepa/api/protocol/websocket/ITWebSocketSubscriptionProtocol.java b/client-api/src/test/java/it/unibo/arces/wot/sepa/api/protocol/websocket/ITWebSocketSubscriptionProtocol.java index bad1a0f2..029ac586 100644 --- a/client-api/src/test/java/it/unibo/arces/wot/sepa/api/protocol/websocket/ITWebSocketSubscriptionProtocol.java +++ b/client-api/src/test/java/it/unibo/arces/wot/sepa/api/protocol/websocket/ITWebSocketSubscriptionProtocol.java @@ -17,6 +17,7 @@ import it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException; import it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException; import it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException; +import it.unibo.arces.wot.sepa.commons.properties.SubscriptionProtocolProperties; import it.unibo.arces.wot.sepa.commons.response.ErrorResponse; import it.unibo.arces.wot.sepa.commons.response.Notification; @@ -53,7 +54,10 @@ public void after() throws IOException, SEPAProtocolException, SEPASecurityExcep @RepeatedTest(ConfigurationProvider.REPEATED_TEST) @Timeout(5) public void Subscribe() throws SEPAPropertiesException, SEPASecurityException, SEPAProtocolException, IOException, InterruptedException { - WebsocketSubscriptionProtocol client = new WebsocketSubscriptionProtocol(provider.getJsap().getSubscribeHost(), provider.getJsap().getSubscribePort(), provider.getJsap().getSubscribePath(), this, provider.getClientSecurityManager()); + + SubscriptionProtocolProperties properties = provider.getJsap().getSubscribeProtocol(); + WebsocketSubscriptionProtocol client = new WebsocketSubscriptionProtocol(provider.getJsap().getSubscribeHost(),properties,this,provider.getClientSecurityManager()); + client.subscribe(provider.buildSubscribeRequest("ALL")); synchronized (mutex) { @@ -67,7 +71,9 @@ public void Subscribe() throws SEPAPropertiesException, SEPASecurityException, S @Timeout(10) public void SubscribeAndResults() throws SEPASecurityException, SEPAPropertiesException, SEPAProtocolException, IOException, InterruptedException { - WebsocketSubscriptionProtocol client = new WebsocketSubscriptionProtocol(provider.getJsap().getSubscribeHost(), provider.getJsap().getSubscribePort(), provider.getJsap().getSubscribePath(), this, provider.getClientSecurityManager()); + SubscriptionProtocolProperties properties = provider.getJsap().getSubscribeProtocol(); + WebsocketSubscriptionProtocol client = new WebsocketSubscriptionProtocol(provider.getJsap().getSubscribeHost(),properties,this,provider.getClientSecurityManager()); + client.subscribe(provider.buildSubscribeRequest("ALL")); synchronized (mutex) { @@ -85,7 +91,9 @@ public void SubscribeAndResults() throws SEPASecurityException, SEPAPropertiesEx @Timeout(5) public void SubscribeAndUnsubscribe() throws SEPASecurityException, SEPAPropertiesException, SEPAProtocolException, IOException, InterruptedException { - WebsocketSubscriptionProtocol client = new WebsocketSubscriptionProtocol(provider.getJsap().getSubscribeHost(), provider.getJsap().getSubscribePort(), provider.getJsap().getSubscribePath(), this, provider.getClientSecurityManager()); + SubscriptionProtocolProperties properties = provider.getJsap().getSubscribeProtocol(); + WebsocketSubscriptionProtocol client = new WebsocketSubscriptionProtocol(provider.getJsap().getSubscribeHost(),properties,this,provider.getClientSecurityManager()); + client.subscribe(provider.buildSubscribeRequest("ALL")); synchronized (mutex) { @@ -106,7 +114,8 @@ public void SubscribeAndUnsubscribe() throws SEPASecurityException, SEPAProperti @Timeout(10) public void WrongSubscribe() throws SEPASecurityException, SEPAPropertiesException, SEPAProtocolException, IOException, InterruptedException { - WebsocketSubscriptionProtocol client = new WebsocketSubscriptionProtocol(provider.getJsap().getSubscribeHost(), provider.getJsap().getSubscribePort(), provider.getJsap().getSubscribePath(), this, provider.getClientSecurityManager()); + SubscriptionProtocolProperties properties = provider.getJsap().getSubscribeProtocol(); + WebsocketSubscriptionProtocol client = new WebsocketSubscriptionProtocol(provider.getJsap().getSubscribeHost(),properties,this,provider.getClientSecurityManager()); client.subscribe(provider.buildSubscribeRequest("WRONG")); diff --git a/engine/src/main/java/it/unibo/arces/wot/sepa/engine/core/EngineProperties.java b/engine/src/main/java/it/unibo/arces/wot/sepa/engine/core/EngineProperties.java index 8d0d1edb..3320c651 100644 --- a/engine/src/main/java/it/unibo/arces/wot/sepa/engine/core/EngineProperties.java +++ b/engine/src/main/java/it/unibo/arces/wot/sepa/engine/core/EngineProperties.java @@ -21,6 +21,7 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; +import java.net.URI; import java.util.Map; import java.util.Optional; import java.util.regex.PatternSyntaxException; @@ -309,7 +310,7 @@ public EngineProperties(String[] args) throws SEPASecurityException { } try { - endpointProperties = new SPARQL11Properties(endpointJpar); + endpointProperties = new SPARQL11Properties(URI.create(endpointJpar)); } catch (SEPAPropertiesException e) { Logging.logger.fatal("Endpoint configuration file not found: "+endpointJpar); System.exit(-1);