示例#1
0
 public String transform(String message) {
   String rv = message;
   try {
     log.debug("in=" + message);
     // decode the message
     org.jengine.tools.hl7.Message msg =
         org.jengine.tools.hl7.Message.read(new java.io.StringReader(message));
     // pass the decoded message to beanshell
     interpreter.eval("org.jengine.tools.hl7.Message message");
     interpreter.set("message", msg);
     // pass the logging category to beanshell
     interpreter.eval("org.apache.log4j.Category log");
     interpreter.set("log", log);
     // call the script
     interpreter.eval(script);
     // encode the possibly modified message
     java.io.StringWriter sw = new java.io.StringWriter();
     msg.write(sw);
     rv = sw.toString();
     log.debug("out=" + rv);
   } catch (Exception e) {
     log.error("Problem processing transformation", e);
   }
   return rv;
 }
示例#2
0
  private void redirectToPrevUrl(String homePage) throws UnsupportedEncodingException, IOException {
    String prevURLobject = (String) request.getSession().getAttribute(ClientConstants.loginRequest);
    String prevURL = null;

    // if you are in an application and your session expired, when you click
    // there the next time the login
    // page will appear and then you will be redirected to the page you HAD
    // OPEN
    //
    // but if you log out , the prev page is logOut so you are sent back
    // || !page.equalsIgnoreCase("logout"))
    if (prevURLobject == null || prevURLobject.indexOf("logout") != -1) {
      prevURL = ClientConstants.servletPage;
      log.info("prevURL was null");
    } else {
      prevURL = prevURLobject;
      log.info("prevURL " + prevURL);
    }

    if (prevURL.length() > 0) {
      log.info("About to redirect to " + prevURL);
      Command.redirectToURL(request, response, prevURL);
    } else {
      Command.redirectToURL(request, response, homePage);
    }
  }
  public static synchronized IdentifierExpertSystem instance() {
    if (chemistryKernel == null) {
      if (logger.isDebugEnabled()) {
        logger.debug("Getting " + IdentifierExpertSystem.class.getName() + " instance.");
      }

      chemistryKernel = new IdentifierExpertSystem();
    }

    return chemistryKernel;
  }
  /**
   * Description of the Method
   *
   * @return Description of the Return Value
   */
  public static synchronized BasicResidueData instance() {
    if (residueData == null) {
      if (logger.isDebugEnabled()) {
        logger.debug("Getting " + BasicResidueData.class.getName() + " instance.");
      }

      residueData = new BasicResidueData();
    }

    return residueData;
  }
示例#5
0
  public LogP() {
    if (logger.isDebugEnabled()) {
      logger.debug("Initialize " + this.getClass().getName());
    }

    descInfo =
        FeatureHelper.generateFeatureInfo(
            this.getClass(),
            BasicFeatureInfo.TYPE_NO_COORDINATES,
            null,
            "joelib2.feature.result.DoubleResult");
  }
  /*
   * Only current solution available to detect
   * if log4j is truly configured.
   */
  private static boolean isLog4jConfigured() {
    Enumeration en = org.apache.log4j.LogManager.getRootLogger().getAllAppenders();

    if (!(en instanceof org.apache.log4j.helpers.NullEnumeration)) {
      return true;
    } else {
      Enumeration cats = Category.getCurrentCategories();
      while (cats.hasMoreElements()) {
        Category c = (Category) cats.nextElement();
        if (!(c.getAllAppenders() instanceof org.apache.log4j.helpers.NullEnumeration)) return true;
      }
    }
    return false;
  }
