Search in sources :

Example 1 with WebsocketSubscriptionProtocol

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));
}
Also used : Response(it.unibo.arces.wot.sepa.commons.response.Response) QueryResponse(it.unibo.arces.wot.sepa.commons.response.QueryResponse) ConfigurationProvider(it.unibo.arces.wot.sepa.ConfigurationProvider) WebsocketSubscriptionProtocol(it.unibo.arces.wot.sepa.api.protocols.websocket.WebsocketSubscriptionProtocol) Sync(it.unibo.arces.wot.sepa.Sync) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with WebsocketSubscriptionProtocol

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();
            }
        }
    }
}
Also used : SPARQL11SEProtocol(it.unibo.arces.wot.sepa.api.SPARQL11SEProtocol) SEPAProtocolException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException) SEPABindingsException(it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) WebsocketSubscriptionProtocol(it.unibo.arces.wot.sepa.api.protocols.websocket.WebsocketSubscriptionProtocol)

Example 3 with WebsocketSubscriptionProtocol

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();
}
Also used : WebsocketSubscriptionProtocol(it.unibo.arces.wot.sepa.api.protocols.websocket.WebsocketSubscriptionProtocol) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Timeout(org.junit.jupiter.api.Timeout)

Example 4 with WebsocketSubscriptionProtocol

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);
    }
}
Also used : SPARQL11SEProtocol(it.unibo.arces.wot.sepa.api.SPARQL11SEProtocol) SEPAProtocolException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException) SubscribeRequest(it.unibo.arces.wot.sepa.commons.request.SubscribeRequest) WebsocketSubscriptionProtocol(it.unibo.arces.wot.sepa.api.protocols.websocket.WebsocketSubscriptionProtocol)

Example 5 with WebsocketSubscriptionProtocol

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();
}
Also used : WebsocketSubscriptionProtocol(it.unibo.arces.wot.sepa.api.protocols.websocket.WebsocketSubscriptionProtocol) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

WebsocketSubscriptionProtocol (it.unibo.arces.wot.sepa.api.protocols.websocket.WebsocketSubscriptionProtocol)7 RepeatedTest (org.junit.jupiter.api.RepeatedTest)4 Timeout (org.junit.jupiter.api.Timeout)4 SPARQL11SEProtocol (it.unibo.arces.wot.sepa.api.SPARQL11SEProtocol)2 SEPAProtocolException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException)2 ConfigurationProvider (it.unibo.arces.wot.sepa.ConfigurationProvider)1 Sync (it.unibo.arces.wot.sepa.Sync)1 SEPABindingsException (it.unibo.arces.wot.sepa.commons.exceptions.SEPABindingsException)1 SEPAPropertiesException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException)1 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)1 SubscribeRequest (it.unibo.arces.wot.sepa.commons.request.SubscribeRequest)1 QueryResponse (it.unibo.arces.wot.sepa.commons.response.QueryResponse)1 Response (it.unibo.arces.wot.sepa.commons.response.Response)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1