Search in sources :

Example 61 with ISOException

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

the class NativePackager method unpack.

@Override
public void unpack(ISOComponent m, InputStream in) throws IOException, ISOException {
    try {
        if (m instanceof Externalizable) {
            ObjectInputStream is = new ObjectInputStream(in);
            ((Externalizable) m).readExternal(is);
        }
    } catch (Exception e) {
        throw new ISOException(e);
    }
}
Also used : ISOException(org.jpos.iso.ISOException) ISOException(org.jpos.iso.ISOException)

Example 62 with ISOException

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

the class NativePackager method pack.

@Override
public byte[] pack(ISOComponent c) throws ISOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        if (c instanceof ISOMsg) {
            ISOMsg m = (ISOMsg) c;
            ISOPackager p = m.getPackager();
            m.setPackager(null);
            ObjectOutputStream os = new ObjectOutputStream(baos);
            ((Externalizable) c).writeExternal(os);
            os.flush();
            m.setPackager(p);
        }
    } catch (IOException e) {
        throw new ISOException(e);
    }
    return baos.toByteArray();
}
Also used : ISOPackager(org.jpos.iso.ISOPackager) ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg)

Example 63 with ISOException

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

the class ProtectedLogListener method log.

public LogEvent log(LogEvent ev) {
    synchronized (ev.getPayLoad()) {
        final List<Object> payLoad = ev.getPayLoad();
        int size = payLoad.size();
        for (int i = 0; i < size; i++) {
            Object obj = payLoad.get(i);
            if (obj instanceof ISOMsg) {
                ISOMsg m = (ISOMsg) ((ISOMsg) obj).clone();
                try {
                    checkProtected(m);
                    checkHidden(m);
                } catch (ISOException e) {
                    ev.addMessage(e);
                }
                payLoad.set(i, m);
            } else if (obj instanceof SimpleMsg) {
                try {
                    checkProtected((SimpleMsg) obj);
                } catch (ISOException e) {
                    ev.addMessage(e);
                }
            }
        }
    }
    return ev;
}
Also used : ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg)

Example 64 with ISOException

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

the class QServer method notify.

/*
     * This method will be invoked through the SpaceListener interface we registered once
     * we noticed we had an 'in' queue.
     */
@Override
public void notify(Object key, Object value) {
    Object obj = sp.inp(key);
    if (obj instanceof ISOMsg) {
        ISOMsg m = (ISOMsg) obj;
        if ("LAST".equals(sendMethod)) {
            try {
                ISOChannel c = server.getLastConnectedISOChannel();
                if (c == null) {
                    throw new ISOException("Server has no active connections");
                }
                if (!c.isConnected()) {
                    throw new ISOException("Client disconnected");
                }
                c.send(m);
            } catch (Exception e) {
                getLog().warn("notify", e);
            }
        } else if ("ALL".equals(sendMethod)) {
            String channelNames = getISOChannelNames();
            if (channelNames != null) {
                StringTokenizer tok = new StringTokenizer(channelNames, " ");
                while (tok.hasMoreTokens()) {
                    try {
                        ISOChannel c = server.getISOChannel(tok.nextToken());
                        if (c == null) {
                            throw new ISOException("Server has no active connections");
                        }
                        if (!c.isConnected()) {
                            throw new ISOException("Client disconnected");
                        }
                        c.send(m);
                    } catch (Exception e) {
                        getLog().warn("notify", e);
                    }
                }
            }
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ISOException(org.jpos.iso.ISOException) ISOMsg(org.jpos.iso.ISOMsg) ISOChannel(org.jpos.iso.ISOChannel) ConfigurationException(org.jpos.core.ConfigurationException) ISOException(org.jpos.iso.ISOException)

Example 65 with ISOException

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

the class LoopbackChannel method send.

public void send(ISOMsg m) throws IOException, ISOException {
    if (!isConnected())
        throw new ISOException("unconnected ISOChannel");
    LogEvent evt = new LogEvent(this, "loopback-send", m);
    m = applyOutgoingFilters(m, evt);
    queue.enqueue(m);
    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