public static void main(String[] args) {
    try {
      if (args.length < 3) {
        System.out.println("Usage: ebms-recv [config-xml] [log-path] [output folders] ");
        System.out.println();
        System.out.println(
            "Example: ebms-recv "
                + "./config/ebms-recv/ebms-request.xml "
                + "./logs/ebms-recv.log "
                + "./output/ebms-recv/ ");
        System.exit(1);
      }
      System.out.println("----------------------------------------------------");
      System.out.println("       EBMS Message Receiver           ");
      System.out.println("----------------------------------------------------");

      // Initalize the logger.
      System.out.println("Initialize Logger ... ");
      FileLogger logger = new FileLogger(new java.io.File(args[1]));

      // Initialize the query parameter.
      System.out.println("Importing  ebMS sending parameters ... " + args[0]);
      EBMSMessageData requestData =
          DataFactory.getInstance()
              .createEBMSMessageDataFromXML(
                  new PropertyTree(new java.io.File(args[0]).toURI().toURL()));

      // Initalize the receiver client for downloading available message.
      System.out.println("Initialize ebMS message receiver... ");
      EBMSMessageReceiver recvSender = new EBMSMessageReceiver(logger, requestData);
      recvSender.setOutputDirectory(args[2]);

      System.out.println(
          "Sending  ebMS receiving request ... for " + requestData.getMessageIdForReceive());
      recvSender.run();
      System.out.println();

      System.out.println("----------------------------------------------------");
      System.out.println();
      System.out.println("Please view logs for details .. ");
    } catch (Exception e) {
      e.printStackTrace(System.err);
    }
  }
  /** The main method is for CLI mode. */
  public static void main(String[] args) {
    try {
      if (args.length < 2) {
        System.out.println("Usage: message-status [config-xml] [log-path]");
        System.out.println();
        System.out.println(
            "Example: message-status ./config/message-status/ms-request.xml ./logs/message-status.log");
        System.exit(1);
      }
      System.out.println("----------------------------------------------------");
      System.out.println("        Message Status Web service query            ");
      System.out.println("----------------------------------------------------");

      // Initalize the logger.
      System.out.println("Initialize Logger ... ");
      FileLogger logger = new FileLogger(new java.io.File(args[1]));

      // Initialize the query parameter.
      System.out.println("Importing  query parameters ... ");
      MessageStatusRequestData msd =
          DataFactory.createMessageRequestStatusDataFromXML(
              new PropertyTree(new java.io.File(args[0]).toURI().toURL()));

      // Send the query.
      System.out.println("Sending    message status query ... ");
      MessageStatusSender sender = new MessageStatusSender(logger, msd);
      sender.run();

      System.out.println();
      System.out.println("                   Query Done:                      ");
      System.out.println("----------------------------------------------------");
      System.out.println("Number of records found: " + sender.getMessageStatusList().size());
      System.out.println();
      System.out.println("Please view log for detail .. ");

    } catch (Exception e) {
      e.printStackTrace(System.err);
    }
  }
  /** The main method is for CLI mode. */
  public static void main(String[] args) {
    try {
      if (args.length < 2) {
        System.out.println("Usage: as2-permitdl [config-xml] [log-path]");
        System.out.println();
        System.out.println(
            "Example: as2-permitdl "
                + "./config/as2-permitdl/as2-request.xml "
                + "./logs/as2-permitdl.log");
        System.exit(1);
      }
      System.out.println("----------------------------------------------------");
      System.out.println("           AS2 Permit Redownload Request Sender            ");
      System.out.println("----------------------------------------------------");

      // Initialize the logger.
      System.out.println("Initialize Logger ... ");
      FileLogger logger = new FileLogger(new java.io.File(args[1]));

      // Initialize the query parameter.
      System.out.println("Importing  AS2 Redownload Permition Request parameters ... " + args[0]);
      PermitRedownloadData data =
          DataFactory.getInstance()
              .createAS2PermitRedownloadDataFromXML(
                  new PropertyTree(new java.io.File(args[0]).toURI().toURL()));
      // Initialize the sender.
      System.out.println("Initialize AS2 Permit Redownload Request ... ");
      AS2PermitRedownloadSender sender = new AS2PermitRedownloadSender(logger, data);

      System.out.println("Sending AS2 Redownload Permition Request ... ");
      sender.run();

      System.out.println("Please view log for details .. ");

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  /** The main method is for CLI mode. */
  public static void main(String[] args) {
    try {
      java.io.PrintStream out = System.out;

      if (args.length < 2) {
        out.println("Usage: as2-envelop [config-xml] [log-path]");
        out.println();
        out.println(
            "Example: as2-envelop ./config/as2-envelop/as2-request.xml ./logs/as2-envelop.log");
        System.exit(1);
      }

      out.println("------------------------------------------------------");
      out.println("       AS2 Envelop Queryer       ");
      out.println("------------------------------------------------------");

      // Initialize the logger.
      out.println("Initialize logger .. ");
      // The logger path is specified at the last argument.
      FileLogger logger = new FileLogger(new File(args[args.length - 1]));

      // Initialize the query parameter.
      out.println("Importing AS2 administrative sending parameters ... ");
      AS2AdminData acd =
          DataFactory.getInstance()
              .createAS2AdminDataFromXML(new PropertyTree(new File(args[0]).toURI().toURL()));

      boolean historyQueryNeeded = false;
      AS2MessageHistoryRequestData queryData = new AS2MessageHistoryRequestData();
      if (acd.getMessageIdCriteria() == null || acd.getMessageIdCriteria().trim().equals("")) {

        historyQueryNeeded = true;

        // print command prompt
        out.println("No messageID was specified!");
        out.println("Start querying message repositry ...");

        String endpoint = acd.getEnvelopQueryEndpoint();
        String host = endpoint.substring(0, endpoint.indexOf("/corvus"));
        host += "/corvus/httpd/as2/msg_history";
        queryData.setEndPoint(host);
      } /*
        	If the user has entered message id but no messagebox,
        	using the messageid as serach criteria and as
        	user to chose his target message
        */ else if (acd.getMessageBoxCriteria() == null
          || acd.getMessageBoxCriteria().trim().equals("")) {

        historyQueryNeeded = true;

        // print command prompt
        out.println("Message Box value haven't specified.");
        out.println(
            "Start query message whcih matched with messageID: " + acd.getMessageIdCriteria());

        String endpoint = acd.getEnvelopQueryEndpoint();
        String host = endpoint.substring(0, endpoint.indexOf("/corvus"));
        host += "/corvus/httpd/as2/msg_history";

        queryData.setEndPoint(host);
        queryData.setMessageId(acd.getMessageIdCriteria());
      }
      // Debug Message
      System.out.println("history Endpoint: " + queryData.getEndPoint());
      System.out.println("Repositry Endpoint: " + acd.getEnvelopQueryEndpoint());

      if (historyQueryNeeded) {
        List msgList = listAvailableMessage(queryData, logger);

        if (msgList == null || msgList.size() == 0) {
          out.println();
          out.println();
          out.println("No stream data found in repositry...");
          out.println("Please view log for details .. ");
          return;
        }

        int selection = promptForSelection(msgList);

        if (selection == -1) {
          return;
        }

        String messageID = (String) ((List) msgList.get(selection)).get(0);
        String messageBox = (String) ((List) msgList.get(selection)).get(1);
        acd.setMessageIdCriteria(messageID);
        acd.setMessageBoxCriteria(messageBox.toUpperCase());
        out.println();
        out.println();
        out.println("Start download targeted message envelop ...");
      }

      // Initialize the sender.
      out.println("Initialize AS2 HTTP data service client... ");
      AS2EnvelopQuerySender sender = new AS2EnvelopQuerySender(logger, acd);

      out.println("Sending    AS2 HTTP Envelop Query request ... ");
      sender.run();

      out.println();
      out.println("                    Sending Done:                   ");
      out.println("----------------------------------------------------");
      out.println("The Message Envelope : ");
      InputStream eins = sender.getEnvelopStream();
      if (eins.available() == 0) {
        out.println("No stream data found.");
        out.println(
            "The message envelop does not exist for message id "
                + sender.getMessageIdToDownload()
                + " and message box "
                + sender.getMessageBoxToDownload());
      } else IOHandler.pipe(sender.getEnvelopStream(), out);

      out.println("Please view log for details .. ");
    } catch (Exception e) {
      e.printStackTrace(System.err);
    }
  }