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));
}
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);
}
}
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);
}
}
}
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);
}
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);
}
}
Aggregations