Search in sources :

Example 21 with SpongeException

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);
    }
}
Also used : SpongeException(org.openksavi.sponge.SpongeException) InputStream(java.io.InputStream) CertificateException(java.security.cert.CertificateException) SSLContext(javax.net.ssl.SSLContext) KeyStoreException(java.security.KeyStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) KeyStore(java.security.KeyStore) URL(java.net.URL) KeyManagementException(java.security.KeyManagementException) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) UnrecoverableKeyException(java.security.UnrecoverableKeyException) TrustManagerFactory(javax.net.ssl.TrustManagerFactory)

Example 22 with SpongeException

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();
}
Also used : SpongeException(org.openksavi.sponge.SpongeException) MidiDevice(javax.sound.midi.MidiDevice)

Example 23 with SpongeException

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();
    }
}
Also used : SpongeException(org.openksavi.sponge.SpongeException) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 24 with SpongeException

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();
        }
    }
}
Also used : SpongeException(org.openksavi.sponge.SpongeException) SpongeEngine(org.openksavi.sponge.engine.SpongeEngine)

Example 25 with SpongeException

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);
    }
}
Also used : StandaloneEngineMain(org.openksavi.sponge.standalone.StandaloneEngineMain) SpongeException(org.openksavi.sponge.SpongeException) ArrayList(java.util.ArrayList)

Aggregations

SpongeException (org.openksavi.sponge.SpongeException)25 SpongeEngine (org.openksavi.sponge.engine.SpongeEngine)4 EventMode (org.openksavi.sponge.rule.EventMode)4 ArrayList (java.util.ArrayList)3 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)3 TreeNode (org.openksavi.sponge.core.util.TreeNode)3 KnowledgeBaseType (org.openksavi.sponge.kb.KnowledgeBaseType)3 StringTokenizer (java.util.StringTokenizer)2 SpongeUtils (org.openksavi.sponge.core.util.SpongeUtils)2 KnowledgeBaseEngineOperations (org.openksavi.sponge.kb.KnowledgeBaseEngineOperations)2 KnowledgeBaseInterpreter (org.openksavi.sponge.kb.KnowledgeBaseInterpreter)2 KnowledgeBaseScript (org.openksavi.sponge.kb.KnowledgeBaseScript)2 Plugin (org.openksavi.sponge.plugin.Plugin)2 GroovyObject (groovy.lang.GroovyObject)1 MetaMethod (groovy.lang.MetaMethod)1 Script (groovy.lang.Script)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1