示例#7
0
  /** See if the data was correctly added. */
  public void verifyDataTest() {
    int iCount = 0;
    cat.debug("Count records.\n");
    try {
      //          testTable.setKeyArea(Constants.MAIN_KEY_AREA);
      iCount = 0;
      testTable.close();
      while (testTable.hasNext()) {
        testTable.next();
        cat.debug(record.toString());
        iCount++;
        this.verifyRecord(record, iCount);
        assertTrue(((Integer) record.getField(0).getData()).intValue() == iCount);
      }
    } catch (Exception e) {
      fail("Record count error");
    }
    assertTrue(iCount == 6);

    cat.debug("Count records backwards.\n");
    iCount = 6;
    try {
      //          testTable.setKeyArea(Constants.MAIN_KEY_AREA);
      testTable.close();
      while (testTable.hasPrevious()) {
        testTable.previous();
        this.verifyRecord(record, iCount);
        cat.debug(record.toString());
        assertTrue(((Integer) record.getField(0).getData()).intValue() == iCount);
        iCount--;
      }
    } catch (Exception e) {
      fail("Record count error");
    }
    //      assertTrue(iCount == 0);

    cat.debug("Seek records.\n");
    iCount = 1;
    try {
      //          testTable.setKeyArea(Constants.MAIN_KEY_AREA);
      while (iCount < 10) {
        record.getField(0).setData(new Integer(iCount));
        boolean bSuccess = testTable.seek("=");
        if (bSuccess) {
          assertTrue(iCount <= 6);
          this.verifyRecord(record, iCount);
          cat.debug(record.toString());
          assertTrue(((Integer) record.getField(0).getData()).intValue() == iCount);
        } else {
          cat.debug("" + iCount);
          cat.debug(record.toString());
          assertTrue(iCount > 6);
        }
        iCount++;
      }
    } catch (Exception e) {
      fail("Record count error");
    }
  }
  public static IShawnProcess create() throws Exception {
    log.debug("Creating shawn instance with default values");

    IShawnProcess s = null;

    if (defaultValues.isDryRun()) {
      log.info("Creating dry run shawn instance");
      s = new DryRunShawnProcess();
    } else {
      log.info("Creating local process shawn instance");
      s = new ShawnProcess(defaultValues.getShawnExecutable(), defaultValues.getWorkDir());
    }
    shawns.add(s);
    return s;
  }
示例#9
0
  /** Process the start tag */
  public int doStartTag() throws javax.servlet.jsp.JspException {

    // Look up the requested property value
    if (name != null) {
      Object beanValue = RequestUtils.lookup(pageContext, name, property, scope);
      if (cat.isDebugEnabled()) cat.debug("Value is : '" + beanValue + "'");
      if (beanValue == null) return (EVAL_BODY_TAG);

      // set the property as value
      setValue(beanValue.toString());
    }

    // Continue processing this page
    return (EVAL_BODY_TAG);
  }
public class RETSServerInformationTransaction extends RETSTransaction {
  /** */
  private static final long serialVersionUID = 9214592476498826752L;

  static Category cat = Category.getInstance(RETSServerInformationTransaction.class);
  String version = null;

  /** constructor */
  public RETSServerInformationTransaction() {
    super();
    setRequestType("ServerInformation");
  }

  public void setResource(String str) {
    setRequestVariable("Resource", str);
  }

  public void setInfoClass(String str) {
    setRequestVariable("Class", str);
  }

  public void setStandardNames(String str) {
    setRequestVariable("StandardNames", str);
  }

  public void setVersion(String version) {
    this.version = version;
  }

  public String getVersion() {
    return version;
  }
}
public class Log4JTest {
  // Create a category instance for this class
  static Category cat = Category.getInstance(Log4JTest.class.getName());

