Пример #1
0
  /**
   * Start the proxy, this method has to be called after the init method throws Exception that which
   * can be caught by the upper application
   */
  public void start() throws Exception {
    if (configuration != null && configuration.isValidConfiguration()) {
      Properties properties = new Properties();
      // LOGGING property:

      if (configuration.enableDebug) {
        ProxyDebug.debug = true;
        ProxyDebug.setProxyOutputFile(configuration.outputProxy);
        ProxyDebug.println("DEBUG properties set!");
        if (configuration.badMessageLogFile != null)
          properties.setProperty(
              "gov.nist.javax.sip.BAD_MESSAGE_LOG", configuration.badMessageLogFile);
        if (configuration.debugLogFile != null) {
          properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", configuration.debugLogFile);
        }
        if (configuration.serverLogFile != null)
          properties.setProperty("gov.nist.javax.sip.SERVER_LOG", configuration.serverLogFile);
        if (configuration.debugLogFile != null)
          properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "32");
        else if (configuration.serverLogFile != null)
          properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "16");
        else properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "0");

      } else {
        System.out.println("DEBUG properties not set!");
      }
      registrar.setExpiresTime(configuration.expiresTime);

      // STOP TIME
      if (configuration.stopTime != null) {
        try {
          long stopTime = Long.parseLong(configuration.stopTime);
          StopProxy stopProxy = new StopProxy(this);
          Timer timer = new Timer();
          timer.schedule(stopProxy, stopTime);
        } catch (Exception e) {
          e.printStackTrace();
        }
      }

      sipStack = null;

      SipFactory sipFactory = SipFactory.getInstance();
      sipFactory.setPathName("gov.nist");

      headerFactory = sipFactory.createHeaderFactory();
      addressFactory = sipFactory.createAddressFactory();
      messageFactory = sipFactory.createMessageFactory();

      // Create SipStack object

      properties.setProperty("javax.sip.IP_ADDRESS", configuration.stackIPAddress);

      // We have to add the IP address of the proxy for the domain:
      configuration.domainList.addElement(configuration.stackIPAddress);
      ProxyDebug.println("The proxy is responsible for the domain:" + configuration.stackIPAddress);

      properties.setProperty("javax.sip.STACK_NAME", configuration.stackName);
      if (configuration.check(configuration.outboundProxy))
        properties.setProperty("javax.sip.OUTBOUND_PROXY", configuration.outboundProxy);
      if (configuration.check(configuration.routerPath))
        properties.setProperty("javax.sip.ROUTER_PATH", configuration.routerPath);
      if (configuration.check(configuration.extensionMethods))
        properties.setProperty("javax.sip.EXTENSION_METHODS", configuration.extensionMethods);
      // This has to be hardcoded to true. for the proxy.
      properties.setProperty("javax.sip.RETRANSMISSION_FILTER", "on");

      if (configuration.check(configuration.maxConnections))
        properties.setProperty("gov.nist.javax.sip.MAX_CONNECTIONS", configuration.maxConnections);
      if (configuration.check(configuration.maxServerTransactions))
        properties.setProperty(
            "gov.nist.javax.sip.MAX_SERVER_TRANSACTIONS", configuration.maxServerTransactions);
      if (configuration.check(configuration.threadPoolSize))
        properties.setProperty("gov.nist.javax.sip.THREAD_POOL_SIZE", configuration.threadPoolSize);

      if (configuration.domainList != null)
        for (int j = 0; j < configuration.domainList.size(); j++) {
          String domain = (String) configuration.domainList.elementAt(j);
          ProxyDebug.println("Here is one domain to take care of:" + domain);
        }
      else ProxyDebug.println("No domain to take care of...");

      if (configuration.accessLogViaRMI) {
        properties.setProperty("gov.nist.javax.sip.ACCESS_LOG_VIA_RMI", "true");

        properties.setProperty("gov.nist.javax.sip.RMI_PORT", configuration.logRMIPort);

        if (configuration.check(configuration.logLifetime))
          properties.setProperty("gov.nist.javax.sip.LOG_LIFETIME", configuration.logLifetime);
      }

      sipStack = sipFactory.createSipStack(properties);

      // Authentication part:
      if (configuration.enableAuthentication) {
        authentication = new Authentication(this);
        try {

          Class authMethodClass = Class.forName(configuration.classFile);
          AuthenticationMethod authMethod = (AuthenticationMethod) authMethodClass.newInstance();
          authMethod.initialize(configuration.passwordsFile);

          authentication.setAuthenticationMethod(authMethod);

        } catch (Exception e) {
          ProxyDebug.println("ERROR, authentication process stopped, exception raised:");
          e.printStackTrace();
        }
      }

      // We create the Listening points:
      Vector lps = configuration.getListeningPoints();

      for (int i = 0; lps != null && i < lps.size(); i++) {
        Association a = (Association) lps.elementAt(i);
        try {
          System.out.println("transport  " + a.transport);
          System.out.println("port  " + Integer.valueOf(a.port).intValue());
          ListeningPoint lp =
              sipStack.createListeningPoint(Integer.valueOf(a.port).intValue(), a.transport);
          this.listeningPoints.add(lp);
          SipProvider sipProvider = sipStack.createSipProvider(lp);
          if (this.defaultProvider == null) this.defaultProvider = sipProvider;
          sipProvider.addSipListener(this);
        } catch (Exception e) {
          e.printStackTrace();
          ProxyDebug.println("ERROR: listening point not created ");
        }
      }
      // Export the registry for polling by the responder.

      if (configuration.exportRegistry)
        // initialize the registrar for RMI.
        this.registrar.initRMIBindings();

      // Parse static configuration for registrar.
      if (configuration.enableRegistrations) {
        String value = configuration.registrationsFile;
        ProxyDebug.println("Parsing the XML registrations file: " + value);
        if (value == null || value.trim().equals(""))
          ProxyDebug.println("You have to set the registrations file...");
        else registrar.parseXMLregistrations(value);
      } else ProxyDebug.println("No registrations to parse...");

      // Register to proxies if any:
      registrar.registerToProxies();

    } else {
      System.out.println(
          "ERROR: the configuration file is not correct!" + " Correct the errors first.");
    }
  }