Search in sources :

Example 51 with LogEvent

use of org.jpos.util.LogEvent in project jPOS by jpos.

the class CTCSubElementPackager method unpack.

public int unpack(ISOComponent m, byte[] b) throws ISOException {
    LogEvent evt = new LogEvent(this, "unpack");
    int consumed = 0;
    for (int i = 0; consumed < b.length; i++) {
        ISOComponent c = fld[i].createComponent(i);
        consumed += fld[i].unpack(c, b, consumed);
        if (logger != null) {
            evt.addMessage("<unpack fld=\"" + i + "\" packager=\"" + fld[i].getClass().getName() + "\">");
            if (c.getValue() instanceof ISOMsg)
                evt.addMessage(c.getValue());
            else
                evt.addMessage("  <value>" + c.getValue().toString() + "</value>");
            evt.addMessage("</unpack>");
        }
        m.set(c);
    }
    Logger.log(evt);
    return consumed;
}
Also used : ISOComponent(org.jpos.iso.ISOComponent) ISOMsg(org.jpos.iso.ISOMsg) LogEvent(org.jpos.util.LogEvent)

Example 52 with LogEvent

use of org.jpos.util.LogEvent in project jPOS by jpos.

the class CTCSubFieldPackager method unpack.

public int unpack(ISOComponent m, byte[] b) throws ISOException {
    LogEvent evt = new LogEvent(this, "unpack");
    int consumed = 0;
    for (int i = 0; consumed < b.length; i++) {
        ISOComponent c = fld[i].createComponent(i);
        consumed += fld[i].unpack(c, b, consumed);
        if (logger != null) {
            evt.addMessage("<unpack fld=\"" + i + "\" packager=\"" + fld[i].getClass().getName() + "\">");
            evt.addMessage("  <value>" + c.getValue().toString() + "</value>");
            evt.addMessage("</unpack>");
        }
        m.set(c);
    }
    Logger.log(evt);
    return consumed;
}
Also used : ISOComponent(org.jpos.iso.ISOComponent) LogEvent(org.jpos.util.LogEvent)

Example 53 with LogEvent

use of org.jpos.util.LogEvent in project jPOS by jpos.

the class GenericSubFieldPackager method pack.

/**
 * Pack the subfield into a byte array
 */
public byte[] pack(ISOComponent m) throws ISOException {
    LogEvent evt = new LogEvent(this, "pack");
    try {
        ISOComponent c;
        List<byte[]> l = new ArrayList<byte[]>();
        Map fields = m.getChildren();
        int len = 0;
        if (emitBitMap()) {
            // BITMAP (-1 in HashTable)
            c = (ISOComponent) fields.get(-1);
            byte[] b = getBitMapfieldPackager().pack(c);
            len += b.length;
            l.add(b);
        }
        for (int i = getFirstField(); i <= m.getMaxField(); i++) {
            c = (ISOComponent) fields.get(i);
            if (c == null && !emitBitMap())
                c = new ISOField(i, "");
            if (c != null) {
                try {
                    byte[] b = fld[i].pack(c);
                    len += b.length;
                    l.add(b);
                } catch (Exception e) {
                    evt.addMessage("error packing subfield " + i);
                    evt.addMessage(c);
                    evt.addMessage(e);
                    throw e;
                }
            }
        }
        int k = 0;
        byte[] d = new byte[len];
        for (byte[] b : l) {
            System.arraycopy(b, 0, d, k, b.length);
            k += b.length;
        }
        if (// save a few CPU cycle if no logger available
        logger != null)
            evt.addMessage(ISOUtil.hexString(d));
        return d;
    } catch (ISOException e) {
        evt.addMessage(e);
        throw e;
    } catch (Exception e) {
        evt.addMessage(e);
        throw new ISOException(e);
    } finally {
        Logger.log(evt);
    }
}
Also used : LogEvent(org.jpos.util.LogEvent) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 54 with LogEvent

use of org.jpos.util.LogEvent in project jPOS by jpos.

the class GenericTaggedFieldsPackager method unpack.

