use of org.jpos.util.LogEvent in project jPOS by jpos.
the class GenericValidatingPackager method validate.
public ISOComponent validate(ISOComponent m) throws ISOException {
LogEvent evt = new LogEvent(this, "validate");
try {
ISOComponent c;
Map<Object, ISOComponent> fields = m.getChildren();
/**
* Field validations *
*/
for (ISOValidator val : fvlds) {
if ((c = fields.get(((ISOFieldValidator) val).getFieldId())) != null) {
try {
m.set(val.validate(c));
} catch (ISOVException e) {
if (!e.treated()) {
m.set(e.getErrComponent());
e.setTreated(true);
}
evt.addMessage("Component Validation Error.");
throw e;
}
}
}
/**
* msg validations *
*/
try {
for (ISOBaseValidator mval : mvlds) m = mval.validate(m);
} catch (ISOVException ex) {
evt.addMessage("Component Validation Error.");
throw ex;
}
return m;
} finally {
Logger.log(evt);
}
}
use of org.jpos.util.LogEvent in project jPOS by jpos.
the class ISOBaseValidatingPackager method validate.
public ISOComponent validate(ISOComponent m) throws ISOException {
LogEvent evt = new LogEvent(this, "validate");
try {
ISOComponent c;
Map fields = m.getChildren();
/**
* Field validations *
*/
for (ISOValidator aFldVld : fldVld) {
if (aFldVld != null && (c = (ISOComponent) fields.get(Integer.valueOf(((ISOFieldValidator) aFldVld).getFieldId()))) != null) {
try {
m.set(aFldVld.validate(c));
} catch (ISOVException e) {
if (!e.treated()) {
m.set(e.getErrComponent());
e.setTreated(true);
}
evt.addMessage("Component Validation Error.");
throw e;
}
}
}
/**
* msg validations *
*/
try {
if (msgVld != null) {
for (ISOBaseValidator aMsgVld : this.msgVld) {
if (aMsgVld != null)
m = aMsgVld.validate(m);
}
}
} catch (ISOVException ex) {
evt.addMessage("Component Validation Error.");
throw ex;
}
return m;
} finally {
Logger.log(evt);
}
}
use of org.jpos.util.LogEvent in project jPOS by jpos.
the class VISA1Packager method pack.
public byte[] pack(ISOComponent c) throws ISOException {
LogEvent evt = new LogEvent(this, "pack");
try {
if (!(c instanceof ISOMsg))
throw new ISOException("Can't call VISA1 packager on non ISOMsg");
ISOMsg m = (ISOMsg) c;
int len = 0;
List<byte[]> l = new ArrayList();
for (int i = 0; i < sequence.length; i++) {
int fld = sequence[i];
if (fld == 35)
len += handleSpecialField35(m, l);
else if (m.hasField(fld)) {
byte[] value;
if (fld == 4) {
long amt = Long.valueOf(m.getString(4));
value = ISOUtil.formatAmount(amt, 12).trim().getBytes();
} else
value = m.getString(fld).getBytes();
l.add(value);
len += value.length;
if (i < sequence.length - 1) {
l.add(FS);
len++;
}
}
}
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.dumpString(d));
return d;
} catch (ISOException e) {
evt.addMessage(e);
throw e;
} finally {
Logger.log(evt);
}
}
use of org.jpos.util.LogEvent in project jPOS by jpos.
the class XML2003Packager method unpack.
public synchronized void unpack(ISOComponent c, InputStream in) throws ISOException, IOException {
LogEvent evt = new LogEvent(this, "unpack");
try {
if (!(c instanceof ISOMsg))
throw new ISOException("Can't call packager on non Composite");
while (// purge from possible previous error
!stk.empty()) stk.pop();
reader.parse(new InputSource(in));
if (stk.empty())
throw new ISOException("error parsing");
ISOMsg m = (ISOMsg) c;
m.merge((ISOMsg) stk.pop());
fixup(m, BINARY_FIELDS);
if (logger != null)
evt.addMessage(m);
} catch (ISOException e) {
evt.addMessage(e);
throw e;
} catch (SAXException e) {
evt.addMessage(e);
throw new ISOException(e.toString());
} finally {
Logger.log(evt);
}
}
use of org.jpos.util.LogEvent in project jPOS by jpos.
the class XML2003Packager method unpack.
public synchronized int unpack(ISOComponent c, byte[] b) throws ISOException {
LogEvent evt = new LogEvent(this, "unpack");
try {
if (!(c instanceof ISOMsg))
throw new ISOException("Can't call packager on non Composite");
while (// purge from possible previous error
!stk.empty()) stk.pop();
InputSource src = new InputSource(new ByteArrayInputStream(b));
reader.parse(src);
if (stk.empty())
throw new ISOException("error parsing");
ISOMsg m = (ISOMsg) c;
ISOMsg m1 = (ISOMsg) stk.pop();
m.merge(m1);
m.setHeader(m1.getHeader());
fixup(m, BINARY_FIELDS);
if (logger != null)
evt.addMessage(m);
return b.length;
} catch (ISOException e) {
evt.addMessage(e);
throw e;
} catch (IOException e) {
evt.addMessage(e);
throw new ISOException(e.toString());
} catch (SAXException e) {
evt.addMessage(e);
throw new ISOException(e.toString());
} finally {
Logger.log(evt);
}
}
Aggregations