/** Starts the server using Spring configuration. */
  public void start() {
    try {
      if (isStandAlone()) {
        Runtime.getRuntime().addShutdownHook(new ShutdownHookThread());
      }

      //  locateServer();
      serverName = Config.getString("xmpp.domain", "127.0.0.1").toLowerCase();
      // 获取spring对象的上下文
      context = new ClassPathXmlApplicationContext("spring-config.xml");
      log.info("Spring Configuration loaded.");

      //            AdminConsole adminConsole = new AdminConsole(serverHomeDir);
      //            adminConsole.startup();
      //            if (adminConsole.isHttpStarted()) {
      //                log.info("Admin console listening at http://"
      //                        + adminConsole.getAdminHost() + ":"
      //                        + adminConsole.getAdminPort());
      //            }
      log.info("XmppServer started: " + serverName);
      log.info("Androidpn Server v" + version);

    } catch (Exception e) {
      e.printStackTrace();
      shutdownServer();
    }
  }
  public ModelAndView send(HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    String broadcast = ServletRequestUtils.getStringParameter(request, "broadcast", "Y");
    String username = ServletRequestUtils.getStringParameter(request, "username");
    String title = ServletRequestUtils.getStringParameter(request, "title");
    String message = ServletRequestUtils.getStringParameter(request, "message");
    String uri = ServletRequestUtils.getStringParameter(request, "uri");

    String apiKey = Config.getString("apiKey", "");
    logger.debug("apiKey=" + apiKey);

    if (broadcast.equalsIgnoreCase("Y")) {
      notificationManager.sendBroadcast(apiKey, title, message, uri);
    } else {
      notificationManager.sendNotifcationToUser(apiKey, username, title, message, uri);
    }

    ModelAndView mav = new ModelAndView();
    mav.setViewName("redirect:notification.do");
    return mav;
  }
  static {
    classPath = SSLConfig.class.getResource("/");

    storeType = Config.getString("xmpp.ssl.storeType", "JKS");
    keyStoreLocation =
        Config.getString(
            "xmpp.ssl.keystore",
            "conf" + File.separator + "security" + File.separator + "keystore");
    keyStoreLocation = classPath.getPath() + File.separator + keyStoreLocation;
    keyPass = Config.getString("xmpp.ssl.keypass", "changeit");
    trustStoreLocation =
        Config.getString(
            "xmpp.ssl.truststore",
            "conf" + File.separator + "security" + File.separator + "truststore");
    trustStoreLocation = classPath.getPath() + File.separator + trustStoreLocation;
    trustPass = Config.getString("xmpp.ssl.trustpass", "changeit");

    log.debug("keyStoreLocation=" + keyStoreLocation);
    log.debug("trustStoreLocation=" + trustStoreLocation);

    // Load keystore
    try {
      keyStore = KeyStore.getInstance(storeType);
      keyStore.load(new FileInputStream(keyStoreLocation), keyPass.toCharArray());
    } catch (Exception e) {
      log.error(
          "SSLConfig startup problem.\n"
              + "  storeType: ["
              + storeType
              + "]\n"
              + "  keyStoreLocation: ["
              + keyStoreLocation
              + "]\n"
              + "  keyPass: ["
              + keyPass
              + "]",
          e);
      keyStore = null;
    }

    // Load truststore
    try {
      trustStore = KeyStore.getInstance(storeType);
      trustStore.load(new FileInputStream(trustStoreLocation), trustPass.toCharArray());

    } catch (Exception e) {
      try {
        trustStore = KeyStore.getInstance(storeType);
        trustStore.load(null, trustPass.toCharArray());
      } catch (Exception ex) {
        log.error(
            "SSLConfig startup problem.\n"
                + "  storeType: ["
                + storeType
                + "]\n"
                + "  trustStoreLocation: ["
                + trustStoreLocation
                + "]\n"
                + "  trustPass: ["
                + trustPass
                + "]",
            e);
        trustStore = null;
      }
    }

    // Init factory
    try {
      sslContext = SSLContext.getInstance("TLS");

      KeyManagerFactory keyFactory =
          KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
      keyFactory.init(keyStore, SSLConfig.getKeyPassword().toCharArray());

      TrustManagerFactory c2sTrustFactory =
          TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
      c2sTrustFactory.init(trustStore);

      sslContext.init(
          keyFactory.getKeyManagers(),
          c2sTrustFactory.getTrustManagers(),
          new java.security.SecureRandom());

    } catch (Exception e) {
      log.error(
          "SSLConfig factory setup problem."
              + "  storeType: ["
              + storeType
              + "]\n"
              + "  keyStoreLocation: ["
              + keyStoreLocation
              + "]\n"
              + "  keyPass: ["
              + keyPass
              + "]\n"
              + "  trustStoreLocation: ["
              + trustStoreLocation
              + "]\n"
              + "  trustPass: ["
              + trustPass
              + "]",
          e);
      keyStore = null;
      trustStore = null;
    }
  }