@Override
public void unpack(ISOComponent m, InputStream in) throws IOException, ISOException {
    LogEvent evt = new LogEvent(this, "unpack");
    try {
        if (m.getComposite() != m)
            throw new ISOException("Can't call packager on non Composite");
        // if ISOMsg and headerLength defined
        if (m instanceof ISOMsg && ((ISOMsg) m).getHeader() == null && headerLength > 0) {
            byte[] h = new byte[headerLength];
            in.read(h, 0, headerLength);
            ((ISOMsg) m).setHeader(h);
        }
        if (!(fld[0] instanceof ISOMsgFieldPackager) && !(fld[0] instanceof ISOBitMapPackager)) {
            ISOComponent mti = fld[0].createComponent(0);
            fld[0].unpack(mti, in);
            m.set(mti);
        }
        int maxField = fld.length;
        for (int i = getFirstField(); i < maxField; i++) {
            if (fld[i] == null)
                continue;
            ISOComponent c = fld[i].createComponent(i);
            fld[i].unpack(c, in);
            if (logger != null) {
                evt.addMessage("<unpack fld=\"" + i + "\" packager=\"" + fld[i].getClass().getName() + "\">");
                if (c.getValue() instanceof ISOMsg)
                    evt.addMessage(c.getValue());
                else
                    evt.addMessage("  <value>" + c.getValue().toString() + "</value>");
                evt.addMessage("</unpack>");
            }
            m.set(c);
        }
    } catch (ISOException e) {
        evt.addMessage(e);
        throw e;
    } catch (EOFException e) {
        throw e;
    } catch (Exception e) {
        evt.addMessage(e);
        throw new ISOException(e);
    } finally {
        Logger.log(evt);
    }
}
Also used : LogEvent(org.jpos.util.LogEvent) EOFException(java.io.EOFException) IOException(java.io.IOException) EOFException(java.io.EOFException)

Example 55 with LogEvent

use of org.jpos.util.LogEvent in project jPOS by jpos.

the class GenericTaggedFieldsPackager method pack.

/**
 * Pack the subfield into a byte array
 *
 * @return packed array of bytes
 * @throws org.jpos.iso.ISOException
 */
@Override
public byte[] pack(ISOComponent m) throws ISOException {
    LogEvent evt = new LogEvent(this, "pack");
    try {
        ISOComponent c;
        List<byte[]> l = new ArrayList<byte[]>();
        Map fields = m.getChildren();
        int len = 0;
        for (int i = getFirstField(); i <= m.getMaxField(); i++) {
            c = (ISOComponent) fields.get(i);
            if (c != null) {
                try {
                    byte[] b = fld[i].pack(c);
                    len += b.length;
                    l.add(b);
                } catch (Exception e) {
                    evt.addMessage("error packing subfield " + i);
                    evt.addMessage(c);
                    evt.addMessage(e);
                    throw e;
                }
            }
        }
        int k = 0;
        byte[] d = new byte[len];
        for (byte[] b : l) {
            System.arraycopy(b, 0, d, k, b.length);
            k += b.length;
        }
        if (// save a few CPU cycle if no logger available
        logger != null)
            evt.addMessage(ISOUtil.hexString(d));
        return d;
    } catch (ISOException e) {
        evt.addMessage(e);
        throw e;
    } catch (Exception e) {
        evt.addMessage(e);
        throw new ISOException(e);
    } finally {
        Logger.log(evt);
    }
}
Also used : LogEvent(org.jpos.util.LogEvent) ArrayList(java.util.ArrayList) Map(java.util.Map) IOException(java.io.IOException) EOFException(java.io.EOFException)

Aggregations

LogEvent (org.jpos.util.LogEvent)189 Test (org.junit.Test)78 ConfigurationException (org.jpos.core.ConfigurationException)51 ISOMsg (org.jpos.iso.ISOMsg)41 SimpleMsg (org.jpos.util.SimpleMsg)40 NotFoundException (org.jpos.util.NameRegistrar.NotFoundException)38 ArrayList (java.util.ArrayList)24 IOException (java.io.IOException)18 SimpleConfiguration (org.jpos.core.SimpleConfiguration)14 CSChannel (org.jpos.iso.channel.CSChannel)12 Loggeable (org.jpos.util.Loggeable)11 Map (java.util.Map)9 ISOChannel (org.jpos.iso.ISOChannel)9 PostChannel (org.jpos.iso.channel.PostChannel)9 CTCSubFieldPackager (org.jpos.iso.packager.CTCSubFieldPackager)9 ISOFilter (org.jpos.iso.ISOFilter)8 BASE24TCPChannel (org.jpos.iso.channel.BASE24TCPChannel)8 PADChannel (org.jpos.iso.channel.PADChannel)8 ISOBaseValidatingPackager (org.jpos.iso.packager.ISOBaseValidatingPackager)8 EOFException (java.io.EOFException)7