示例#1
0
  /**
   * Show details about the request
   *
   * @param servlet used to get teh servlet context, may be null
   * @param req the request
   * @return string showing the details of the request.
   */
  public static String showRequestDetail(HttpServlet servlet, HttpServletRequest req) {
    StringBuilder sbuff = new StringBuilder();

    sbuff.append("Request Info\n");
    sbuff.append(" req.getServerName(): ").append(req.getServerName()).append("\n");
    sbuff.append(" req.getServerPort(): ").append(req.getServerPort()).append("\n");
    sbuff.append(" req.getContextPath:").append(req.getContextPath()).append("\n");
    sbuff.append(" req.getServletPath:").append(req.getServletPath()).append("\n");
    sbuff.append(" req.getPathInfo:").append(req.getPathInfo()).append("\n");
    sbuff.append(" req.getQueryString:").append(req.getQueryString()).append("\n");
    sbuff
        .append(" getQueryStringDecoded:")
        .append(EscapeStrings.urlDecode(req.getQueryString()))
        .append("\n");
    /*try {
      sbuff.append(" getQueryStringDecoded:").append(URLDecoder.decode(req.getQueryString(), "UTF-8")).append("\n");
    } catch (UnsupportedEncodingException e1) {
      e1.printStackTrace();
    }*/
    sbuff.append(" req.getRequestURI:").append(req.getRequestURI()).append("\n");
    sbuff.append(" getRequestBase:").append(getRequestBase(req)).append("\n");
    sbuff.append(" getRequestServer:").append(getRequestServer(req)).append("\n");
    sbuff.append(" getRequest:").append(getRequest(req)).append("\n");
    sbuff.append("\n");

    sbuff.append(" req.getPathTranslated:").append(req.getPathTranslated()).append("\n");
    String path = req.getPathTranslated();
    if ((path != null) && (servlet != null)) {
      ServletContext context = servlet.getServletContext();
      sbuff.append(" getMimeType:").append(context.getMimeType(path)).append("\n");
    }
    sbuff.append("\n");
    sbuff.append(" req.getScheme:").append(req.getScheme()).append("\n");
    sbuff.append(" req.getProtocol:").append(req.getProtocol()).append("\n");
    sbuff.append(" req.getMethod:").append(req.getMethod()).append("\n");
    sbuff.append("\n");
    sbuff.append(" req.getContentType:").append(req.getContentType()).append("\n");
    sbuff.append(" req.getContentLength:").append(req.getContentLength()).append("\n");

    sbuff.append(" req.getRemoteAddr():").append(req.getRemoteAddr());
    try {
      sbuff
          .append(" getRemoteHost():")
          .append(java.net.InetAddress.getByName(req.getRemoteHost()).getHostName())
          .append("\n");
    } catch (java.net.UnknownHostException e) {
      sbuff.append(" getRemoteHost():").append(e.getMessage()).append("\n");
    }
    sbuff.append(" getRemoteUser():").append(req.getRemoteUser()).append("\n");

    sbuff.append("\n");
    sbuff.append("Request Parameters:\n");
    Enumeration params = req.getParameterNames();
    while (params.hasMoreElements()) {
      String name = (String) params.nextElement();
      String values[] = req.getParameterValues(name);
      if (values != null) {
        for (int i = 0; i < values.length; i++) {
          sbuff
              .append("  ")
              .append(name)
              .append("  (")
              .append(i)
              .append("): ")
              .append(values[i])
              .append("\n");
        }
      }
    }
    sbuff.append("\n");

    sbuff.append("Request Headers:\n");
    Enumeration names = req.getHeaderNames();
    while (names.hasMoreElements()) {
      String name = (String) names.nextElement();
      Enumeration values = req.getHeaders(name); // support multiple values
      if (values != null) {
        while (values.hasMoreElements()) {
          String value = (String) values.nextElement();
          sbuff.append("  ").append(name).append(": ").append(value).append("\n");
        }
      }
    }
    sbuff.append(" ------------------\n");

    return sbuff.toString();
  }
