Search in sources :

Example 76 with LogEvent

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

the class BaseChannel method connect.

/**
 * Connects client ISOChannel to server
 * @exception IOException
 */
public void connect() throws IOException {
    LogEvent evt = new LogEvent(this, "connect");
    try {
        if (serverSocket != null) {
            accept(serverSocket);
            evt.addMessage("local port " + serverSocket.getLocalPort() + " remote host " + socket.getInetAddress());
        } else {
            connect(newSocket(hosts, ports, evt));
        }
        applyTimeout();
        Logger.log(evt);
    } catch (ConnectException e) {
        Logger.log(new LogEvent(this, "connection-refused", getHost() + ":" + getPort()));
    } catch (IOException e) {
        evt.addMessage(e.getMessage());
        Logger.log(evt);
        throw e;
    }
}
Also used : LogEvent(org.jpos.util.LogEvent)

Example 77 with LogEvent

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

the class BaseChannel method receive.

/**
 * Waits and receive an ISOMsg over the TCP/IP session
 * @return the Message received
 * @throws IOException
 * @throws ISOException
 */
public ISOMsg receive() throws IOException, ISOException {
    byte[] b = null;
    byte[] header = null;
    LogEvent evt = new LogEvent(this, "receive");
    // call createMsg instead of createISOMsg for
    ISOMsg m = createMsg();
    // backward compatibility
    m.setSource(this);
    try {
        if (!isConnected())
            throw new IOException("unconnected ISOChannel");
        synchronized (serverInLock) {
            int len = getMessageLength();
            if (expectKeepAlive) {
                while (len == 0) {
                    // If zero length, this is a keep alive msg
                    Logger.log(new LogEvent(this, "receive", "Zero length keep alive message received"));
                    len = getMessageLength();
                }
            }
            int hLen = getHeaderLength();
            if (len == -1) {
                if (hLen > 0) {
                    header = readHeader(hLen);
                }
                b = streamReceive();
            } else if (len > 0 && len <= getMaxPacketLength()) {
                if (hLen > 0) {
                    // ignore message header (TPDU)
                    // Note header length is not necessarily equal to hLen (see VAPChannel)
                    header = readHeader(hLen);
                    len -= header.length;
                }
                b = new byte[len];
                getMessage(b, 0, len);
                getMessageTrailer(m);
            } else
                throw new ISOException("receive length " + len + " seems strange - maxPacketLength = " + getMaxPacketLength());
        }
        m.setPackager(getDynamicPackager(header, b));
        m.setHeader(getDynamicHeader(header));
        if (// Ignore NULL messages
        b.length > 0 && !shouldIgnore(header))
            unpack(m, b);
        m.setDirection(ISOMsg.INCOMING);
        evt.addMessage(m);
        m = applyIncomingFilters(m, header, b, evt);
        m.setDirection(ISOMsg.INCOMING);
        cnt[RX]++;
        setChanged();
        notifyObservers(m);
    } catch (ISOException e) {
        evt.addMessage(e);
        if (header != null) {
            evt.addMessage("--- header ---");
            evt.addMessage(ISOUtil.hexdump(header));
        }
        if (b != null) {
            evt.addMessage("--- data ---");
            evt.addMessage(ISOUtil.hexdump(b));
        }
        throw e;
    } catch (EOFException e) {
        closeSocket();
        evt.addMessage("<peer-disconnect/>");
        throw e;
    } catch (SocketException e) {
        closeSocket();
        if (usable)
            evt.addMessage("<peer-disconnect>" + e.getMessage() + "</peer-disconnect>");
        throw e;
    } catch (InterruptedIOException e) {
        closeSocket();
        evt.addMessage("<io-timeout/>");
        throw e;
    } catch (IOException e) {
        closeSocket();
        if (usable)
            evt.addMessage(e);
        throw e;
    } catch (Exception e) {
        closeSocket();
        evt.addMessage(m);
        evt.addMessage(e);
        throw new IOException("unexpected exception", e);
    } finally {
        Logger.log(evt);
    }
    return m;
}
Also used : LogEvent(org.jpos.util.LogEvent) ConfigurationException(org.jpos.core.ConfigurationException) VetoException(org.jpos.iso.ISOFilter.VetoException)

Example 78 with LogEvent

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

the class BaseChannel method disconnect.

/**
 * disconnects the TCP/IP session. The instance is ready for
 * a reconnection. There is no need to create a new ISOChannel<br>
 * @exception IOException
 */
public void disconnect() throws IOException {
    LogEvent evt = new LogEvent(this, "disconnect");
    if (serverSocket != null)
        evt.addMessage("local port " + serverSocket.getLocalPort() + " remote host " + serverSocket.getInetAddress());
    else
        evt.addMessage(host + ":" + port);
    try {
        usable = false;
        setChanged();
        notifyObservers();
        closeSocket();
        if (serverIn != null) {
            try {
                serverIn.close();
            } catch (IOException ex) {
                evt.addMessage(ex);
            }
            serverIn = null;
        }
        if (serverOut != null) {
            try {
                serverOut.close();
            } catch (IOException ex) {
                evt.addMessage(ex);
            }
            serverOut = null;
        }
    } catch (IOException e) {
        evt.addMessage(e);
        Logger.log(evt);
        throw e;
    }
    socket = null;
}
Also used : LogEvent(org.jpos.util.LogEvent)

Example 79 with LogEvent

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

the class LoggerService method run.

@SuppressWarnings("unchecked")
public void run() {
    while (running()) {
        LogEvent evt = (LogEvent) sp.in(queueName, 1000L);
        if (evt != null) {
            evt.setSource(getLog());
            Logger.log(evt);
        }
    }
}
Also used : LogEvent(org.jpos.util.LogEvent)

Example 80 with LogEvent

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

the class QExec method exec.

private void exec(String script) throws IOException {
    if (script != null) {
        Process p = Runtime.getRuntime().exec(script);
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        LogEvent evt = getLog().createInfo("--- " + script + " ---");
        String line;
        while ((line = in.readLine()) != null) {
            evt.addMessage(line);
        }
        Logger.log(evt);
    }
}
Also used : LogEvent(org.jpos.util.LogEvent)

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