Пример #1
0
 public void updateLanguage() {
   //////////////////////////////////////////////////////////////
   mdic = MonitorDictionary.getChildDictionary("ThreadManager");
   MonitorDictionary.applyButton(btnKick, "Kick");
   MonitorDictionary.applyButton(btnRefresh, "Refresh");
   MonitorDictionary.applyButton(btnSend, "Send");
   tblUser.setColumnNameEx(mdic.getString("LoginName"), 1);
   tblUser.setColumnNameEx(mdic.getString("LoginTime"), 2);
   tblUser.setColumnNameEx(mdic.getString("Host"), 3);
   //////////////////////////////////////////////////////////////
   MonitorDictionary.applyButton(mnuSelectAll, "jmenu.Edit.SelectAll");
   MonitorDictionary.applyButton(mnuClearAll, "jmenu.Edit.ClearAll");
   MonitorDictionary.applyButton(mnuClearSelected, "jmenu.Edit.ClearSelected");
   //////////////////////////////////////////////////////////////
   MonitorDictionary.applyButton(mnuSystem, "jmenu.System");
   MonitorDictionary.applyButton(mnuSystem_ChangePassword, "jmenu.System.ChangePassword");
   MonitorDictionary.applyButton(mnuSystem_StopServer, "jmenu.System.Shutdown");
   MonitorDictionary.applyButton(mnuSystem_EnableThreads, "jmenu.System.ThreadManager");
   MonitorDictionary.applyButton(mnuHelp, "jmenu.Help");
   MonitorDictionary.applyButton(mnuHelp_About, "jmenu.Help.About");
   //////////////////////////////////////////////////////////////
   MonitorDictionary.applyButton(mnuUI, "jmenu.UI");
   //////////////////////////////////////////////////////////////
   if (isOpen()) {
     lblStatus.setText(
         "  " + MonitorDictionary.getString("LoggedUser") + ": " + channel.getUserName());
     MonitorDictionary.applyButton(mnuSystem_Login, "jmenu.System.Logout");
     mnuSystem_ChangePassword.setEnabled(true);
     mnuSystem_StopServer.setEnabled(true);
     mnuSystem_EnableThreads.setEnabled(true);
   } else {
     lblStatus.setText("");
     MonitorDictionary.applyButton(mnuSystem_Login, "jmenu.System.Login");
     mnuSystem_ChangePassword.setEnabled(false);
     mnuSystem_StopServer.setEnabled(false);
     mnuSystem_EnableThreads.setEnabled(false);
   }
   //////////////////////////////////////////////////////////////
   for (int iIndex = 0; iIndex < pnlThread.getTabCount(); iIndex++)
     ((PanelThreadMonitor) pnlThread.getComponentAt(iIndex)).updateLanguage();
 }
Пример #2
0
  /**
   * @param request JSONObject contain request data
   * @param response
   * @throws Exception
   */
  public static void processRequest(
      HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception {
    JSONObject jsonResponse = new JSONObject();
    JSONObject jsonRequest;
    try {
      // get parameter
      String strServiceName = servletRequest.getServletPath();
      String strMethodName = servletRequest.getMethod();
      // get service config
      DictionaryNode ndClassConfig = mDic.getNode(strServiceName);
      if (ndClassConfig == null) {
        throw new Exception("unknown request " + strServiceName);
      }
      // request
      StringBuilder stringBuilder = new StringBuilder(1000);
      Scanner scanner = new Scanner(servletRequest.getInputStream());
      while (scanner.hasNextLine()) {
        stringBuilder.append(scanner.nextLine());
      }
      String strRequest = stringBuilder.toString();
      System.out.println(strRequest);
      // JSON request
      //			jsonRequest = new JSONObject("{}");
      jsonRequest = new JSONObject(strRequest);
      // Get class name & create class instance
      String strClassName = ndClassConfig.getString("Class");
      if (strClassName.length() == 0) throw new Exception("Class name was not passed");
      @SuppressWarnings("rawtypes")
      Class cls = Class.forName(strClassName);
      Object obj = cls.newInstance();

      // Check class
      if (!(obj instanceof DatabaseProcessor))
        throw new Exception("Class '" + strClassName + "' must be a Database Processor");
      DatabaseProcessor storage = (DatabaseProcessor) obj;
      // Get function name and method
      String strFunctionName = "";
      switch (strMethodName.toUpperCase()) {
        case "GET":
          strFunctionName = "doGet";
          break;
        case "POST":
          strFunctionName = "doPost";
          break;
        case "DELETE":
          strFunctionName = "doDelete";
          break;
        default:
          throw new Exception("method is unsupport");
      }
      if (strFunctionName.length() == 0) throw new Exception("Function name was not passed");
      // Get method from class name and function name
      @SuppressWarnings("unchecked")
      Method method = cls.getMethod(strFunctionName);
      if (method == null)
        throw new Exception(
            "Function '" + strClassName + "." + strFunctionName + "' was not declared");

      // Check function
      if (Modifier.isAbstract(method.getModifiers()))
        throw new Exception(
            "Function '" + strClassName + "." + strFunctionName + "' was not implemented");
      if (!Modifier.isPublic(method.getModifiers()))
        throw new Exception(
            "Function '" + strClassName + "." + strFunctionName + "' is not public");
      // Invoke function
      storage.setRequest(jsonRequest);
      storage.setResponse(jsonResponse);
      try {
        obj = method.invoke(storage);
        // response.put("handle", strHandle);
      } catch (InvocationTargetException e) {
        if (e.getTargetException() instanceof Exception) throw (Exception) e.getTargetException();
        throw new Exception(e.getTargetException());
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      jsonResponse.put("handle", "on_error");
      jsonResponse.put("message", ex.getMessage());
    } finally {
      // response
      servletResponse.setCharacterEncoding("utf-8");
      servletResponse.setContentType("text/plain");
      servletResponse.setHeader("Access-Control-Allow-Origin", "*, ");
      servletResponse.setHeader(
          "Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
      servletResponse.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
      // return response
      PrintWriter out = servletResponse.getWriter();
      out.println(jsonResponse.toString());
      out.flush();
    }
  }