示例#2
0
  protected void doWatchInputDir() throws Exception, IOException {

    final String sInputDirToWatch = Consts.getInputWatchDirectory();
    final String sFileExtToWatch = Consts.getInputWatchDirectoryFileExtension();
    final String sInputTempDir = Consts.getInputTempDirectory();
    final String sInputArchiveDir = Consts.getInputArchiveDirectory();

    /** JEFF */
    String servername = "";
    try {
      servername = java.net.InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
      e.printStackTrace();
    }

    Properties properties = new Properties();

    try {
      String fileName = "Connector.properties";
      InputStream inputStream = getClass().getResourceAsStream(fileName);

      properties.load(inputStream);
    } catch (IOException e) {
    }

    int iServerNum =
        Integer.parseInt(properties.getProperty("connector." + servername + ".servernum"));

    final String sInputLineDir = Consts.getInputLineDirectory();
    final String sInputLineDirToWatch = sInputLineDir + iServerNum;
    final String sInputLineTempDir =
        sInputLineDirToWatch + Consts.PATH_SEPARATOR + Consts.ATS_INPUT_LINE_TEMP_DIR;
    /** JEFF End */

    // fire up the watcher
    // TimerTask task = new DirWatcher(sInputDirToWatch, sFileExtToWatch)
    TimerTask task =
        new DirWatcher(sInputLineDirToWatch, sFileExtToWatch, iServerNum) {
          protected void onChange(File file, String action, BufferedOutputStream log) {
            // here we code the action on a change - only process add situations
            if (action.equalsIgnoreCase(Consts.FILE_ACTION_ADD)) {
              try {
                pgpTempFile = null;

                // Load up the BouncyCastle Crypto engine
                Security.addProvider(new BouncyCastleProvider());
                // get the incoming file name
                String sOrigFileName = file.getName();

                // archive the original
                File archiveInputFile = new File(sInputArchiveDir, file.getName());
                FileUtils.writeLog("Archiving Original File - " + file.getName(), log);
                FileUtils.fileCopy(file, archiveInputFile);

                // open the file and decrypt to temp directory
                Reader reader = new Reader();

                FileUtils.writeLog("Unencrypting File - " + file.getName(), log);
                // pgpTempFile = reader.Open(file, sInputTempDir, sOrigFileName);
                pgpTempFile = reader.Open(file, sInputLineTempDir, sOrigFileName); // JEFF

                // rename the decrypted file to the original output
                pgpTempFile =
                    reader.Rename(
                        pgpTempFile,
                        sOrigFileName); // needed as the fileSplitter looks at the file name to
                // determine how to process.

                // process the unencrypted pgpTempFile
                EmployeeImport empImp = new EmployeeImport();
                empImp.doProcess(pgpTempFile.getName(), log);
              } catch (Exception e) {
                try {
                  FileUtils.writeLog("Exception in doWatchInputDir(): " + e.toString(), log);
                  FileUtils.writeLog(
                      "Exception in doWatchInputDir() Stack Trace: " + FileUtils.getStackTrace(e),
                      log);
                  // TODO - need to find a way to notify this error
                } catch (Exception ex) {
                  ex.printStackTrace();
                }
              } finally {
                if (pgpTempFile != null) {
                  pgpTempFile.delete();
                }
                file.delete();
              }
            }
          }
        };

    Timer timer = new Timer();
    //        timer.schedule( task , new Date(), 10000);

    // run every hour at 50 minutes to give time for filemover to move it (filemover runs at *:40)
    // once per hour - in milliseconds
    long ONCE_PER_HOUR = 1000 * 60 * 60;

    // set this to current hour 59 minutes
    Calendar rightNow = new GregorianCalendar();
    rightNow.set(Calendar.MINUTE, 00);
    rightNow.set(Calendar.SECOND, 30);

    timer.scheduleAtFixedRate(task, rightNow.getTime(), ONCE_PER_HOUR);
  }