/**
   * Initialize the jWebSocket Server system
   *
   * @param aConfigPath the overridden path to xml config file
   * @return the initializer object
   * @throws WebSocketException if there's an exception while initialization
   */
  public final WebSocketInitializer initialize(String aConfigPath) throws WebSocketException {
    String lConfigPath;
    if (aConfigPath != null && !"".equals(aConfigPath)) {
      lConfigPath = Tools.expandEnvVarsAndProps(aConfigPath);
      if (mLog.isDebugEnabled()) {
        mLog.debug("Initializing: Using config file '" + aConfigPath + "'...");
      }
    } else {
      lConfigPath = JWebSocketConfig.getConfigPath();
    }
    if (lConfigPath == null) {
      throw new WebSocketException(
          "Either "
              + JWebSocketServerConstants.JWEBSOCKET_HOME
              + " variable is not set"
              + " or jWebSocket.xml file does neither exist at ${"
              + JWebSocketServerConstants.JWEBSOCKET_HOME
              + "}/conf nor at ${CLASSPATH}/conf.");
    }
    // load the entire settings from the configuration xml file
    JWebSocketConfig lConfig = loadConfiguration(lConfigPath);

    // initialize security by using config settings
    SecurityFactory.initFromConfig(lConfig);
    WebSocketInitializer lInitializer = new JWebSocketXmlConfigInitializer(lConfig);
    return lInitializer;
  }
 /**
  * Load all the configurations based on jWebSocket.xml file at the given <tt>configFilePath</tt>
  * location.
  *
  * @param aConfigPath the path to jWebSocket.xml file
  * @return the web socket config object with all the configuration
  * @throws WebSocketException if there's any while loading configuration
  */
 public JWebSocketConfig loadConfiguration(final String aConfigPath) throws WebSocketException {
   JWebSocketConfig lConfig = null;
   String lMsg;
   try {
     InputStream lIS;
     if (JWebSocketConfig.isLoadConfigFromResource()) {
       if (mLog.isDebugEnabled()) {
         mLog.debug("Loading configuration from resource '" + aConfigPath + "...");
       }
       lIS = this.getClass().getResourceAsStream("/" + aConfigPath);
     } else {
       if (mLog.isDebugEnabled()) {
         mLog.debug("Loading configuration from file '" + aConfigPath + "...");
       }
       File lFile = new File(aConfigPath);
       lIS = new FileInputStream(lFile);
     }
     XMLInputFactory lFactory = XMLInputFactory.newInstance();
     XMLStreamReader lStreamReader = null;
     lStreamReader = lFactory.createXMLStreamReader(lIS);
     lConfig = (JWebSocketConfig) mConfigHandler.processConfig(lStreamReader);
     if (mLog.isInfoEnabled()) {
       mLog.info("Configuration successfully loaded from '" + aConfigPath + "'.");
     }
   } catch (XMLStreamException lEx) {
     lMsg =
         lEx.getClass().getSimpleName()
             + " occurred while creating XML stream ("
             + aConfigPath
             + "): "
             + lEx.getMessage()
             + ".";
     throw new WebSocketException(lMsg);
   } catch (FileNotFoundException lEx) {
     lMsg =
         "jWebSocket config file not found while creating XML stream ("
             + aConfigPath
             + "): "
             + lEx.getMessage()
             + ".";
     throw new WebSocketException(lMsg);
   }
   return lConfig;
 }