@Override
  public void start(BundleContext context) throws Exception {
    this.logger = LoggerActivator.getLogger();
    this.logger.info("Starting the " + context.getBundle().getSymbolicName() + " bundle...");

    PermissionActivator.configTracker =
        new ServiceTracker<Config, Config>(context, Config.class, null);
    PermissionActivator.configTracker.open();

    PermissionActivator.messengerTracker =
        new ServiceTracker<MessengerService, MessengerService>(
            context, MessengerService.class, null);
    PermissionActivator.messengerTracker.open();

    /* Register the Permissions service. */
    this.logger.debug("Registering the Permissions SOAP interface service.");
    ServletContainerService soapService = new ServletContainerService();
    soapService.addServlet(new ServletContainer(new AxisServlet(), true));
    this.soapRegistration =
        context.registerService(ServletContainerService.class, soapService, null);

    this.pageRegistrations = new ArrayList<ServiceRegistration<HostedPage>>(3);
    this.pageRegistrations.add(
        context.registerService(HostedPage.class, UsersPage.getHostedPage(), null));
    this.pageRegistrations.add(
        context.registerService(HostedPage.class, UserClassesPage.getHostedPage(), null));
    this.pageRegistrations.add(
        context.registerService(HostedPage.class, KeysPage.getHostedPage(), null));
  }
  /**
   * Adds a servlet to hosted on server based on the provided service reference. If the server is
   * started, it is briefly stopped to add the servlet and is then restarted.
   *
   * @param ref service reference pointing to a ServletContainerService service
   */
  public synchronized void addService(final ServiceReference<ServletContainerService> ref) {
    boolean wasRunning = false;
    try {
      final ServletContainerService serv = this.bundleContext.getService(ref);
      ServletContainer containers[] = serv.getServlets();
      if (containers.length == 0) {
        this.logger.error(
            "Server registration from bundle "
                + ref.getBundle().getSymbolicName()
                + " does not contain a servlet so it cannot be hosted. This is a bug.");
        throw new IllegalArgumentException("Servlet is empty.");
      }

      /* If running, stop the server. */
      wasRunning = this.server.isStarted() || this.server.isStarting();
      if (wasRunning) this.server.stop();

      /* Create the context. */
      final String contextPath =
          serv.getOverriddingPathSpec() == null
              ? '/' + ref.getBundle().getSymbolicName()
              : serv.getOverriddingPathSpec();
      this.logger.info(
          "The servlets for bundle "
              + ref.getBundle().getSymbolicName()
              + " will be hosted on "
              + "path "
              + contextPath
              + '.');
      final Context context = new Context(this.server, contextPath, Context.SESSIONS);
      this.contexts.put(ref.getProperty(Constants.SERVICE_ID), context);

      /* Populate a context with all the servlets to run. */
      for (ServletContainer cont : containers) {
        final ServletHolder holder = new ServletHolder(cont.getServlet());
        if (cont.isAxis()) {
          URL repoUrl = cont.getServlet().getClass().getResource("/META-INF/repo");
          if (repoUrl != null) {
            this.logger.debug(
                "Axis repository for bundle "
                    + ref.getBundle().getSymbolicName()
                    + " has URI "
                    + repoUrl.toURI().toString()
                    + '.');
            holder.setInitParameter("axis2.repository.url", repoUrl.toURI().toString());
          } else {
            this.logger.error(
                "Unable to find the repository resource from the "
                    + ref.getBundle().getSymbolicName()
                    + " bundle. There must be a 'repo' folder in the "
                    + "bundle META-INF folder containing the services list (services.list) and a service "
                    + "archive file with the service WSDL and service descriptor (services.xml).");
            continue;
          }
        }
        this.logger.debug(
            "Deploying servlet from the "
                + ref.getBundle().getSymbolicName()
                + " bundle with service ID: "
                + ref.getProperty(Constants.SERVICE_ID));
        context.addServlet(holder, cont.getPath());
      }

      this.contextCollection.addHandler(context);
    } catch (Exception ex) {
      ex.printStackTrace();
      this.logger.error(
          "Failed adding server service from bundle "
              + ref.getBundle().getSymbolicName()
              + " because of exception with message: "
              + ex.getMessage()
              + '.');
    } finally {
      /* Restore the server state. */
      if (wasRunning && this.server.isStopped()) {
        try {
          this.logger.debug("Restarting Scheduling server servlet server.");
          this.server.start();
        } catch (Exception e) {
          this.logger.error(
              "Failed starting Jetty server because of exception with message: "
                  + e.getMessage()
                  + '.');
        }
      }
    }
  }