public static String info() { return info(1); } public static String info(int pos) {
private boolean validParam(Context ctx, Map.Entry<String, Pattern> entry, String value) { Pattern p = entry.getValue(); Matcher m = p.matcher(value); if (!m.matches()) { ctx.getResult().fail(ResultCode.BAD_REQUEST, Caller.info(), "Invalid param " + entry.getKey().toLowerCase()); return false; } return true; }
private void assertNoExtraFields (ISOMsg m, Set validFields, Result rc) { StringBuffer sb = new StringBuffer(); for (int i=1; i<=m.getMaxField(); i++) { // we start at 1, MTI is always valid String s = Integer.toString (i); if (m.hasField(i) && !validFields.contains (s)) { if (sb.length() > 0) sb.append (' '); sb.append (s); } } if (sb.length() > 0) rc.fail(CMF.EXTRA_FIELD, Caller.info(), sb.toString()); }
private boolean checkMandatoryPathParams (Context ctx) { Map<String,Object> pathParams = ctx.get(Constants.PATHPARAMS); for (Map.Entry<String,Pattern> entry : mandatoryPathParams.entrySet()) { Object v = pathParams.get(entry.getKey()); String value = v != null ? v.toString() : null; if (value == null) { ctx.getResult().fail(ResultCode.BAD_REQUEST, Caller.info(), "Mandatory param " + entry.getKey().toLowerCase() + " not present"); return false; } return validParam(ctx, entry, value); } return true; }
private boolean checkMandatoryQueryParams (Context ctx) { Map<String,Object> queryParams = ctx.get(Constants.QUERYPARAMS); for (Map.Entry<String,Pattern> entry : mandatoryQueryParams.entrySet()) { Object v = queryParams.get(entry.getKey()); String value = v != null ? v.toString() : null; if (value == null) { ctx.getResult().fail(ResultCode.BAD_REQUEST, Caller.info(), "Mandatory param " + entry.getKey().toLowerCase() + " not present"); return false; } return validParam(ctx, entry, value); } return true; }
private void putTimestamp (Context ctx, ISOMsg m, String key, int fieldNumber, boolean mandatory, Set<String> validFields, Result rc) { if (m.hasField(fieldNumber)) { String s = m.getString(fieldNumber); validFields.add(Integer.toString(fieldNumber)); if (TIMESTAMP_PATTERN.matcher(s).matches()) ctx.put (key, ISODate.parseISODate(s)); else rc.fail(CMF.INVALID_FIELD, Caller.info(), "Invalid %s '%s'", key, s); } else if (mandatory) { rc.fail(CMF.MISSING_FIELD, Caller.info(), TRANSMISSION_TIMESTAMP.toString()); } }
private void putPCode (Context ctx, ISOMsg m, boolean mandatory, Set<String> validFields, Result rc) { if (m.hasField(3)) { String s = m.getString(3); validFields.add("3"); if (PCODE_PATTERN.matcher(s).matches()) { ctx.put(ContextConstants.PCODE.toString(), m.getString(3)); } else rc.fail(CMF.INVALID_FIELD, Caller.info(), "Invalid PCODE '%s'", s); } else if (mandatory) { rc.fail(CMF.MISSING_FIELD, Caller.info(), "PCODE"); } }
private void putTid (Context ctx, ISOMsg m, boolean mandatory, Set<String> validFields, Result rc) { if (m.hasField(41)) { String s = m.getString(41); validFields.add("41"); if (TID_PATTERN.matcher(s).matches()) { ctx.put(ContextConstants.TID.toString(), m.getString(41)); } else rc.fail(CMF.INVALID_FIELD, Caller.info(), "Invalid TID '%s'", s); } else if (mandatory) { rc.fail(CMF.MISSING_FIELD, Caller.info(), "TID"); } }
private void putMid (Context ctx, ISOMsg m, boolean mandatory, Set<String> validFields, Result rc) { if (m.hasField(42)) { String s = m.getString(42); validFields.add("42"); if (MID_PATTERN.matcher(s).matches()) { ctx.put(ContextConstants.MID.toString(), m.getString(42)); } else rc.fail(CMF.INVALID_FIELD, Caller.info(), "Invalid MID '%s'", s); } else if (mandatory) { rc.fail(CMF.MISSING_FIELD, Caller.info(), "MID"); } } private void putTimestamp (Context ctx, ISOMsg m, String key, int fieldNumber, boolean mandatory, Set<String> validFields, Result rc) {
/** * puts an Object in the transient Map */ public void put (Object key, Object value) { if (trace) { getProfiler().checkPoint( String.format("%s='%s' [%s]", getKeyName(key), value, Caller.info(1)) ); } getMap().put (key, value); synchronized (this) { notifyAll(); } } /**
/** * puts an Object in the transient Map */ public void put (Object key, Object value, boolean persist) { if (trace) { getProfiler().checkPoint( String.format("%s(P)='%s' [%s]", getKeyName(key), value, Caller.info(1)) ); } if (persist && value instanceof Serializable) getPMap().put (key, value); getMap().put(key, value); }
private void putCaptureDate (Context ctx, ISOMsg m, boolean mandatory, Set<String> validFields, Result rc) { if (m.hasField(17)) { String s = m.getString(17); validFields.add("17"); if (CAPTUREDATE_PATTERN.matcher(s).matches()) ctx.put (CAPTURE_DATE.toString(), ISODate.parseISODate(s + "120000")); else rc.fail(CMF.INVALID_FIELD, Caller.info(), "Invalid %s '%s'", CAPTURE_DATE, s); } else if (mandatory) { rc.fail(CMF.MISSING_FIELD, Caller.info(), CAPTURE_DATE.toString()); } }
private void putOriginalDataElements (Context ctx, ISOMsg m, boolean mandatory, Set<String> validFields, Result rc) { String s = m.getString(56); if (s != null) { validFields.add("56"); if (ORIGINAL_DATA_ELEMENTS_PATTERN.matcher(s).matches()) { ctx.put (ORIGINAL_MTI.toString(), s.substring(0,4)); ctx.put (ORIGINAL_STAN.toString(), s.substring(4,16)); ctx.put (ORIGINAL_TIMESTAMP.toString(), ISODate.parseISODate (s.substring(16,30))); } else { rc.fail(CMF.INVALID_FIELD, Caller.info(), "Invalid %s '%s'", ORIGINAL_DATA_ELEMENTS, s); } } else if (mandatory) { rc.fail(CMF.MISSING_FIELD, Caller.info(), ContextConstants.ORIGINAL_DATA_ELEMENTS.toString()); } } }
private boolean checkOptionalJson (Context ctx) { for (Map.Entry<String,JsonSchema> entry : optionalJson.entrySet()) { String value = ctx.getString(entry.getKey()); ProcessingReport report; if (value != null) { try { JsonSchema schema = entry.getValue(); JsonNode node = JsonLoader.fromString(value); report = schema.validate(node); } catch(Exception ex) { ctx.getResult().fail(ResultCode.BAD_REQUEST, Caller.info(), ex.toString()); return false; } if (!report.isSuccess()) { ctx.getResult().fail(ResultCode.BAD_REQUEST, Caller.info(), report.toString()); return false; } } } return true; } }
public int prepare (long id, Serializable context) { Context ctx = (Context) context; Result rc = ctx.getResult(); try { ISOMsg m = (ISOMsg) ctx.get (request); if (m == null) { ctx.getResult().fail(CMF.INVALID_TRANSACTION, Caller.info(), "'%s' not available in Context", request); return ABORTED | NO_JOIN | READONLY; } Set<String> validFields = new HashSet<>(); assertFields (ctx, m, cfg.get ("mandatory", ""), true, validFields, rc); assertFields (ctx, m, cfg.get ("optional", ""), false, validFields, rc); assertNoExtraFields (m, validFields, rc); } catch (Throwable t) { rc.fail(CMF.SYSTEM_ERROR, Caller.info(), t.getMessage()); ctx.log(t); } return (rc.hasFailures() ? ABORTED : PREPARED) | NO_JOIN | READONLY; }
private void putPDC (Context ctx, ISOMsg m, boolean mandatory, Set<String> validFields, Result rc) { if (m.hasField(22)) { byte[] b = m.getBytes(22); validFields.add("22"); if (b.length != 16) { rc.fail( CMF.INVALID_FIELD, Caller.info(), "Invalid %s '%s'", ContextConstants.POS_DATA_CODE.toString(), ISOUtil.hexString(b) ); } else { ctx.put(ContextConstants.POS_DATA_CODE.toString(), PosDataCode.valueOf(m.getBytes(22))); } } else if (mandatory) { rc.fail(CMF.MISSING_FIELD, Caller.info(), ContextConstants.POS_DATA_CODE.toString()); } }
private void putAmount (Context ctx, ISOMsg m, boolean mandatory,Set<String> validFields, Result rc) { Object o4 = m.getComponent(4); Object o5 = m.getComponent(5); ISOAmount a4 = null; ISOAmount a5 = null; if (o4 instanceof ISOAmount) { a4 = (ISOAmount) o4; validFields.add("4"); } if (o5 instanceof ISOAmount) { a5 = (ISOAmount) o5; validFields.add("5"); } if (a5 != null) { ctx.put (AMOUNT.toString(), a5); if (a4 != null) { ctx.put (LOCAL_AMOUNT.toString(), a4); } } else if (a4 != null) { ctx.put (AMOUNT.toString(), a4); } if (mandatory && (a4 == null && a5 == null)) rc.fail(CMF.MISSING_FIELD, Caller.info(), ContextConstants.AMOUNT.toString()); }
@Test public void testInvalidSuccess() { Result rc = new Result(); try { rc.success(CMF.GENERAL_DECLINE, Caller.info(), "Invalid Success"); fail ("IllegalArgumentException should have been raised"); } catch (IllegalArgumentException ignored) { } }
@Test public void testInhibit() { Result rc = new Result(); rc.fail(CMF.INTERNAL_ERROR, Caller.info(), "Internal Error"); assertTrue(rc.hasInhibit()); }