  public static void main(String[] args) {
    // Ensure to have all necessary drivers installed !
    try {
      Driver d = (Driver) (Class.forName("oracle.jdbc.driver.OracleDriver").newInstance());
      DriverManager.registerDriver(d);
    } catch (Exception e) {
    }

    // Set the priority which messages have to be logged
    cat.setPriority(Priority.INFO);

    // Configuration with configuration-file
    PropertyConfigurator.configure("log4jtestprops.txt");

    // These messages with Priority >= setted priority will be logged to the database.
    cat.debug("debug"); // this not, because Priority DEBUG is less than INFO
    cat.info("info");
    cat.error("error");
    cat.fatal("fatal");
  }
}
示例#12
0
  public sf.inventory.HargaJual getLatestHargaJual(String kbarang, String tglBukti)
      throws DAException {
    try {
      String strSQL =
          "SELECT a.*,b.nbarang,b.satuan FROM mhjual a,mproduk b where a.recstatus<>? and a.kbarang=b.kbarang and a.kbarang=? and a.ktanggal <=? order by a.ktanggal desc LIMIT 0,1";
      log.info(strSQL + "[0]" + kbarang + ",[1]" + tglBukti);
      PreparedStatement p = db.getStatement(strSQL);
      p.setString(1, "D");
      p.setString(2, kbarang);
      p.setString(3, tglBukti);
      Vector rows = db.getData(p);
      Vector v = (Vector) rows.get(0);
      sf.inventory.HargaJual item = new sf.inventory.HargaJual();
      item.setKbarang(v.get(0).toString());
      item.setKtanggal(v.get(1).toString());
      item.setKvaluta(v.get(2).toString());
      item.setNvaluta(Double.parseDouble(v.get(3).toString()));
      item.setPotongan(Double.parseDouble(v.get(4).toString()));

      item.setRecstatus(v.get(5).toString());
      item.setTglupdate(Long.parseLong(v.get(6).toString()));
      item.setUserupdate(v.get(7).toString());
      item.setNbarang(v.get(8).toString());
      item.setSatuan(v.get(9).toString());
      return item;
    } catch (Exception ex) {
      throw new DAException(ex.getLocalizedMessage());
    }
  }
  public void addHardCodedKernel(IdentifierHardDependencies hardCodedKernel) {
    String kernelString =
        hardCodedKernel.getClass().getName()
            + " "
            + hardCodedKernel.getVendorInternal()
            + " "
            + hardCodedKernel.getReleaseVersionInternal()
            + " "
            + hardCodedKernel.getReleaseDateInternal();

    if (logger.isDebugEnabled()) {
      logger.debug("hard dependencies: " + kernelString);
    }

    hardInfos.put(CML_HARD_KERNEL + ":" + hardCodedKernel.getClass().getName(), kernelString);
  }
 private void redirectDuoAuth(
     Principal principal,
     HttpServletRequest httpServletRequest,
     HttpServletResponse httpServletResponse,
     String contextPath)
     throws java.io.IOException {
   // Redirect to servlet if we can.  If the request is committed,
   // we can't, possibly because there's already a redirection in
   // progress; this is what Seraph's SecurityFilter does.
   if (!httpServletResponse.isCommitted()) {
     String sigRequest = DuoWeb.signRequest(ikey, skey, akey, principal.getName());
     final String originalURL =
         contextPath
             + httpServletRequest.getServletPath()
             + (httpServletRequest.getPathInfo() == null ? "" : httpServletRequest.getPathInfo())
             + (httpServletRequest.getQueryString() == null
                 ? ""
                 : "?" + httpServletRequest.getQueryString());
     String qs;
     String redirectUrl;
     qs = DUO_REQUEST_KEY + "=" + URLEncoder.encode(sigRequest, "UTF-8");
     qs = qs + "&" + DUO_HOST_KEY + "=" + URLEncoder.encode(host, "UTF-8");
     qs = qs + "&" + DUO_ORIGINAL_URL_KEY + "=" + URLEncoder.encode(originalURL, "UTF-8");
     redirectUrl = contextPath + loginUrl + "?" + qs;
     httpServletResponse.sendRedirect(redirectUrl);
   } else {
     log.warn("Could not redirect to Duo auth page.");
   }
 }
示例#15
0
 @Override
 public LinkedList<ShawnResult> runCommand(String cmd, String params) {
   String cmdLine = toCommandLine(cmd, params);
   storeCommandInHistory(cmdLine);
   log.debug("Sending line to shawn: " + cmdLine);
   return new LinkedList<ShawnResult>();
 }
示例#16
0
 /**
  * Returns complete composite object, if applicable, by searching the database key on the <code>
  * List</code> object of <code>PersistentObject</code>s that contains an encoded key (<code>
  * PersistentObject.getEncodedKey()</code>).
  *
  * @param list <code>List</code> of objects to search.
  * @param encodedKey key obtained via <code>PersistentObject.getEncodedKey()</code>.
  * @return object that matches encoded key or <code>null</code> if not found.
  * @see net.sf.jrf.domain.PersistentObject#getEncodedKey()
  * @see #findIndexByKey(List,String)
  */
 public PersistentObject findByKey(List list, String encodedKey) {
   PersistentObject po = getPoInList(list, encodedKey);
   if (po == null) {
     LOG.error("findByKey(List," + encodedKey + ") called without key on the list.");
     return null;
   }
   return findByKey(po);
 }
  /**
   * Method addKeyStore
   *
   * @param keyStore
   */
  public void add(KeyStore keyStore) {

    try {
      this.add(new KeyStoreResolver(keyStore));
    } catch (StorageResolverException ex) {
      cat.error("Could not add KeyStore because of: ", ex);
    }
  }
示例#18
0
  /**
   * Get all log classes names
   *
   * @return
   */
  public static Map<String, Object> getLogClasses() {
    SortedMap<String, Object> loggers = new TreeMap<String, Object>();
    Map<String, Object> res =
        Objects.newHashMap(
            "level",
            LogManager.getRootLogger().getLevel().toString().toUpperCase(),
            "loggers",
            loggers);

    Enumeration<Category> en = LogManager.getCurrentLoggers();
    while (en.hasMoreElements()) {
      Category e = en.nextElement();
      loggers.put(e.getName(), e.getEffectiveLevel().toString().toUpperCase());
    }

    return res;
  }
 static {
   try {
     _address = InetAddress.getLocalHost();
   } catch (java.net.UnknownHostException e) {
     cat.fatal("ERROR: unable to get localhost information.  UUIDs will not be unique.", e);
     System.exit(-1);
   }
 }
