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;
}
}
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;
}
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;
}
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);
}
}
}
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);
}
}
Aggregations