use of org.openksavi.sponge.SpongeException in project sponge by softelnet.
the class BasePy4JPlugin method createSslContext.
protected SSLContext createSslContext() {
InputStream fis = null;
try {
char[] password = security.getPassword().toCharArray();
KeyStore ks = KeyStore.getInstance("JKS");
URL keystoreUrl = SpongeUtils.getUrlFromClasspath(security.getKeystore());
if (keystoreUrl == null) {
throw new SpongeException("Expected a '" + security.getKeystore() + "' keystore file on the classpath");
}
fis = keystoreUrl.openStream();
ks.load(fis, password);
// Setup the key manager factory.
KeyManagerFactory kmf = KeyManagerFactory.getInstance(security.getAlgorithm());
kmf.init(ks, password);
// Setup the trust manager factory.
TrustManagerFactory tmf = TrustManagerFactory.getInstance(security.getAlgorithm());
tmf.init(ks);
SSLContext sslContext = SSLContext.getInstance("TLS");
// Setup the HTTPS context and parameters.
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
return sslContext;
} catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException | UnrecoverableKeyException | KeyManagementException e) {
throw SpongeUtils.wrapException(e);
} finally {
SpongeUtils.close(fis);
}
}
use of org.openksavi.sponge.SpongeException in project sponge by softelnet.
the class MidiPlugin method connectDefaultInputDevice.
/**
* Sets and updates the default input MIDI device in the plugin. If there has already been connected an another input device then
* replaces it.
*/
public void connectDefaultInputDevice() {
MidiDevice device = MidiUtils.getDefaultInputDevice();
if (device == null) {
throw new SpongeException("No default input MIDI device found");
}
setInputDevice(device);
updateInputDevice();
}
use of org.openksavi.sponge.SpongeException in project sponge by softelnet.
the class EventsTestTemplate method testCron.
public static void testCron(KnowledgeBaseType type) {
SpongeEngine engine = ScriptTestUtils.startWithKnowledgeBase(type, "events_cron");
try {
await().atMost(30, TimeUnit.SECONDS).until(() -> engine.getOperations().getVariable(Number.class, "eventCounter").intValue() >= 2);
TimeUnit.SECONDS.sleep(5);
assertEquals(2, engine.getOperations().getVariable(Number.class, "eventCounter").intValue());
assertFalse(engine.isError());
} catch (InterruptedException ie) {
throw new SpongeException(ie);
} finally {
engine.shutdown();
}
}
use of org.openksavi.sponge.SpongeException in project sponge by softelnet.
the class TriggersTestTemplate method testTriggersEventPatternIncorrect.
public static void testTriggersEventPatternIncorrect(KnowledgeBaseType type) {
SpongeEngine engine = null;
try {
engine = ScriptTestUtils.startWithKnowledgeBase(type, "triggers_event_pattern_incorrect");
fail("Expected pattern syntax exception");
} catch (SpongeException e) {
if (ExceptionUtils.indexOfThrowable(e, PatternSyntaxException.class) < 0) {
throw e;
}
} finally {
if (engine != null) {
engine.shutdown();
}
}
}
use of org.openksavi.sponge.SpongeException in project sponge by softelnet.
the class StandaloneErrorReportingTest method testErrorReporting.
protected void testErrorReporting(String name, KnowledgeBaseType type) {
StandaloneEngineMain engineMain = null;
try {
List<String> args = new ArrayList<>();
args.add("-k");
args.add("examples/standalone/" + name + "/" + name + "." + type.getFileExtensions().get(0));
engineMain = StandaloneTestUtils.startupStandaloneEngineMain(args.toArray(new String[args.size()]));
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!engineMain.getEngine().isError()) {
Assert.fail("Expected exception");
}
} catch (SpongeException e) {
// Ignore expected exception.
} finally {
StandaloneTestUtils.shutdownStandaloneEngineMain(engineMain);
}
}
Aggregations