use of org.jpos.iso.ISOException in project jPOS by jpos.
the class CTCSubElementPackager method pack.
public byte[] pack(ISOComponent c) throws ISOException {
try {
Map tab = c.getChildren();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < fld.length; i++) {
ISOMsg f = (ISOMsg) tab.get(i);
if (f != null) {
sb.append(ISOUtil.zeropad(f.getKey().toString(), 2) + new String(fld[i].pack(f)));
}
}
return sb.toString().getBytes();
} catch (Exception ex) {
throw new ISOException(this.getRealm() + ":" + ex.getMessage(), ex);
}
}
use of org.jpos.iso.ISOException in project jPOS by jpos.
the class GICCSubFieldPackager method pack.
public byte[] pack(ISOComponent c) throws ISOException {
try {
int len = 0;
byte[] result;
Map tab = c.getChildren();
List list = new ArrayList();
// Handle first IF_CHAR field
ISOField f0 = (ISOField) tab.get(0);
if (f0 != null) {
String s = (String) f0.getValue();
list.add(s.getBytes());
len += s.getBytes().length;
}
for (int i = 1; i < fld.length; i++) {
Object obj = tab.get(i);
if (obj instanceof ISOComponent) {
ISOComponent f = (ISOComponent) obj;
byte[] b = fld[i].pack(f);
list.add(b);
len += b.length;
}
}
result = new byte[len];
int k = 0;
for (int i = 0; i < list.size(); i++) {
byte[] b = (byte[]) list.get(i);
for (int j = 0; j < b.length; j++) result[k++] = b[j];
}
return result;
} catch (Exception ex) {
throw new ISOException(ex);
}
}
use of org.jpos.iso.ISOException 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());
}
}
use of org.jpos.iso.ISOException in project jPOS by jpos.
the class GenericPackager method readFile.
/**
* Parse the field descriptions from an XML file.
*
* <pre>
* Uses the sax parser specified by the system property 'sax.parser'
* The default parser is org.apache.crimson.parser.XMLReaderImpl
* </pre>
* @param filename The XML field description file
*/
public void readFile(String filename) throws ISOException {
try {
if (filename.startsWith("jar:") && filename.length() > 4) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
readFile(cl.getResourceAsStream(filename.substring(4)));
} else {
createXMLReader().parse(filename);
}
} catch (Exception e) {
throw new ISOException("Error reading " + filename, e);
}
}
use of org.jpos.iso.ISOException in project jPOS by jpos.
the class LoopbackChannel method send.
public void send(byte[] b) throws IOException, ISOException {
if (!isConnected())
throw new ISOException("unconnected ISOChannel");
LogEvent evt = new LogEvent(this, "loopback-send", b);
queue.enqueue(b);
cnt[TX]++;
notifyObservers();
Logger.log(evt);
}
Aggregations