Search in sources :

Example 16 with ISOComponent

use of org.jpos.iso.ISOComponent 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 17 with ISOComponent

use of org.jpos.iso.ISOComponent 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 18 with ISOComponent

use of org.jpos.iso.ISOComponent in project jPOS by jpos.

the class GICCSubFieldPackager method unpack.

public int unpack(ISOComponent m, byte[] b) throws ISOException {
    // Unpack the IF_CHAR field
    int consumed = 0;
    ISOComponent c;
    if (fld[0] != null && b[consumed] == 0x20) {
        // Hack to support a nine-byte filler
        c = fld[0].createComponent(0);
        consumed += fld[0].unpack(c, b, consumed);
        m.set(c);
    }
    // Now unpack the IFEP_LLCHAR fields
    for (; consumed < b.length; ) {
        int fieldNumber = Integer.parseInt(ISOUtil.ebcdicToAscii(b, consumed + 3, 2));
        if (fld[fieldNumber] == null)
            break;
        c = fld[fieldNumber].createComponent(fieldNumber);
        consumed += fld[fieldNumber].unpack(c, b, consumed);
        m.set(c);
    }
    return consumed;
}
Also used : ISOComponent(org.jpos.iso.ISOComponent)

Example 19 with ISOComponent

use of org.jpos.iso.ISOComponent in project jPOS by jpos.

the class GenericValidatingPackager method validate.

public ISOComponent validate(ISOComponent m) throws ISOException {
    LogEvent evt = new LogEvent(this, "validate");
    try {
        ISOComponent c;
        Map<Object, ISOComponent> fields = m.getChildren();
        /**
         * Field  validations *
         */
        for (ISOValidator val : fvlds) {
            if ((c = fields.get(((ISOFieldValidator) val).getFieldId())) != null) {
                try {
                    m.set(val.validate(c));
                } catch (ISOVException e) {
                    if (!e.treated()) {
                        m.set(e.getErrComponent());
                        e.setTreated(true);
                    }
                    evt.addMessage("Component Validation Error.");
                    throw e;
                }
            }
        }
        /**
         * msg validations *
         */
        try {
            for (ISOBaseValidator mval : mvlds) m = mval.validate(m);
        } catch (ISOVException ex) {
            evt.addMessage("Component Validation Error.");
            throw ex;
        }
        return m;
    } finally {
        Logger.log(evt);
    }
}
Also used : ISOComponent(org.jpos.iso.ISOComponent) LogEvent(org.jpos.util.LogEvent) ISOVException(org.jpos.iso.validator.ISOVException) ISOValidator(org.jpos.iso.ISOValidator) ISOBaseValidator(org.jpos.iso.ISOBaseValidator) ISOFieldValidator(org.jpos.iso.ISOFieldValidator)

Example 20 with ISOComponent

use of org.jpos.iso.ISOComponent in project jPOS by jpos.

the class VISA1PackagerTest method testUnpack1.

@Test
public void testUnpack1() throws Throwable {
    int[] sequence = new int[0];
    VISA1Packager vISA1Packager = new VISA1Packager(sequence, 100, "testVISA1PackagerBadResultCode", "testVISA1PackagerOkPattern");
    ISOComponent m = new ISOMsg(100);
    byte[] b = new byte[0];
    int result = vISA1Packager.unpack(m, b);
    assertEquals("(ISOVMsg) m.getMaxField()", 100, m.getMaxField());
    assertEquals("result", 0, result);
}
Also used : ISOComponent(org.jpos.iso.ISOComponent) ISOMsg(org.jpos.iso.ISOMsg) Test(org.junit.Test)

Aggregations

ISOComponent (org.jpos.iso.ISOComponent)34 ISOMsg (org.jpos.iso.ISOMsg)25 Test (org.junit.Test)23 ISOVMsg (org.jpos.iso.ISOVMsg)8 ISOException (org.jpos.iso.ISOException)6 LogEvent (org.jpos.util.LogEvent)6 Vector (java.util.Vector)5 ISOBaseValidator (org.jpos.iso.ISOBaseValidator)5 ISOField (org.jpos.iso.ISOField)5 ISOVError (org.jpos.iso.ISOVError)5 Map (java.util.Map)4 ISOBinaryField (org.jpos.iso.ISOBinaryField)4 ISOValidator (org.jpos.iso.ISOValidator)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ISOFieldPackager (org.jpos.iso.ISOFieldPackager)3 ISOFieldValidator (org.jpos.iso.ISOFieldValidator)3 ISOTaggedField (org.jpos.tlv.ISOTaggedField)3 TreeMap (java.util.TreeMap)2 ConfigurationException (org.jpos.core.ConfigurationException)2