Search in sources :

Example 56 with LogEvent

use of org.jpos.util.LogEvent 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 57 with LogEvent

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

the class ISOBaseValidatingPackager method validate.

public ISOComponent validate(ISOComponent m) throws ISOException {
    LogEvent evt = new LogEvent(this, "validate");
    try {
        ISOComponent c;
        Map fields = m.getChildren();
        /**
         * Field  validations *
         */
        for (ISOValidator aFldVld : fldVld) {
            if (aFldVld != null && (c = (ISOComponent) fields.get(Integer.valueOf(((ISOFieldValidator) aFldVld).getFieldId()))) != null) {
                try {
                    m.set(aFldVld.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 {
            if (msgVld != null) {
                for (ISOBaseValidator aMsgVld : this.msgVld) {
                    if (aMsgVld != null)
                        m = aMsgVld.validate(m);
                }
            }
        } catch (ISOVException ex) {
            evt.addMessage("Component Validation Error.");
            throw ex;
        }
        return m;
    } finally {
        Logger.log(evt);
    }
}
Also used : LogEvent(org.jpos.util.LogEvent) ISOVException(org.jpos.iso.validator.ISOVException) Map(java.util.Map)

Example 58 with LogEvent

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

the class VISA1Packager method pack.

public byte[] pack(ISOComponent c) throws ISOException {
    LogEvent evt = new LogEvent(this, "pack");
    try {
        if (!(c instanceof ISOMsg))
            throw new ISOException("Can't call VISA1 packager on non ISOMsg");
        ISOMsg m = (ISOMsg) c;
        int len = 0;
        List<byte[]> l = new ArrayList();
        for (int i = 0; i < sequence.length; i++) {
            int fld = sequence[i];
            if (fld == 35)
                len += handleSpecialField35(m, l);
            else if (m.hasField(fld)) {
                byte[] value;
                if (fld == 4) {
                    long amt = Long.valueOf(m.getString(4));
                    value = ISOUtil.formatAmount(amt, 12).trim().getBytes();
                } else
                    value = m.getString(fld).getBytes();
                l.add(value);
                len += value.length;
                if (i < sequence.length - 1) {
                    l.add(FS);
                    len++;
                }
            }
        }
        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.dumpString(d));
        return d;
    } catch (ISOException e) {
        evt.addMessage(e);
        throw e;
    } finally {
        Logger.log(evt);
    }
}
Also used : LogEvent(org.jpos.util.LogEvent) ArrayList(java.util.ArrayList)

Example 59 with LogEvent

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

the class XML2003Packager method unpack.

public synchronized void unpack(ISOComponent c, InputStream in) throws ISOException, IOException {
    LogEvent evt = new LogEvent(this, "unpack");
    try {
        if (!(c instanceof ISOMsg))
            throw new ISOException("Can't call packager on non Composite");
        while (// purge from possible previous error
        !stk.empty()) stk.pop();
        reader.parse(new InputSource(in));
        if (stk.empty())
            throw new ISOException("error parsing");
        ISOMsg m = (ISOMsg) c;
        m.merge((ISOMsg) stk.pop());
        fixup(m, BINARY_FIELDS);
        if (logger != null)
            evt.addMessage(m);
    } catch (ISOException e) {
        evt.addMessage(e);
        throw e;
    } catch (SAXException e) {
        evt.addMessage(e);
        throw new ISOException(e.toString());
    } finally {
        Logger.log(evt);
    }
}
Also used : InputSource(org.xml.sax.InputSource) LogEvent(org.jpos.util.LogEvent) SAXException(org.xml.sax.SAXException)

Example 60 with LogEvent

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

the class XML2003Packager method unpack.

public synchronized int unpack(ISOComponent c, byte[] b) throws ISOException {
    LogEvent evt = new LogEvent(this, "unpack");
    try {
        if (!(c instanceof ISOMsg))
            throw new ISOException("Can't call packager on non Composite");
        while (// purge from possible previous error
        !stk.empty()) stk.pop();
        InputSource src = new InputSource(new ByteArrayInputStream(b));
        reader.parse(src);
        if (stk.empty())
            throw new ISOException("error parsing");
        ISOMsg m = (ISOMsg) c;
        ISOMsg m1 = (ISOMsg) stk.pop();
        m.merge(m1);
        m.setHeader(m1.getHeader());
        fixup(m, BINARY_FIELDS);
        if (logger != null)
            evt.addMessage(m);
        return b.length;
    } catch (ISOException e) {
        evt.addMessage(e);
        throw e;
    } catch (IOException e) {
        evt.addMessage(e);
        throw new ISOException(e.toString());
    } catch (SAXException e) {
        evt.addMessage(e);
        throw new ISOException(e.toString());
    } finally {
        Logger.log(evt);
    }
}
Also used : InputSource(org.xml.sax.InputSource) LogEvent(org.jpos.util.LogEvent) SAXException(org.xml.sax.SAXException)

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