use of it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException 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);
}
use of it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException 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;
}
use of it.unibo.arces.wot.sepa.commons.exceptions.SEPAProtocolException in project SEPA by arces-wot.
the class SPUManager method subscribe.
public Response subscribe(SubscribeRequest req, EventHandler handler) {
logger.debug(req.toString());
SPUManagerBeans.subscribeRequest();
// TODO: choose different kinds of SPU based on subscribe request
SPU spu = null;
try {
spu = new SPUNaive(req, handler, endpointProperties, endpointSemaphore, processingSpus);
// spu.addObserver(this);
} catch (SEPAProtocolException e) {
logger.debug("SPU creation failed: " + e.getMessage());
return new ErrorResponse(req.getToken(), 500, "SPU creation failed: " + req.toString());
}
logger.debug("SPU init");
if (!spu.init()) {
logger.debug("SPU initialization failed");
return new ErrorResponse(req.getToken(), 500, "SPU initialization failed: " + req.toString());
}
synchronized (subscribeQueue) {
logger.debug("Add SPU to activation queue");
subscribeQueue.offer(spu);
subscribeQueue.notify();
}
return new SubscribeResponse(req.getToken(), spu.getUUID(), req.getAlias(), spu.getFirstResults());
}
Aggregations