Search in sources :

Example 26 with ISOException

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);
    }
}
Also used : ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg) Map(java.util.Map) ISOVException(org.jpos.iso.validator.ISOVException) ISOException(org.jpos.iso.ISOException)

Example 27 with ISOException

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);
    }
}
Also used : ISOField(org.jpos.iso.ISOField) ISOComponent(org.jpos.iso.ISOComponent) ISOException(org.jpos.iso.ISOException) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) ISOException(org.jpos.iso.ISOException)

Example 28 with ISOException

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());
    }
}
Also used : ISOException(org.jpos.iso.ISOException) ConfigurationException(org.jpos.core.ConfigurationException)

Example 29 with ISOException

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);
    }
}
Also used : ISOException(org.jpos.iso.ISOException) ConfigurationException(org.jpos.core.ConfigurationException) ISOException(org.jpos.iso.ISOException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException)

Example 30 with ISOException

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);
}
Also used : ISOException(org.jpos.iso.ISOException)

Aggregations

ISOException (org.jpos.iso.ISOException)66 Test (org.junit.Test)36 ISOMsg (org.jpos.iso.ISOMsg)29 ISOField (org.jpos.iso.ISOField)15 ISOFieldPackager (org.jpos.iso.ISOFieldPackager)12 ISOBaseValidator (org.jpos.iso.ISOBaseValidator)8 IOException (java.io.IOException)7 ISOBinaryField (org.jpos.iso.ISOBinaryField)7 TEST0100 (org.jpos.iso.validator.TEST0100)7 Map (java.util.Map)6 ConfigurationException (org.jpos.core.ConfigurationException)6 ISOComponent (org.jpos.iso.ISOComponent)6 ISOFieldValidator (org.jpos.iso.ISOFieldValidator)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 LogEvent (org.jpos.util.LogEvent)5 SAXParseException (org.xml.sax.SAXParseException)5 IVA_ALPHANUMNOBLANK (org.jpos.iso.IVA_ALPHANUMNOBLANK)4 ISOVException (org.jpos.iso.validator.ISOVException)4 ISOTaggedField (org.jpos.tlv.ISOTaggedField)4 ArrayList (java.util.ArrayList)3