use of it.unibo.arces.wot.sepa.api.protocols.websocket.WebsocketSubscriptionProtocol in project SEPA by arces-wot.
the class ITSPARQL11SEProtocol method beginTest.
@BeforeEach
public void beginTest() throws IOException, SEPAProtocolException, SEPAPropertiesException, SEPASecurityException, URISyntaxException, InterruptedException {
provider = new ConfigurationProvider();
handler = new Sync();
protocol = new WebsocketSubscriptionProtocol(provider.getJsap().getSubscribeHost(), provider.getJsap().getSubscribePort(), provider.getJsap().getSubscribePath(), handler, provider.getClientSecurityManager());
client = new SPARQL11SEProtocol(protocol, provider.getClientSecurityManager());
Response ret = client.update(provider.buildUpdateRequest("DELETE_ALL"));
assertFalse(ret.isError(), String.valueOf(ret));
}
use of it.unibo.arces.wot.sepa.api.protocols.websocket.WebsocketSubscriptionProtocol in project SEPA by arces-wot.
the class Consumer method onBrokenConnection.
@Override
public void onBrokenConnection(ErrorResponse errorResponse) {
logger.warn("onBrokenConnection");
subscribed = false;
// Auto reconnection mechanism
if (appProfile.reconnect()) {
try {
protocol = new WebsocketSubscriptionProtocol(appProfile.getSubscribeHost(subID), appProfile.getSubscribePort(subID), appProfile.getSubscribePath(subID), this, sm);
client = new SPARQL11SEProtocol(protocol, sm);
} catch (SEPASecurityException | SEPAProtocolException e1) {
logger.error(e1.getMessage());
return;
}
while (!subscribed) {
try {
subscribe(TIMEOUT, NRETRY);
} catch (SEPASecurityException | SEPAPropertiesException | SEPAProtocolException | SEPABindingsException e) {
logger.error(e.getMessage());
if (logger.isTraceEnabled())
e.printStackTrace();
}
try {
synchronized (client) {
client.wait(TIMEOUT);
}
} catch (InterruptedException e) {
logger.error(e.getMessage());
if (logger.isTraceEnabled())
e.printStackTrace();
}
}
}
}
use of it.unibo.arces.wot.sepa.api.protocols.websocket.WebsocketSubscriptionProtocol in project SEPA by arces-wot.
the class ITWebSocketSubscriptionProtocol method Subscribe.
@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());
client.subscribe(provider.buildSubscribeRequest("ALL"));
synchronized (mutex) {
while (ITWebSocketSubscriptionProtocol.spuid == null) mutex.wait();
}
client.close();
}
use of it.unibo.arces.wot.sepa.api.protocols.websocket.WebsocketSubscriptionProtocol in project SEPA by arces-wot.
the class GenericClient method _subscribe.
/**
* Subscribe.
*
* @param ID the identifier of the subscribe within the JSAP
* @param sparql if specified it replaces the default SPARQL in the JSAP
* @param forced the forced
* @param handler the handler
* @param timeout the timeout
* @throws SEPAProtocolException the SEPA protocol exception
* @throws SEPASecurityException the SEPA security exception
* @throws IOException Signals that an I/O exception has occurred.
* @throws SEPAPropertiesException the SEPA properties exception
* @throws URISyntaxException the URI syntax exception
* @throws SEPABindingsException the SEPA bindings exception
* @throws InterruptedException
*/
private void _subscribe(String ID, String sparql, Bindings forced, String alias, long timeout, long nRretry) throws SEPAProtocolException, SEPASecurityException, SEPAPropertiesException, SEPABindingsException, InterruptedException {
if (sparql == null)
sparql = appProfile.getSPARQLQuery(ID);
if (sparql == null)
throw new SEPAProtocolException("SPARQL query not found " + ID);
synchronized (subLock) {
if (req != null)
subLock.wait();
if (appProfile.getSubscribeProtocol(ID).equals(SPARQL11SEProperties.SubscriptionProtocol.WS)) {
url = "ws_" + appProfile.getSubscribeHost(ID) + "_" + appProfile.getSubscribePort(ID) + "_" + appProfile.getSubscribePath(ID);
} else {
url = "wss_" + appProfile.getSubscribeHost(ID) + "_" + appProfile.getSubscribePort(ID) + "_" + appProfile.getSubscribePath(ID);
}
if (activeClients.containsKey(url)) {
subscription = activeClients.get(url);
} else {
protocol = new WebsocketSubscriptionProtocol(appProfile.getSubscribeHost(ID), appProfile.getSubscribePort(ID), appProfile.getSubscribePath(ID), this, sm);
subscription = new SPARQL11SEProtocol(protocol);
}
req = new SubscribeRequest(appProfile.addPrefixesAndReplaceBindings(sparql, addDefaultDatatype(forced, ID, true)), alias, appProfile.getDefaultGraphURI(ID), appProfile.getNamedGraphURI(ID), (appProfile.isSecure() ? appProfile.getAuthenticationProperties().getBearerAuthorizationHeader() : null), timeout, nRretry);
subscription.subscribe((SubscribeRequest) req);
}
}
use of it.unibo.arces.wot.sepa.api.protocols.websocket.WebsocketSubscriptionProtocol in project SEPA by arces-wot.
the class ITWebSocketSubscriptionProtocol method SubscribeAndUnsubscribe.
@RepeatedTest(ConfigurationProvider.REPEATED_TEST)
@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());
client.subscribe(provider.buildSubscribeRequest("ALL"));
synchronized (mutex) {
while (ITWebSocketSubscriptionProtocol.spuid == null) mutex.wait();
}
client.unsubscribe(provider.buildUnsubscribeRequest(ITWebSocketSubscriptionProtocol.spuid));
synchronized (mutex) {
while (ITWebSocketSubscriptionProtocol.spuid != null) mutex.wait();
}
client.close();
}
Aggregations