示例#20
0
/** archives and removes a project from the framework */
public class RemoveAction extends BaseAction {
  static Category logger = Category.getInstance(CreateAction.class.getName());

  private final StringBuffer unsetupArgs = new StringBuffer();

  /**
   * Create a new RemoveAction and parse the arguments from a {@link
   * org.apache.commons.cli.CommandLine}
   *
   * @param main
   * @param framework
   * @param cli
   */
  public RemoveAction(final CLIToolLogger main, final Framework framework, final CommandLine cli) {
    this(main, framework, BaseAction.parseBaseActionArgs(cli));
  }

  /**
   * Create a new RemoveAction with argument specifiers
   *
   * @param main
   * @param framework framework object
   * @param baseArgs base args
   * @param args RemoveAction args
   */
  public RemoveAction(
      final CLIToolLogger main, final Framework framework, final BaseActionArgs baseArgs) {
    super(main, framework, baseArgs);
    initArgs();
  }

  private void initArgs() {
    unsetupArgs.append("-name ");
    unsetupArgs.append(project.getFrameworkProject());
  }

  /**
   * Execute the action.
   *
   * @throws Throwable
   */
  public void exec() throws Throwable {
    //        super.exec();
    //        if (project == null) {
    //            throw new IllegalStateException("project was null");
    //        }
    //        if
    // (!framework.getFrameworkProjectMgr().existsFrameworkProject(project.getFrameworkProject())) {
    //            throw new ProjectToolException("project does not exists: " +
    // project.getFrameworkProject());
    //        }
    //        main.verbose("removing project: " + project.getFrameworkProject());
    //        final FrameworkProject d =
    // framework.getFrameworkProjectMgr().createFrameworkProject(project.getFrameworkProject());

    throw new RuntimeException("unimplemented: RemoveAction.exec");
  }
}
示例#21
0
public class ItemMetaData implements Serializable, ItemMetaDataIfc {
  static Category errorLogger = Category.getInstance("errorLogger");

  private static final long serialVersionUID = 7526471155622776147L;

  private Long id;
  private ItemDataIfc item;
  private String label;
  private String entry;

  public ItemMetaData() {}

  public ItemMetaData(ItemDataIfc item, String label, String entry) {
    this.item = item;
    this.label = label;
    this.entry = entry;
  }

  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public ItemDataIfc getItem() {
    return item;
  }

  public void setItem(ItemDataIfc item) {
    this.item = item;
  }

  public String getLabel() {
    return label;
  }

  public void setLabel(String label) {
    this.label = label;
  }

  public String getEntry() {
    return entry;
  }

  public void setEntry(String entry) {
    this.entry = entry;
  }

  private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();
  }

  private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
  }
}
示例#22
0
public class EchoBean implements SessionBean {
  private static final Category log = Category.getInstance(EchoBean.class);
  private SessionContext sessionCtx;

  public void ejbCreate() {
    log.debug("ejbCreate: ");
  }

  public void ejbLoad() {
    log.debug("ejbLoad");
  }

  public void ejbRemove() {
    log.debug("ejbRemove");
  }

  public void ejbStore() {
    log.debug("ejbStore");
  }

  public void setSessionContext(SessionContext context) {
    sessionCtx = context;
    log.debug("setSessionContext");
  }

  public void unsetSessionContext() {
    sessionCtx = null;
    log.debug("unsetSessionContext");
  }

  public void ejbActivate() {
    log.debug("ejbActivate");
  }

  public void ejbPassivate() {
    log.debug("ejbPassivate");
  }

  public String echo(String arg) {
    log.info("echo, arg=" + arg);
    try {
      InitialContext ctx = new InitialContext();
      Object ref = ctx.lookup("java:comp/env/ra/DirContextFactory");
      log.info("echo, ra/DirContextFactory=" + ref);

      DirContextFactory dcf = (DirContextFactory) ref;
      log.info("echo, found dcf=" + dcf);

      DirContext dc = dcf.getConnection();
      log.info("echo, lookup dc=" + dc);

      dc.close();
    } catch (NamingException e) {
      log.error("Failed during JNDI access", e);
    }
    return arg;
  }
}
  public void addSoftCodedKernel(IdentifierSoftDependencies softCodedKernel) {
    String kernelString =
        softCodedKernel.getClass().getName()
            + " "
            + softCodedKernel.getVendorExternal()
            + " "
            + softCodedKernel.getResourceExternal()
            + " "
            + softCodedKernel.getReleaseVersionExternal()
            + " "
            + softCodedKernel.getReleaseDateExternal();

    if (logger.isDebugEnabled()) {
      logger.debug("soft dependencies : " + kernelString);
    }

    softInfos.put(CML_SOFT_KERNEL + ":" + softCodedKernel.getClass().getName(), kernelString);
  }
