Search in sources :

Example 6 with ConfigurationException

use of org.jpos.core.ConfigurationException in project jPOS by jpos.

the class SpaceLogListener method setConfiguration.

/**
 * @param cfg Configuration object
 * @throws ConfigurationException
 */
@Override
public void setConfiguration(Configuration cfg) throws ConfigurationException {
    this.cfg = cfg;
    queueName = cfg.get("queue", null);
    if (queueName == null)
        throw new ConfigurationException("'queue' property not configured");
    timeout = cfg.getLong("timeout", timeout);
    frozen = cfg.getBoolean("frozen", true);
}
Also used : ConfigurationException(org.jpos.core.ConfigurationException)

Example 7 with ConfigurationException

use of org.jpos.core.ConfigurationException in project jPOS by jpos.

the class FilterLogListenerTest method testSetConfigurationThrowsConfigurationException.

@Test
public void testSetConfigurationThrowsConfigurationException() throws Throwable {
    FilterLogListener filterLogListener = new FilterLogListener(new PrintStream(new ByteArrayOutputStream()));
    Configuration cfg = new SubConfiguration();
    try {
        filterLogListener.setConfiguration(cfg);
        fail("Expected ConfigurationException to be thrown");
    } catch (ConfigurationException ex) {
        assertEquals("ex.getMessage()", "java.lang.NullPointerException", ex.getMessage());
        assertNull("ex.getNested().getMessage()", ex.getNested().getMessage());
        assertEquals("filterLogListener.getPriority()", "info", filterLogListener.getPriority());
    }
}
Also used : PrintStream(java.io.PrintStream) SubConfiguration(org.jpos.core.SubConfiguration) SimpleConfiguration(org.jpos.core.SimpleConfiguration) Configuration(org.jpos.core.Configuration) ConfigurationException(org.jpos.core.ConfigurationException) SubConfiguration(org.jpos.core.SubConfiguration) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 8 with ConfigurationException

use of org.jpos.core.ConfigurationException in project jPOS by jpos.

the class SimpleKeyFileTest method testSetConfigurationThrowsConfigurationException.

@Test
public void testSetConfigurationThrowsConfigurationException() throws Throwable {
    SimpleKeyFile simpleKeyFile = new SimpleKeyFile();
    Configuration cfg = new SimpleConfiguration(new Properties());
    try {
        simpleKeyFile.setConfiguration(cfg);
        fail("Expected ConfigurationException to be thrown");
    } catch (ConfigurationException ex) {
        assertEquals("simpleKeyFile.file.getName()", "", simpleKeyFile.file.getName());
        assertEquals("simpleKeyFile.header", "Key File", simpleKeyFile.header);
        assertEquals("simpleKeyFile.props.size()", 0, simpleKeyFile.props.size());
    }
}
Also used : Configuration(org.jpos.core.Configuration) SimpleConfiguration(org.jpos.core.SimpleConfiguration) ConfigurationException(org.jpos.core.ConfigurationException) SimpleConfiguration(org.jpos.core.SimpleConfiguration) Properties(java.util.Properties) Test(org.junit.Test)

Example 9 with ConfigurationException

use of org.jpos.core.ConfigurationException in project jPOS by jpos.

the class GenericPackager method setConfiguration.

/**
 * Packager Configuration.
 *
 * <ul>
 *  <li>packager-config
 *  <li>packager-logger
 *  <li>packager-realm
 * </ul>
 *
 * @param cfg Configuration
 */
public void setConfiguration(Configuration cfg) throws ConfigurationException {
    filename = cfg.get("packager-config", null);
    if (filename == null)
        throw new ConfigurationException("packager-config property cannot be null");
    try {
        String loggerName = cfg.get("packager-logger");
        if (loggerName != null)
            setLogger(Logger.getLogger(loggerName), cfg.get("packager-realm"));
        readFile(filename);
    } catch (ISOException e) {
        throw new ConfigurationException(e.getMessage(), e.fillInStackTrace());
    }
}
Also used : ISOException(org.jpos.iso.ISOException) ConfigurationException(org.jpos.core.ConfigurationException)

Example 10 with ConfigurationException

use of org.jpos.core.ConfigurationException in project jPOS by jpos.

the class QFactory method invoke.

/**
 * Try to invoke a method (usually a setter) on the given object
 * silently ignoring if method does not exist
 * @param obj the object
 * @param m method to invoke
 * @param p parameter
 * @param pc parameter class
 * @throws ConfigurationException if method happens to throw an exception
 */
@SuppressWarnings("PMD.EmptyCatchBlock")
public static void invoke(Object obj, String m, Object p, Class pc) throws ConfigurationException {
    try {
        if (p != null) {
            Class[] paramTemplate = { pc };
            Method method = obj.getClass().getMethod(m, paramTemplate);
            Object[] param = new Object[1];
            param[0] = p;
            method.invoke(obj, param);
        } else {
            Method method = obj.getClass().getMethod(m);
            method.invoke(obj);
        }
    } catch (NoSuchMethodException ignored) {
    } catch (NullPointerException ignored) {
    } catch (IllegalAccessException ignored) {
    } catch (InvocationTargetException e) {
        throw new ConfigurationException(obj.getClass().getName() + "." + m + "(" + p + ")", e.getTargetException());
    }
}
Also used : ConfigurationException(org.jpos.core.ConfigurationException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ConfigurationException (org.jpos.core.ConfigurationException)52 Element (org.jdom2.Element)10 SimpleConfiguration (org.jpos.core.SimpleConfiguration)10 Test (org.junit.Test)9 Configuration (org.jpos.core.Configuration)8 Configurable (org.jpos.core.Configurable)5 SubConfiguration (org.jpos.core.SubConfiguration)5 NameRegistrar (org.jpos.util.NameRegistrar)4 IOException (java.io.IOException)3 Date (java.util.Date)3 Properties (java.util.Properties)3 LogSource (org.jpos.util.LogSource)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 StringTokenizer (java.util.StringTokenizer)2 Timer (java.util.Timer)2 ISOException (org.jpos.iso.ISOException)2 Logger (org.jpos.util.Logger)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1