@Override
  public void start(StartContext startContext) throws StartException {

    ServerEnvironment env = injectedServerEnvironment.getValue();
    Host virtualHost = injectedVirtualHost.getValue().getHost();
    BundleContext syscontext = injectedSystemContext.getValue();
    WebServer webServer = injectedWebServer.getValue();

    File storageDir =
        new File(
            env.getServerTempDir()
                + File.separator
                + CONTEXT_NAME
                + File.separator
                + "httpservice-root");
    context.setDocBase(storageDir.getPath());
    storageDir.mkdirs();

    context.setPath(CONTEXT_NAME);
    context.addLifecycleListener(new ContextConfig());
    Loader loader = new WebCtxLoader(getClass().getClassLoader());
    loader.setContainer(virtualHost);
    context.setLoader(loader);
    context.setInstanceManager(new LocalInstanceManager());

    context.addMimeMapping("html", "text/html");
    context.addMimeMapping("jpg", "image/jpeg");
    context.addMimeMapping("png", "image/png");
    context.addMimeMapping("gif", "image/gif");
    context.addMimeMapping("css", "text/css");
    context.addMimeMapping("js", "text/javascript");

    virtualHost.addChild(context);

    WEB_LOGGER.registerWebapp(context.getName());
    try {
      context.create();
    } catch (Exception ex) {
      throw new StartException(WebMessages.MESSAGES.createContextFailed(), ex);
    }
    try {
      context.start();
    } catch (LifecycleException ex) {
      throw new StartException(WebMessages.MESSAGES.startContextFailed(), ex);
    }

    Hashtable<String, Object> props = new Hashtable<String, Object>();
    props.put(Constants.SERVICE_RANKING, Integer.MIN_VALUE);
    props.put("provider", getClass().getPackage().getName());

    ServiceFactory serviceFactory = new HttpServiceFactory(webServer, virtualHost, context);
    registration = syscontext.registerService(HttpService.class.getName(), serviceFactory, props);
  }
  private void setupIntegrationProperties(StartContext context, Map<String, Object> props) {

    // Setup the Framework's storage area.
    String storage = (String) props.get(Constants.FRAMEWORK_STORAGE);
    if (storage == null) {
      ServerEnvironment environment = injectedServerEnvironment.getValue();
      File dataDir = environment.getServerDataDir();
      storage = dataDir.getAbsolutePath() + File.separator + "osgi-store";
      props.put(Constants.FRAMEWORK_STORAGE, storage);
    }

    // Provide the ModuleLogger
    ModuleLogger moduleLogger = Module.getModuleLogger();
    if (moduleLogger != null)
      props.put(ModuleLogger.class.getName(), moduleLogger.getClass().getName());

    // Setup default system modules
    String sysmodules = (String) props.get(PROP_JBOSS_OSGI_SYSTEM_MODULES);
    if (sysmodules == null) {
      Set<String> sysModules = new LinkedHashSet<String>();
      sysModules.addAll(Arrays.asList(SystemPackagesIntegration.DEFAULT_SYSTEM_MODULES));
      sysmodules = sysModules.toString();
      sysmodules = sysmodules.substring(1, sysmodules.length() - 1);
      props.put(PROP_JBOSS_OSGI_SYSTEM_MODULES, sysmodules);
    }

    // Setup default system packages
    String syspackages =
        (String) getPropertyWithSystemFallback(props, Constants.FRAMEWORK_SYSTEMPACKAGES);
    if (syspackages == null) {
      Set<String> sysPackages = new LinkedHashSet<String>();
      sysPackages.addAll(Arrays.asList(SystemPackagesIntegration.JAVAX_API_PACKAGES));
      sysPackages.addAll(Arrays.asList(SystemPaths.DEFAULT_FRAMEWORK_PACKAGES));
      sysPackages.addAll(Arrays.asList(SystemPackagesIntegration.DEFAULT_INTEGRATION_PACKAGES));
      syspackages = sysPackages.toString();
      syspackages = syspackages.substring(1, syspackages.length() - 1);
      props.put(Constants.FRAMEWORK_SYSTEMPACKAGES, syspackages);
    }

    String extrapackages =
        (String) getPropertyWithSystemFallback(props, Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA);
    if (extrapackages != null) {
      props.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, extrapackages);
    }
  }
  static ProcessType getProcessType(ServerEnvironment serverEnvironment) {
    if (serverEnvironment != null) {
      switch (serverEnvironment.getLaunchType()) {
        case DOMAIN:
          return ProcessType.DOMAIN_SERVER;
        case STANDALONE:
          return ProcessType.STANDALONE_SERVER;
        case EMBEDDED:
          return ProcessType.EMBEDDED_SERVER;
        case APPCLIENT:
          return ProcessType.APPLICATION_CLIENT;
      }
    }

    return ProcessType.EMBEDDED_SERVER;
  }
  static void installHttpManagementConnector(
      final OperationContext context,
      final ModelNode model,
      final ServiceTarget serviceTarget,
      final ServiceVerificationHandler verificationHandler,
      final List<ServiceController<?>> newControllers)
      throws OperationFailedException {

    ServiceName socketBindingServiceName = null;
    ServiceName secureSocketBindingServiceName = null;
    ServiceName interfaceSvcName = null;
    int port = -1;
    int securePort = -1;

    final ModelNode interfaceModelNode = validateResolvedModel(INTERFACE, context, model);
    if (interfaceModelNode.isDefined()) {
      // Legacy config
      String interfaceName = interfaceModelNode.asString();
      interfaceSvcName = NetworkInterfaceService.JBOSS_NETWORK_INTERFACE.append(interfaceName);
      final ModelNode portNode = HTTP_PORT.resolveModelAttribute(context, model);
      port = portNode.isDefined() ? portNode.asInt() : -1;
      final ModelNode securePortNode = HTTPS_PORT.resolveModelAttribute(context, model);
      securePort = securePortNode.isDefined() ? securePortNode.asInt() : -1;

      // Log the config
      if (securePort > -1) {
        if (port > -1) {
          ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnPortAndSecurePort(
              interfaceName, port, securePort);
        } else {
          ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnSecurePort(
              interfaceName, securePort);
        }
      } else if (port > -1) {
        ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnPort(interfaceName, port);
      }
    } else {
      // Socket-binding reference based config
      final ModelNode socketBindingNode = SOCKET_BINDING.resolveModelAttribute(context, model);
      if (socketBindingNode.isDefined()) {
        final String bindingName = socketBindingNode.asString();
        socketBindingServiceName = SocketBinding.JBOSS_BINDING_NAME.append(bindingName);
      }
      final ModelNode secureSocketBindingNode =
          SECURE_SOCKET_BINDING.resolveModelAttribute(context, model);
      if (secureSocketBindingNode.isDefined()) {
        final String bindingName = secureSocketBindingNode.asString();
        secureSocketBindingServiceName = SocketBinding.JBOSS_BINDING_NAME.append(bindingName);
      }

      // Log the config
      if (socketBindingServiceName != null) {
        if (secureSocketBindingServiceName != null) {
          ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnSocketAndSecureSocket(
              socketBindingServiceName.getSimpleName(),
              secureSocketBindingServiceName.getSimpleName());
        } else {
          ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnSocket(
              socketBindingServiceName.getSimpleName());
        }
      } else if (secureSocketBindingServiceName != null) {
        ServerLogger.ROOT_LOGGER.creatingHttpManagementServiceOnSecureSocket(
            secureSocketBindingServiceName.getSimpleName());
      }
    }

    ServiceName realmSvcName = null;
    final ModelNode realmNode = SECURITY_REALM.resolveModelAttribute(context, model);
    if (realmNode.isDefined()) {
      realmSvcName = SecurityRealmService.BASE_SERVICE_NAME.append(realmNode.asString());
    } else {
      ServerLogger.ROOT_LOGGER.httpManagementInterfaceIsUnsecured();
    }
    boolean consoleEnabled = model.get(ModelDescriptionConstants.CONSOLE_ENABLED).asBoolean(true);
    ConsoleMode consoleMode;
    if (consoleEnabled) {
      consoleMode =
          context.getRunningMode() == RunningMode.ADMIN_ONLY
              ? ConsoleMode.ADMIN_ONLY
              : ConsoleMode.CONSOLE;
    } else {
      consoleMode = ConsoleMode.NO_CONSOLE;
    }

    ServerEnvironment environment =
        (ServerEnvironment)
            context
                .getServiceRegistry(false)
                .getRequiredService(ServerEnvironmentService.SERVICE_NAME)
                .getValue();
    final HttpManagementService service =
        new HttpManagementService(consoleMode, environment.getProductConfig().getConsoleSlot());
    ServiceBuilder<HttpManagement> builder =
        serviceTarget
            .addService(HttpManagementService.SERVICE_NAME, service)
            .addDependency(
                Services.JBOSS_SERVER_CONTROLLER,
                ModelController.class,
                service.getModelControllerInjector())
            .addDependency(
                SocketBindingManagerImpl.SOCKET_BINDING_MANAGER,
                SocketBindingManager.class,
                service.getSocketBindingManagerInjector())
            .addDependency(
                ControlledProcessStateService.SERVICE_NAME,
                ControlledProcessStateService.class,
                service.getControlledProcessStateServiceInjector())
            .addInjection(
                service.getExecutorServiceInjector(),
                Executors.newCachedThreadPool(
                    new JBossThreadFactory(
                        new ThreadGroup("HttpManagementService-threads"),
                        Boolean.FALSE,
                        null,
                        "%G - %t",
                        null,
                        null,
                        AccessController.getContext())));

    if (interfaceSvcName != null) {
      builder
          .addDependency(
              interfaceSvcName, NetworkInterfaceBinding.class, service.getInterfaceInjector())
          .addInjection(service.getPortInjector(), port)
          .addInjection(service.getSecurePortInjector(), securePort);
    } else {
      if (socketBindingServiceName != null) {
        builder.addDependency(
            socketBindingServiceName, SocketBinding.class, service.getSocketBindingInjector());
      }
      if (secureSocketBindingServiceName != null) {
        builder.addDependency(
            secureSocketBindingServiceName,
            SocketBinding.class,
            service.getSecureSocketBindingInjector());
      }
    }

    if (realmSvcName != null) {
      builder.addDependency(
          realmSvcName, SecurityRealmService.class, service.getSecurityRealmInjector());
    }

    if (verificationHandler != null) {
      builder.addListener(verificationHandler);
    }
    ServiceController<?> controller = builder.install();
    if (newControllers != null) {
      newControllers.add(controller);
    }
  }