Search in sources :

Example 21 with ConfigurationException

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

the class ISORequestListenerAdaptor method setConfiguration.

public void setConfiguration(Configuration cfg) throws ConfigurationException {
    this.cfg = cfg;
    try {
        mux = (SpaceMUX) NameRegistrar.get(cfg.get("mux"));
    } catch (NotFoundException e) {
        throw new ConfigurationException(e);
    }
    timeout = cfg.getLong("timeout", 120000);
    pool = new ThreadPool(1, cfg.getInt("pool", 100));
}
Also used : ConfigurationException(org.jpos.core.ConfigurationException) NotFoundException(org.jpos.util.NameRegistrar.NotFoundException)

Example 22 with ConfigurationException

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

the class TransactionManagerTest method testInitServiceThrowsConfigurationException.

@Test
public void testInitServiceThrowsConfigurationException() throws Throwable {
    Configuration cfg = new SimpleConfiguration();
    transactionManager.setConfiguration(cfg);
    try {
        transactionManager.initService();
        fail("Expected ConfigurationException to be thrown");
    } catch (ConfigurationException ex) {
        assertEquals("ex.getMessage()", "queue property not specified", ex.getMessage());
        assertNull("ex.getNested()", ex.getNested());
        assertNull("transactionManager.queue", transactionManager.queue);
        assertSame("transactionManager.getConfiguration()", cfg, transactionManager.getConfiguration());
        assertEquals("transactionManager.tail", 0L, transactionManager.tail);
        assertTrue("transactionManager.isModified()", transactionManager.isModified());
        assertNull("transactionManager.sp", transactionManager.sp);
        assertNull("transactionManager.psp", transactionManager.psp);
        assertEquals("transactionManager.head", 0L, transactionManager.head);
        assertNull("transactionManager.groups", transactionManager.groups);
        assertNull("transactionManager.tailLock", transactionManager.tailLock);
    }
}
Also used : SimpleConfiguration(org.jpos.core.SimpleConfiguration) Configuration(org.jpos.core.Configuration) SubConfiguration(org.jpos.core.SubConfiguration) ConfigurationException(org.jpos.core.ConfigurationException) SimpleConfiguration(org.jpos.core.SimpleConfiguration) Test(org.junit.Test)

Example 23 with ConfigurationException

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

the class ConnectionPool method initJDBC.

private void initJDBC() throws ConfigurationException {
    try {
        Class.forName(cfg.get("jdbc.driver")).newInstance();
    } catch (Exception e) {
        throw new ConfigurationException(e);
    }
    driver = cfg.get("jdbc.driver");
    url = cfg.get("jdbc.url");
    username = cfg.get("jdbc.user");
    password = cfg.get("jdbc.password");
    int initialConnections = cfg.getInt("initial-connections");
    maxConnections = cfg.getInt("max-connections");
    waitIfBusy = cfg.getBoolean("wait-if-busy");
    if (initialConnections > maxConnections) {
        initialConnections = maxConnections;
    }
    availableConnections = new Vector(initialConnections);
    busyConnections = new Vector();
    for (int i = 0; i < initialConnections; i++) {
        try {
            availableConnections.addElement(makeNewConnection());
        } catch (SQLException e) {
            throw new ConfigurationException(e);
        }
    }
}
Also used : ConfigurationException(org.jpos.core.ConfigurationException) SQLException(java.sql.SQLException) Vector(java.util.Vector) SQLException(java.sql.SQLException) ConfigurationException(org.jpos.core.ConfigurationException)

Example 24 with ConfigurationException

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

the class SchedulingTaskAdaptor method setConfiguration.

public void setConfiguration(org.jpos.core.Configuration cfg) throws org.jpos.core.ConfigurationException {
    super.setConfiguration(cfg);
    boolean daemon = cfg.getBoolean("daemon", true);
    if (daemon) {
        timer = new Timer(true);
    }
    // By default execute task every 24hs
    period = cfg.getLong("period", 24 * 60 * 60 * 1000);
    String initTimeInfo = "";
    long delayLong = cfg.getLong("delay", -1);
    if (delayLong != -1) {
        delay = new Long(delayLong);
        initTimeInfo = "delay = " + delay;
    } else {
        // By default start at 12 AM
        String strFirstTime = cfg.get("firstTime", "00:00:00");
        Date now = new Date();
        if (strFirstTime.equals("now")) {
            firstTime = now;
        } else {
            SimpleDateFormat dateTimeFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
            try {
                String today = dateFormat.format(now);
                Date time = dateTimeFormat.parse(today + " " + strFirstTime);
                if (time.after(now)) {
                    firstTime = time;
                } else {
                    firstTime = new Date(time.getTime() + 1000 * 60 * 60 * 24);
                }
            } catch (ParseException ex) {
                throw new ConfigurationException("The format in which to specify the first execution time is HH:mm:ss");
            }
            initTimeInfo = "firstTime = " + dateTimeFormat.format(firstTime);
        }
    }
    String strConfig = "daemon = " + daemon + "\n" + initTimeInfo + "\n" + "period = " + period;
    log.info("Configuration", strConfig);
}
Also used : Timer(java.util.Timer) ConfigurationException(org.jpos.core.ConfigurationException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 25 with ConfigurationException

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

the class BaseChannel method setConfiguration.

/**
 * Implements Configurable<br>
 * Properties:<br>
 * <ul>
 * <li>host - destination host (if ClientChannel)
 * <li>port - port number      (if ClientChannel)
 * <li>local-iface - local interfase to use (if ClientChannel)
 * <li>local-port - local port to bind (if ClientChannel)
 * </ul>
 * (host not present indicates a ServerChannel)
 *
 * @param cfg Configuration
 * @throws ConfigurationException
 */
public void setConfiguration(Configuration cfg) throws ConfigurationException {
    this.cfg = cfg;
    String h = cfg.get("host");
    int port = cfg.getInt("port");
    maxPacketLength = cfg.getInt("max-packet-length", 100000);
    if (h != null && h.length() > 0) {
        if (port == 0)
            throw new ConfigurationException("invalid port for host '" + h + "'");
        setHost(h, port);
        setLocalAddress(cfg.get("local-iface", null), cfg.getInt("local-port"));
        String[] altHosts = cfg.getAll("alternate-host");
        int[] altPorts = cfg.getInts("alternate-port");
        hosts = new String[altHosts.length + 1];
        ports = new int[altPorts.length + 1];
        if (hosts.length != ports.length) {
            throw new ConfigurationException("alternate host/port misconfiguration");
        }
        hosts[0] = host;
        ports[0] = port;
        System.arraycopy(altHosts, 0, hosts, 1, altHosts.length);
        System.arraycopy(altPorts, 0, ports, 1, altPorts.length);
    }
    setOverrideHeader(cfg.getBoolean("override-header", false));
    keepAlive = cfg.getBoolean("keep-alive", false);
    expectKeepAlive = cfg.getBoolean("expect-keep-alive", false);
    roundRobin = cfg.getBoolean("round-robin", false);
    if (socketFactory != this && socketFactory instanceof Configurable)
        ((Configurable) socketFactory).setConfiguration(cfg);
    try {
        setTimeout(cfg.getInt("timeout", DEFAULT_TIMEOUT));
        connectTimeout = cfg.getInt("connect-timeout", timeout);
    } catch (SocketException e) {
        throw new ConfigurationException(e);
    }
}
Also used : ConfigurationException(org.jpos.core.ConfigurationException) Configurable(org.jpos.core.Configurable)

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