示例#24
0
  public String echo(String arg) {
    log.info("echo, arg=" + arg);
    try {
      InitialContext ctx = new InitialContext();
      Object ref = ctx.lookup("java:comp/env/ra/DirContextFactory");
      log.info("echo, ra/DirContextFactory=" + ref);

      DirContextFactory dcf = (DirContextFactory) ref;
      log.info("echo, found dcf=" + dcf);

      DirContext dc = dcf.getConnection();
      log.info("echo, lookup dc=" + dc);

      dc.close();
    } catch (NamingException e) {
      log.error("Failed during JNDI access", e);
    }
    return arg;
  }
 protected void tearDown() throws Exception {
   // Required to prevent each message being logged once for each test
   // that has run in the past - this generates a huge log output and
   // seems to crash JUnit reporting with an OutOfMemoryError.
   // Maybe we should put this in the servlet destroy() but the version of
   // Servlet Unit we are using has no way to shut down servlets - later
   // versions do appear to have this.
   Category.shutdown();
   super.tearDown();
 }
 public synchronized String getNewUUID() {
   UID uid = new UID();
   String s = "";
   if (_address != null) {
     byte[] b = _address.getAddress();
     for (int i = 0; i < b.length; i++) s += (new Byte(b[i])).longValue() + "-";
   }
   s += uid.toString();
   cat.debug("new UUID: " + s);
   return s;
 }
示例#27
0
 public static String stackTrace(Throwable t) {
   StringWriter sw = new StringWriter();
   t.printStackTrace(new PrintWriter(sw));
   String s = sw.toString();
   try {
     sw.close();
   } catch (IOException e) {
     cat.error("::stackTrace - cannot close the StringWriter object", e);
   }
   return s;
 }
示例#28
0
 /**
  * This method returns all attributes of a given Classifier, including inherited
  *
  * @param classifier the classifier you want to have the attributes for
  * @return a collection of the attributes
  */
 public Collection getAttributesInh(MClassifier classifier) {
   Collection result = new ArrayList();
   result.addAll(getAttributes(classifier));
   Iterator parents = classifier.getParents().iterator();
   while (parents.hasNext()) {
     MClassifier parent = (MClassifier) parents.next();
     cat.debug("Adding attributes for: " + parent);
     result.addAll(getAttributesInh(parent));
   }
   return result;
 }
  private String preauthWithRetries(int num_tries, Principal principal)
      throws javax.servlet.ServletException {
    // Check if Duo authentication is even necessary by calling preauth
    for (int i = 0; ; i++) {
      try {
        Response preAuthResponse = sendPreAuthRequest(principal.getName());
        int statusCode = preAuthResponse.code();
        if (statusCode / 100 == 5) {
          if (failOpen) {
            log.warn("Duo 500 error. Fail open for user:"******"FAILOPEN";
          }
        }

        // parse response
        JSONObject json = new JSONObject(preAuthResponse.body().string());
        if (!json.getString("stat").equals("OK")) {
          throw new ServletException(
              "Duo error code (" + json.getInt("code") + "): " + json.getString("message"));
        }
        String result = json.getJSONObject("response").getString("result");
        if (result.equals("allow")) {
          log.info("Duo 2FA bypass for user:"******"ALLOW";
        }
        break;
      } catch (java.io.IOException e) {
        if (i >= MAX_TRIES - 1) {
          if (failOpen) {
            log.warn("Duo server unreachable. Fail open for user:"******"FAILOPEN";
          } else {
            throw new ServletException(e);
          }
        }
      } catch (Exception e) {
        throw new ServletException(e);
      }
    }
    return "AUTH";
  }
示例#30
0
 /**
  * Returns the bytes per character used for the given characterset in oracle
  *
  * @param charset charset to query
  * @return bytes per character
  */
 private int getBytes_per_Character(String charset) {
   // see
   // http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/server.817/a76966/appa.htm#958278
   OracleCharsets ocharsets = new OracleCharsets();
   try {
     return ocharsets.getBytes_per_charset(charset);
   } catch (UndefinedCharSetException ex) {
     // for undefined charsets return 1 (request for any better solution)
     LOG.info("Character set " + charset + " is unknown; assumming 1 byte per character.");
     return 1;
   }
 }