Example #1
0
  static void initializeLogging() throws SipXOpenfirePluginException {
    try {
      String javaClassPaths = System.getProperty("java.class.path");
      String openfireHome = System.getProperty("openfire.home");
      StringBuilder sb =
          new StringBuilder(javaClassPaths).append(":" + openfireHome + "/lib/sipxcommons.jar");
      System.setProperty("java.class.path", sb.toString());
      String log4jPropertiesFile = configurationPath + "/log4j.properties";

      if (new File(log4jPropertiesFile).exists()) {
        /*
         * Override the file configuration setting.
         */
        Properties props = new Properties();
        props.load(new FileInputStream(log4jPropertiesFile));
        String level = props.getProperty("log4j.category.org.sipfoundry.openfire");
        if (level != null) {
          watcherConfig.setLogLevel(level);
        }
      }
      setLogAppender(new SipFoundryAppender(new SipFoundryLayout(), logFile));
      // TODO -- this should be org.sipfoundry.openfire.
      Logger applicationLogger = Logger.getLogger("org.sipfoundry");

      /*
       * Set the log level.
       */
      if (watcherConfig.getLogLevel().equals("TRACE")) {
        applicationLogger.setLevel(org.apache.log4j.Level.DEBUG);
      } else {
        applicationLogger.setLevel(org.apache.log4j.Level.toLevel(watcherConfig.getLogLevel()));
      }

      applicationLogger.addAppender(getLogAppender());
      if (System.getProperty("output.console") != null) {
        applicationLogger.addAppender(new ConsoleAppender(new PatternLayout()));
      }

      CallWatcher.setLogAppender(getLogAppender());
    } catch (Exception ex) {
      throw new SipXOpenfirePluginException(ex);
    }
  }
Example #2
0
  public void initializePlugin(PluginManager manager, File pluginDirectory) {
    SipXOpenfirePlugin.instance = this;

    InputStream in = getClass().getResourceAsStream("/config.properties");
    Properties properties = new Properties();
    componentManager = ComponentManagerFactory.getComponentManager();

    try {
      properties.load(in);
    } catch (IOException ex) {
      componentManager.getLog().error(ex);
    }

    try {
      if (new File("/tmp/sipx.properties").exists()) {
        System.getProperties().load(new FileInputStream(new File("/tmp/sipx.properties")));
      }
    } catch (Exception ex) {
      componentManager.getLog().error(ex);
      throw new SipXOpenfirePluginException("Error reading config file ", ex);
    }

    pluginManager = manager;
    ClassLoader classLoader = pluginManager.getPluginClassloader(this);
    classLoader.setPackageAssertionStatus("org.sipfoundry", true);
    Thread.currentThread().setContextClassLoader(classLoader);
    configurationPath = System.getProperty("conf.dir", "/etc/sipxpbx");
    parseConfigurationFile();
    initializeLogging();
    CallWatcher.setWatcherConfig(watcherConfig);
    /*
     * This initializes the SIP side of the show.
     */
    try {
      CallWatcher.pluginInit();
      log.info("completed init");
      ResourceStateChangeListener resourceStateChangeListener =
          new ResourceStateChangeListenerImpl(this);
      CallWatcher.getSubscriber().setResourceStateChangeListener(resourceStateChangeListener);
    } catch (Exception e) {
      log.error("Error initializing CallWatcher");
      throw new SipXOpenfirePluginException("Init error", e);
    }

    server = XMPPServer.getInstance();

    userManager = server.getUserManager();
    presenceManager = server.getPresenceManager();

    hostname = server.getServerInfo().getXMPPDomain();
    log.info("HostName = " + hostname);

    probedPresence = new ConcurrentHashMap<String, Presence>();
    componentJID = new JID(subdomain + "." + hostname);

    groupManager = GroupManager.getInstance();

    multiUserChatManager = server.getMultiUserChatManager();
    /*
     * Load up the database.
     */
    multiUserChatManager.start();
    log.info("hostname " + hostname);
    try {
      componentManager.addComponent(subdomain, this);
    } catch (Exception e) {
      componentManager.getLog().error(e);
      log.error(e);
      throw new SipXOpenfirePluginException("Init error", e);
    }

    String accountConfigurationFile = configurationPath + "/xmpp-account-info.xml";
    if (!new File(accountConfigurationFile).exists()) {
      System.err.println("User account file not found");
      throw new SipXOpenfirePluginException("Cannot find user accounts file");
    } else {
      this.accountsParser = new AccountsParser(accountConfigurationFile);
      this.accountsParser.startScanner();
    }
    // config and instantiate and the presence unifier used to gather all presence info

    PresenceUnifier.setPlugin(this);
    PresenceUnifier.getInstance();
    // add packet interceptor

    InterceptorManager.getInstance().addInterceptor(new MessagePacketInterceptor(this));
    log.info("plugin initializaton completed");
    log.info("DONE");
  }