Search in sources :

Example 1 with SEPAPropertiesException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException in project SEPA by arces-wot.

the class SPARQL11Properties method storeProperties.

/**
 * Store properties.
 *
 * @param propertiesFile
 *            the properties file
 * @throws SEPAPropertiesException
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
protected void storeProperties(String propertiesFile) throws SEPAPropertiesException {
    FileWriter out;
    try {
        out = new FileWriter(propertiesFile);
        out.write(doc.toString());
        out.close();
    } catch (Exception e) {
        throw new SEPAPropertiesException(e);
    }
}
Also used : SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException)

Example 2 with SEPAPropertiesException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException in project SEPA by arces-wot.

the class SEPATest method main.

public static void main(String[] args) {
    boolean ret = false;
    try {
        properties = new SPARQL11SEProperties("client.jpar");
    } catch (SEPAPropertiesException e2) {
        logger.fatal("JSAP exception: " + e2.getMessage());
        System.exit(1);
    }
    try {
        client = new SPARQL11SEProtocol(properties, handler);
    } catch (SEPAProtocolException e2) {
        logger.fatal(e2.getLocalizedMessage());
        System.exit(1);
    }
    logger.warn("**********************************************************");
    logger.warn("***     SPARQL 1.1 SE Protocol Service test suite      ***");
    logger.warn("**********************************************************");
    logger.warn("***   WARNING: the RDF store content will be ERASED    ***");
    logger.warn("***         Do you want to continue (yes/no)?          ***");
    logger.warn("**********************************************************");
    logger.warn("SPARQL 1.1 SE Protocol Service parameters: " + client.toString());
    Scanner scanner = new Scanner(System.in);
    // "\\z" means end of input
    scanner.useDelimiter("\\n");
    String input = scanner.next();
    if (!input.equals("yes")) {
        scanner.close();
        logger.info("Bye bye! :-)");
        System.exit(0);
    }
    logger.warn("**********************************************************");
    logger.warn("***                Are you sure (yes/no)?              ***");
    logger.warn("**********************************************************");
    input = scanner.next();
    if (!input.equals("yes")) {
        scanner.close();
        logger.info("Bye bye! :-)");
        System.exit(0);
    }
    scanner.close();
    // UPDATE
    ret = updateTest("prefix test:<http://www.vaimee.com/test#> delete {?s ?p ?o} insert {test:Sub test:Pred \"測試\"} where {?s ?p ?o}", false);
    results.addResult("Update", ret);
    if (ret)
        logger.info("Update PASSED");
    else
        logger.error("Update FAILED");
    // QUERY
    ret = queryTest("select ?o where {?s ?p ?o}", "測試", false);
    results.addResult("Query", ret);
    if (ret)
        logger.info("Query PASSED");
    else
        logger.error("Query FAILED");
    // SUBSCRIBE
    ret = subscribeTest("select ?o where {?s ?p ?o}", false);
    results.addResult("Subscribe - request", ret);
    if (ret)
        logger.info("Subscribe PASSED");
    else
        logger.error("Subscribe FAILED");
    // PING
    ret = waitPing();
    results.addResult("Subscribe - ping", ret);
    if (ret)
        logger.info("Ping received PASSED");
    else
        logger.error("Ping recevied FAILED");
    // TRIGGER A NOTIFICATION
    ret = updateTest("prefix test:<http://www.vaimee.com/test#> delete {?s ?p ?o} insert {test:Sub test:Pred \"ვაიმეე\"} where {?s ?p ?o}", false);
    results.addResult("Subscribe - triggering", ret);
    if (ret)
        logger.info("Triggering update PASSED");
    else
        logger.error("Triggering update FAILED");
    // WAIT NOTIFICATION
    ret = waitNotification();
    results.addResult("Subscribe - notification", ret);
    if (ret)
        logger.info("Notification PASSED");
    else
        logger.error("Notification FAILED");
    // UNSUBSCRIBE
    ret = unsubscribeTest(spuid, false);
    results.addResult("Unsubscribe - request", ret);
    if (ret)
        logger.info("Unsubscribe PASSED");
    else
        logger.error("Unsubscribe FAILED");
    // PING
    ret = !waitPing();
    results.addResult("Unsubscribe - ping", ret);
    if (ret)
        logger.info("Ping not received PASSED");
    else
        logger.error("Ping not recevied FAILED");
    // **********************
    // Enable security
    // **********************
    logger.debug("Switch to secure mode");
    // REGISTRATION (registration not allowed)
    ret = !registrationTest("RegisterMePlease");
    results.addResult("Registration not allowed", ret);
    if (ret)
        logger.info("Registration not allowed PASSED");
    else
        logger.error("Registration not allowed FAILED");
    // REGISTRATION
    ret = registrationTest("SEPATest");
    results.addResult("Registration", ret);
    if (ret)
        logger.info("Registration PASSED");
    else
        logger.error("Registration FAILED");
    // REQUEST ACCESS TOKEN
    ret = requestAccessTokenTest();
    results.addResult("Access token", ret);
    if (ret)
        logger.info("Access token PASSED");
    else
        logger.error("Access token FAILED");
    // REQUEST ACCESS TOKEN (not expired);
    try {
        if (!properties.isTokenExpired())
            ret = !requestAccessTokenTest();
        else
            ret = false;
    } catch (SEPASecurityException e2) {
        logger.error(e2.getMessage());
        ret = false;
    }
    results.addResult("Access token not expired", ret);
    if (ret)
        logger.info("Access token (not expired) PASSED");
    else
        logger.error("Access token (not expired) FAILED");
    // REQUEST ACCESS TOKEN (expired);
    try {
        logger.debug("Waiting token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e2) {
        logger.error(e2.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    try {
        if (properties.isTokenExpired())
            ret = requestAccessTokenTest();
        else
            ret = false;
    } catch (SEPASecurityException e2) {
        logger.error(e2.getMessage());
        ret = false;
    }
    results.addResult("Access token expired", ret);
    if (ret)
        logger.info("Access token (expired) PASSED");
    else
        logger.error("Access token (expired) FAILED");
    // SECURE UPDATE
    try {
        logger.debug("Waiting token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e2) {
        logger.error(e2.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    try {
        if (properties.isTokenExpired())
            requestAccessTokenTest();
    } catch (SEPASecurityException e13) {
        logger.error(e13.getMessage());
    }
    ret = updateTest("prefix test:<http://wot.arces.unibo.it/test#> delete {?s ?p ?o} insert {test:Sub test:Pred \"ვაიმეე\"} where {?s ?p ?o}", true);
    results.addResult("Secure update ", ret);
    if (ret)
        logger.info("Secure update PASSED");
    else
        logger.error("Secure update FAILED");
    // SECURE UPDATE (expired token)
    try {
        logger.debug("Waiting token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e12) {
        logger.error(e12.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    ret = !updateTest("prefix test:<http://wot.arces.unibo.it/test#> delete {?s ?p ?o} insert {test:Sub test:Pred \"vaimee!\"} where {?s ?p ?o}", true);
    results.addResult("Secure update (expired)", ret);
    if (ret)
        logger.info("Secure update (expired) PASSED");
    else
        logger.error("Secure update (expired) FAILED");
    // SECURE QUERY
    try {
        logger.debug("Waiting token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e11) {
        logger.error(e11.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    try {
        if (properties.isTokenExpired())
            requestAccessTokenTest();
    } catch (SEPASecurityException e10) {
        logger.error(e10.getMessage());
    }
    ret = queryTest("select ?o where {?s ?p ?o}", "ვაიმეე", true);
    results.addResult("Secure query", ret);
    if (ret)
        logger.info("Secure query PASSED");
    else
        logger.error("Secure query FAILED");
    // SECURE QUERY (expired token)
    try {
        logger.debug("Waiting token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e9) {
        logger.error(e9.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    ret = !queryTest("select ?o where {?s ?p ?o}", "ვაიმეე", true);
    results.addResult("Secure query (expired)", ret);
    if (ret)
        logger.info("Secure query (expired) PASSED");
    else
        logger.error("Secure query (expired) FAILED");
    // SECURE SUBSCRIBE
    try {
        logger.debug("Waiting token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e8) {
        logger.error(e8.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    try {
        if (properties.isTokenExpired())
            requestAccessTokenTest();
    } catch (SEPASecurityException e7) {
        logger.error(e7.getMessage());
    }
    ret = subscribeTest("select ?o where {?s ?p ?o}", true);
    results.addResult("Secure subscribe - request", ret);
    if (ret)
        logger.info("Secure subscribe PASSED");
    else
        logger.error("Secure subscribe FAILED");
    // PING
    ret = waitPing();
    results.addResult("Secure subscribe - ping", ret);
    if (ret)
        logger.info("Secure ping received PASSED");
    else
        logger.error("Secure ping recevied FAILED");
    // TRIGGER A NOTIFICATION
    try {
        logger.debug("Waiting token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e6) {
        logger.error(e6.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    try {
        if (properties.isTokenExpired())
            requestAccessTokenTest();
    } catch (SEPASecurityException e5) {
        logger.error(e5.getMessage());
    }
    ret = updateTest("prefix test:<http://wot.arces.unibo.it/test#> delete {?s ?p ?o} insert {test:Sub test:Pred \"卢卡\"} where {?s ?p ?o}", true);
    results.addResult("Secure subscribe - triggering", ret);
    if (ret)
        logger.info("Secure triggering update PASSED");
    else
        logger.error("Secure triggering update FAILED");
    // NOTIFICATION
    ret = waitNotification();
    results.addResult("Secure subscribe - notification", ret);
    if (ret)
        logger.info("Secure subscribe - notification PASSED");
    else
        logger.error("Secure subscribe - notification FAILED");
    // SECURE UNSUBSCRIBE (expired)
    try {
        logger.debug("Wait token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e4) {
        logger.error(e4.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    ret = !unsubscribeTest(spuid, true);
    results.addResult("Secure unsubscribe (expired) - request", ret);
    if (ret)
        logger.info("Secure unsubscribe (expired) - request PASSED");
    else
        logger.error("Secure unsubscribe (expired) - request FAILED");
    // UNSUBSCRIBE
    try {
        logger.debug("Waiting token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e3) {
        logger.error(e3.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    try {
        if (properties.isTokenExpired())
            requestAccessTokenTest();
    } catch (SEPASecurityException e2) {
        logger.error(e2.getMessage());
    }
    ret = unsubscribeTest(spuid, true);
    results.addResult("Secure unsubscribe - request", ret);
    if (ret)
        logger.info("Secure unsubscribe - request PASSED");
    else
        logger.error("Secure unsubscribe - request FAILED");
    // WAITING PING
    ret = !waitPing();
    results.addResult("Secure unsubscribe - ping", ret);
    if (ret)
        logger.info("Secure unsubscribe - ping PASSED");
    else
        logger.error("Secure unsubscribe - ping FAILED");
    // SECURE SUBSCRIBE (expired)
    try {
        logger.info("Wait token expiring in " + properties.getExpiringSeconds() + " + 2 seconds...");
    } catch (SEPASecurityException e1) {
        logger.error(e1.getMessage());
    }
    try {
        Thread.sleep((properties.getExpiringSeconds() + 2) * 1000);
    } catch (InterruptedException | SEPASecurityException e) {
        logger.error(e.getMessage());
    }
    ret = !subscribeTest("select ?o where {?s ?p ?o}", true);
    results.addResult("Secure subscribe (expired) - request", ret);
    if (ret)
        logger.info("Secure subscribe (expired) - request PASSED");
    else
        logger.error("Secure subscribe (expired) - request FAILED");
    results.print();
    System.exit(0);
}
Also used : SPARQL11SEProtocol(it.unibo.arces.wot.sepa.api.SPARQL11SEProtocol) SEPAProtocolException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException) Scanner(java.util.Scanner) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException) SPARQL11SEProperties(it.unibo.arces.wot.sepa.api.SPARQL11SEProperties) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)

Example 3 with SEPAPropertiesException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException in project SEPA by arces-wot.

the class Dashboard method loadSAP.

private boolean loadSAP(String file) {
    if (file == null) {
        FileInputStream in = null;
        try {
            in = new FileInputStream("dashboard.properties");
        } catch (FileNotFoundException e) {
            logger.warn(e.getMessage());
            lblInfo.setText("Error: " + e.getMessage());
            lblInfo.setToolTipText("Error: " + e.getMessage());
            frmSepaDashboard.setTitle(versionLabel + " - " + e.getMessage());
            return false;
        }
        // Properties sapFile = new Properties();
        try {
            appProperties.load(in);
        } catch (IOException e) {
            logger.error(e.getMessage());
            lblInfo.setText("Error: " + e.getMessage());
            lblInfo.setToolTipText("Error: " + e.getMessage());
            frmSepaDashboard.setTitle(versionLabel + " - " + e.getMessage());
            return false;
        }
        String path = appProperties.getProperty("appProfile");
        if (path == null) {
            lblInfo.setText("Error: path in dashboard.properties is null");
            lblInfo.setToolTipText("Error: path in dashboard.properties is null");
            frmSepaDashboard.setTitle(versionLabel + " - " + "path in dashboard.properties is null");
            return false;
        }
        file = path;
    }
    labelUrl.setText("---");
    labelHttpPort.setText("---");
    labelHttpsPort.setText("---");
    labelWsPort.setText("---");
    labelWssPort.setText("---");
    labelUpdatePath.setText("---");
    labelQueryPath.setText("---");
    labelSubscribePath.setText("---");
    labelSecurePath.setText("---");
    SPARQLSubscribe.setText("");
    SPARQLUpdate.setText("");
    namespacesDM.getDataVector().clear();
    updateListDM.clear();
    subscribeListDM.clear();
    updateForcedBindingsDM.clearBindings();
    subscribeForcedBindingsDM.clearBindings();
    updatesList.clearSelection();
    subscribesList.clearSelection();
    try {
        appProfile = new ApplicationProfile(file);
    } catch (SEPAPropertiesException e) {
        logger.error(e.getMessage());
        lblInfo.setText("Error: " + e.getMessage());
        lblInfo.setToolTipText("Error: " + e.getMessage());
        frmSepaDashboard.setTitle(versionLabel + " - " + e.getMessage());
        return false;
    }
    try {
        sepaClient = new SEPADashbooard(appProfile);
    } catch (SEPAProtocolException | SEPASecurityException e) {
        logger.error(e.getMessage());
        lblInfo.setText("Error: " + e.getMessage());
        lblInfo.setToolTipText("Error: " + e.getMessage());
        frmSepaDashboard.setTitle(versionLabel + " - " + e.getMessage());
        return false;
    }
    frmSepaDashboard.setTitle(versionLabel + " - " + file);
    // Loading namespaces
    for (String prefix : appProfile.getPrefixes()) {
        Vector<String> row = new Vector<String>();
        row.add(prefix);
        row.addElement(appProfile.getNamespaceURI(prefix));
        namespacesDM.addRow(row);
    }
    // Loading updates
    for (String update : appProfile.getUpdateIds()) {
        // updateListDM.addElement(update);
        updateListDM.add(update);
    }
    // Loading subscribes
    for (String subscribe : appProfile.getSubscribeIds()) {
        // subscribeListDM.addElement(subscribe);
        subscribeListDM.add(subscribe);
    }
    // Enable all the buttons
    btnUpdate.setEnabled(true);
    btnSubscribe.setEnabled(true);
    btnQuery.setEnabled(true);
    labelUrl.setText(appProfile.getHost());
    labelHttpPort.setText(String.format("%d", appProfile.getHttpPort()));
    labelHttpsPort.setText(String.format("%d", appProfile.getHttpsPort()));
    labelWsPort.setText(String.format("%d", appProfile.getWsPort()));
    labelWssPort.setText(String.format("%d", appProfile.getWssPort()));
    labelUpdatePath.setText(appProfile.getUpdatePath());
    labelQueryPath.setText(appProfile.getQueryPath());
    labelSubscribePath.setText(appProfile.getSubscribePath());
    labelSecurePath.setText(appProfile.getSecurePath());
    lblInfo.setText("JSAP loaded");
    lblInfo.setToolTipText("JSAP loaded");
    return true;
}
Also used : SEPAProtocolException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException) FileNotFoundException(java.io.FileNotFoundException) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) IOException(java.io.IOException) ApplicationProfile(it.unibo.arces.wot.sepa.pattern.ApplicationProfile) Vector(java.util.Vector) FileInputStream(java.io.FileInputStream)

Example 4 with SEPAPropertiesException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException in project SEPA by arces-wot.

the class EngineProperties method checkParameters.

protected void checkParameters() throws SEPAPropertiesException {
    try {
        properties.get("scheduler").getAsJsonObject().get("queueSize").getAsInt();
        properties.get("processor").getAsJsonObject().get("updateTimeout").getAsInt();
        properties.get("processor").getAsJsonObject().get("queryTimeout").getAsInt();
        properties.get("processor").getAsJsonObject().get("maxConcurrentRequests").getAsInt();
        properties.get("spu").getAsJsonObject().get("keepalive").getAsInt();
        properties.get("ports").getAsJsonObject().get("http").getAsInt();
        properties.get("ports").getAsJsonObject().get("https").getAsInt();
        properties.get("ports").getAsJsonObject().get("ws").getAsInt();
        properties.get("ports").getAsJsonObject().get("wss").getAsInt();
        properties.get("paths").getAsJsonObject().get("securePath").getAsString();
        properties.get("paths").getAsJsonObject().get("update").getAsString();
        properties.get("paths").getAsJsonObject().get("query").getAsString();
        properties.get("paths").getAsJsonObject().get("subscribe").getAsString();
        properties.get("paths").getAsJsonObject().get("register").getAsString();
        properties.get("paths").getAsJsonObject().get("tokenRequest").getAsString();
    } catch (Exception e) {
        throw new SEPAPropertiesException(e);
    }
}
Also used : SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException) IOException(java.io.IOException) NoSuchElementException(java.util.NoSuchElementException) FileNotFoundException(java.io.FileNotFoundException)

Example 5 with SEPAPropertiesException

use of it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException in project SEPA by arces-wot.

the class SPARQL11SEProperties method validate.

@Override
protected void validate() throws SEPAPropertiesException {
    super.validate();
    try {
        // parameters.get("ports").getAsJsonObject().get("https").getAsInt();
        // parameters.get("ports").getAsJsonObject().get("ws").getAsInt();
        // parameters.get("ports").getAsJsonObject().get("wss").getAsInt();
        parameters.get("paths").getAsJsonObject().get("subscribe").getAsString();
        parameters.get("paths").getAsJsonObject().get("register").getAsString();
        parameters.get("paths").getAsJsonObject().get("tokenRequest").getAsString();
        parameters.get("paths").getAsJsonObject().get("securePath").getAsString();
    } catch (Exception e) {
        throw new SEPAPropertiesException(e);
    }
}
Also used : SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException) SEPASecurityException(it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException) SEPAPropertiesException(it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException)

Aggregations

SEPAPropertiesException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAPropertiesException)8 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)4 JsonParser (com.google.gson.JsonParser)2 SEPAProtocolException (it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 SPARQL11SEProperties (it.unibo.arces.wot.sepa.api.SPARQL11SEProperties)1 SPARQL11SEProtocol (it.unibo.arces.wot.sepa.api.SPARQL11SEProtocol)1 ErrorResponse (it.unibo.arces.wot.sepa.commons.response.ErrorResponse)1 JWTResponse (it.unibo.arces.wot.sepa.commons.response.JWTResponse)1 QueryResponse (it.unibo.arces.wot.sepa.commons.response.QueryResponse)1 RegistrationResponse (it.unibo.arces.wot.sepa.commons.response.RegistrationResponse)1 UpdateResponse (it.unibo.arces.wot.sepa.commons.response.UpdateResponse)1 ApplicationProfile (it.unibo.arces.wot.sepa.pattern.ApplicationProfile)1 FileInputStream (java.io.FileInputStream)1 Date (java.util.Date)1 NoSuchElementException (java.util.NoSuchElementException)1 Scanner (java.util.Scanner)1