Search in sources :

Example 31 with ISOException

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

the class LoopbackChannel method receive.

public ISOMsg receive() throws IOException, ISOException {
    if (!isConnected())
        throw new ISOException("unconnected ISOChannel");
    try {
        ISOMsg m = (ISOMsg) ((ISOMsg) queue.dequeue()).clone();
        LogEvent evt = new LogEvent(this, "loopback-receive", m);
        m = applyIncomingFilters(m, evt);
        cnt[RX]++;
        notifyObservers();
        Logger.log(evt);
        return m;
    } catch (InterruptedException e) {
        throw new IOException(e.toString());
    } catch (BlockingQueue.Closed e) {
        throw new IOException(e.toString());
    }
}
Also used : ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg) IOException(java.io.IOException)

Example 32 with ISOException

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

the class SpaceMUX method notify.

public void notify(Object k, Object value) {
    Object obj = sp.inp(k);
    if (obj instanceof ISOMsg) {
        ISOMsg m = (ISOMsg) obj;
        try {
            String key = getKey(m);
            String req = key + ".req";
            if (sp.inp(req) != null) {
                sp.out(key, m);
                return;
            }
        } catch (ISOException e) {
            Logger.log(new LogEvent(this, "notify", e));
        }
        if (unhandled != null)
            sp.out(unhandled, m, 120000);
    }
}
Also used : ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg) LogEvent(org.jpos.util.LogEvent)

Example 33 with ISOException

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

the class ISOMultiFieldPackager method unpack.

/**
 * @param m      - the ISOComponent to receive the value consumed from ...
 * @param b      - the byte[] holding the raw message
 * @param offset - the current position within b.
 */
public int unpack(ISOComponent m, byte[] b, int offset) throws ISOException {
    ListIterator i = possibles.listIterator();
    while (i.hasNext()) {
        try {
            current = (ISOFieldPackager) i.next();
            ISOField f = new ISOField();
            int consumed = current.unpack(f, b, offset);
            m.setValue(f.getValue());
            return consumed;
        } catch (ISOException eok) {
            current = null;
        }
    }
    throw new ISOException("unpack failed in List process!");
}
Also used : ISOField(org.jpos.iso.ISOField) ISOException(org.jpos.iso.ISOException) ListIterator(java.util.ListIterator)

Example 34 with ISOException

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

the class ISOMultiFieldPackager method unpack.

/**
 * Unpack the passed InputStream into an ISOComponent from our list of possibles.
 * The InputStream *must* support mark!
 */
public void unpack(ISOComponent c, InputStream in) throws IOException, ISOException {
    if (!in.markSupported()) {
        throw new ISOException("InputStream passed to ISOMultFieldPackager *must* support the mark method.");
    }
    ListIterator i = possibles.listIterator();
    // Save our position in the InputStream
    in.mark(1024);
    while (i.hasNext()) {
        in.reset();
        try {
            // One of our possibles will succeed in it's unpack from this Stream.
            current = (ISOFieldPackager) i.next();
            current.unpack(c, in);
            return;
        } catch (ISOException eok) {
            // This one failed.
            current = null;
        } catch (IOException eok) {
            // This one failed.
            current = null;
        }
    }
    throw new ISOException("unpack failed to find a match in the possible List!");
}
Also used : ISOException(org.jpos.iso.ISOException) IOException(java.io.IOException) ListIterator(java.util.ListIterator)

Example 35 with ISOException

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

the class VISA1PackagerTest method testPackThrowsISOException.

public void testPackThrowsISOException() throws Throwable {
    int[] sequence = new int[0];
    try {
        new VISA1Packager(sequence, 100, "testVISA1PackagerBadResultCode", "testVISA1PackagerOkPattern").pack(new ISOField());
        fail("Expected ISOException to be thrown");
    } catch (ISOException ex) {
        assertEquals("ex.getMessage()", "Can't call VISA1 packager on non ISOMsg", ex.getMessage());
        assertNull("ex.getNested()", ex.getNested());
    }
}
Also used : ISOField(org.jpos.iso.ISOField) 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