/**
   * the following mesg param will be filled by client "ClientName" - Client name (shop no)
   * "LocalVersion" - Version in mysql.appsetting."localversion" "AppVersion" - what client about
   * dialog shows
   */
  public void onMessage(SessionMsg msg) {
    String clientName = msg.getParam("ClientName");
    boolean shouldNotify = checkShouldNotifyLatestVersion(clientName);
    logger.debug(
        "UpdateActivePOS request from "
            + clientName
            + ", whose local version:"
            + msg.getParam("LocalVersion"));
    // yfzhu added 2003-11-09 to insert table poslog
    notifyClientStatus(clientName, "LocalVersion", msg.getParam("LocalVersion"));

    SessionMsg out = new SessionMsg(sessionMsgPrefix);
    JabberChatMessage jcm = msg.getOrigionalJabberMessage();

    out.setParentMsgID(msg.getID());
    out.setThreadID(msg.getThreadID());
    if (shouldNotify) {
      out.addParam("LatestVersion", lastestVersion);
      out.addParam("DownloadURL", downloadURL);
      out.addParam("FileCheckSum", checkSum);
      out.addParam("FileLength", fileLength);
      //        out.addParam("CVSROOT",cvsRoot);
      out.addParam("CVSPOSModule", cvsPOSModule);
      out.addParam("CVSPassword", cvsPassword);
      out.addParam("CVSRecentUpdateTime", getCVSRecentUpdateTime());
    } else {
      out.addParam("LatestVersion", "1");
      out.addParam("DownloadURL", "");
      out.addParam("FileCheckSum", "");
      out.addParam("FileLength", "0");
      //        out.addParam("CVSROOT",cvsRoot);
      out.addParam("CVSPOSModule", cvsPOSModule);
      out.addParam("CVSPassword", cvsPassword);
      out.addParam("CVSRecentUpdateTime", getCVSRecentUpdateTime());
    }
    controller.sendMsg(out, jcm.getFrom(), jcm.getThreadID());
  }
Beispiel #2
0
  public void onMessage(SessionMsg msg) {
    SessionMsg out = new SessionMsg(sessionMsgPrefix);
    JabberChatMessage jcm = msg.getOrigionalJabberMessage();
    out.setParentMsgID(msg.getID());
    out.setThreadID(msg.getThreadID());

    int resultCode = 0;
    String resultString = "OK";

    String clientName = msg.getParam("ClientName");
    // relative to uploadRootDir+ "/" + clientName
    String fileName = msg.getParam("File");
    if (fileName.endsWith(".sql")) fileName += ".gz";
    logger.debug("DBImport request from " + clientName + ", file:" + fileName);
    // command
    String outputFileName = tmpDir + "/" + clientName + "_" + fileName + ".out";

    // file like "c:/tmp/12.sql.gz
    String fullFileName = (uploadRootDir + "/" + clientName + "/" + fileName);
    String checkSum = msg.getParam("FileCheckSum");
    if (checkSum == null || checkSum.length() != 32) {
      logger.debug("FileCheckSum not found or invalid:" + checkSum);
    } else {
      // compare checksum
      String fck = MD5SumUtil.getCheckSum(new File(fullFileName), "");
      // System.out.println("Checksum for file:"+ fullFileName + " is " + fck);
      if (fck.length() == 32) {
        if (!fck.equalsIgnoreCase(checkSum)) {
          // error file upload
          // return result
          out.addParam("ResultCode", "99");
          out.addParam(
              "ResultString", "MD5 Checksum error for file " + fileName + ", please check.");
          logger.debug(
              "MD5 Checksum error for file "
                  + fileName
                  + ", local="
                  + fck
                  + ", while remote="
                  + checkSum);
          controller.sendMsg(out, jcm.getFrom(), jcm.getThreadID());
          return;
        }
      }
    }

    // start a command
    /*        CommandExecuter exec= new CommandExecuter(outputFileName);
            String cmd= impCmd + " " + fileName;
            try{
                resultCode=exec.run(cmd);
                if ( resultCode != 0) resultString= "Internal Error[code=" + resultCode+"]";
                logger.debug("Result in executing " +cmd+":" + Tools.getFileContent(outputFileName ));
            }catch(Exception e){
                logger.error("Error executing " + cmd, e);
                resultString="Error in executing:" + cmd;
                resultCode = 1;
            }
    */

    manager.getRelayManager().removeFile(clientName, fileName, 0 /* normal maintain*/);
    manager.getRelayManager().addFile(clientName, fileName, "P");

    // return result
    out.addParam("ResultCode", "0");
    out.addParam("ResultString", "File will be handled.");
    controller.sendMsg(out, jcm.getFrom(), jcm.getThreadID());
  }