Search in sources :

Example 71 with LogEvent

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

the class PADChannel method receive.

@Override
public ISOMsg receive() throws IOException, ISOException {
    byte[] header = null;
    ISOMsg m = new ISOMsg();
    m.setPackager(packager);
    m.setSource(this);
    int hLen = getHeaderLength();
    LogEvent evt = new LogEvent(this, "receive");
    try {
        synchronized (serverInLock) {
            if (hLen > 0) {
                header = new byte[hLen];
                serverIn.readFully(header);
            }
            m.unpack(serverIn);
        }
        m.setHeader(header);
        m.setDirection(ISOMsg.INCOMING);
        m = applyIncomingFilters(m, evt);
        m.setDirection(ISOMsg.INCOMING);
        evt.addMessage(m);
        cnt[RX]++;
        setChanged();
        notifyObservers(m);
    } catch (ISOException e) {
        evt.addMessage(e);
        throw e;
    } catch (EOFException e) {
        evt.addMessage("<peer-disconnect/>");
        throw e;
    } catch (InterruptedIOException e) {
        evt.addMessage("<io-timeout/>");
        throw e;
    } catch (IOException e) {
        if (usable)
            evt.addMessage(e);
        throw e;
    } catch (Exception e) {
        evt.addMessage(e);
        throw new ISOException("unexpected exception", e);
    } finally {
        Logger.log(evt);
    }
    return m;
}
Also used : InterruptedIOException(java.io.InterruptedIOException) LogEvent(org.jpos.util.LogEvent) EOFException(java.io.EOFException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException) ConfigurationException(org.jpos.core.ConfigurationException) IOException(java.io.IOException) EOFException(java.io.EOFException) InterruptedIOException(java.io.InterruptedIOException)

Example 72 with LogEvent

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

the class Base1SubFieldPackager 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();
        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++) {
            if ((c = (ISOComponent) fields.get(i)) != null) {
                try {
                    byte[] b = fld[i].pack(c);
                    len += b.length;
                    l.add(b);
                } catch (Exception e) {
                    evt.addMessage("error packing field " + i);
                    evt.addMessage(c);
                    evt.addMessage(e);
                    throw new ISOException(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;
    } finally {
        Logger.log(evt);
    }
}
Also used : LogEvent(org.jpos.util.LogEvent) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 73 with LogEvent

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

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

the class ConnectionPool method run.

public void run() {
    Connection connection = null;
    while (connection == null) {
        try {
            connection = makeNewConnection();
            synchronized (this) {
                availableConnections.addElement(connection);
                connectionPending = false;
                notifyAll();
            }
        } catch (Exception e) {
            // SQLException or OutOfMemory
            LogEvent evt = new LogEvent(this, "error");
            evt.addMessage("An error occurred while trying to make a background connection");
            evt.addMessage(e);
            Logger.log(evt);
            try {
                // don't get too crazy about retrying
                Thread.sleep(3000);
            } catch (InterruptedException ie) {
            // this one, we don't care.
            }
        }
    }
}
Also used : LogEvent(org.jpos.util.LogEvent) Connection(java.sql.Connection) SQLException(java.sql.SQLException) ConfigurationException(org.jpos.core.ConfigurationException)

Example 75 with LogEvent

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

the class BSHLogListener method log.

public LogEvent log(LogEvent ev) {
    LogEvent ret = ev;
    boolean processed = false;
    try {
        String[] sources = replace(cfg.getAll("source"), patterns, new String[] { ev.getTag(), ev.getRealm() });
        for (int i = 0; i < sources.length && ret != null; i++) {
            try {
                Interpreter bsh = new Interpreter();
                BSHLogListener.ScriptInfo info = getScriptInfo(sources[i]);
                NameSpace ns = info != null ? info.getNameSpace() : null;
                if (ns != null)
                    bsh.setNameSpace(ns);
                bsh.set("event", ret);
                bsh.set("cfg", cfg);
                File f = new File(sources[i]);
                if (!cfg.getBoolean("preload-scripts")) {
                    if (f.exists() && f.canRead() && f.isFile()) {
                        // if(f.lastModified())
                        processed = true;
                        bsh.eval(new java.io.FileReader(f));
                    }
                } else {
                    if (info == null)
                        scripts.put(sources[i], info = new ScriptInfo());
                    if (System.currentTimeMillis() > info.getLastCheck() + cfg.getLong("reload")) {
                        info.setLastCheck(System.currentTimeMillis());
                        if (f.exists() && f.canRead() && f.isFile()) {
                            if (info.getLastModified() != f.lastModified()) {
                                info.setLastModified(f.lastModified());
                                info.setCode(loadCode(f));
                            }
                        } else {
                            info.setCode(null);
                        }
                    }
                    if (info.getCode() != null) {
                        processed = true;
                        bsh.eval(new StringReader(info.getCode()));
                    } else
                        scripts.remove(sources[i]);
                }
                ret = (LogEvent) bsh.get("event");
                Object saveNS = bsh.get("saveNameSpace");
                boolean saveNameSpace = saveNS instanceof Boolean ? (Boolean) saveNS : cfg.getBoolean("save-name-space");
                if (saveNameSpace) {
                    if (info != null)
                        info.setNameSpace(bsh.getNameSpace());
                    else
                        scripts.put(sources[i], new ScriptInfo(bsh.getNameSpace()));
                } else if (info != null)
                    info.setNameSpace(null);
            } catch (Exception e) {
                ret.addMessage(e);
            }
        }
        return !processed && cfg.getBoolean("filter-by-default") ? null : ret;
    } catch (Exception e) {
        if (ret != null) {
            ret.addMessage(e);
        }
        return ret;
    }
}
Also used : Interpreter(bsh.Interpreter) LogEvent(org.jpos.util.LogEvent) NameSpace(bsh.NameSpace) IOException(java.io.IOException) StringReader(java.io.StringReader) FileReader(java.io.FileReader) File(java.io.File)

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