@Test public void testLog() throws Throwable { BSHLogListener bSHLogListener = new BSHLogListener(); Configuration cfg = new SimpleConfiguration(new Properties()); bSHLogListener.setConfiguration(cfg); LogEvent ev = new LogEvent("testBSHLogListenerTag"); ev.setSource(new LogChannel()); LogEvent result = bSHLogListener.log(ev); assertSame(ev, result, "result"); assertSame(cfg, bSHLogListener.cfg, "bSHLogListener.cfg"); }
@Override 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()){ 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; } }
BSHLogListener implements org.jpos.util.LogListener, org.jpos.core.Configurable { @Override 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()){ 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; } } }
BSHLogListener implements org.jpos.util.LogListener, org.jpos.core.Configurable { @Override 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()){ 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; } } BSHLogListener(); }
BSHLogListener implements org.jpos.util.LogListener, org.jpos.core.Configurable { @Override 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()){ 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; } } BSHLogListener(); @Override void setConfiguration(org.jpos.core.Configuration cfg); @Override LogEvent log(LogEvent ev); }
BSHLogListener implements org.jpos.util.LogListener, org.jpos.core.Configurable { @Override 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()){ 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; } } BSHLogListener(); @Override void setConfiguration(org.jpos.core.Configuration cfg); @Override LogEvent log(LogEvent ev);  }