@Override
  public void configureComponent(Configuration configuration) {
    super.configureComponent(configuration);

    Activity activity = getComponentContext().getActivity();

    webSocketUriPrefix =
        configuration.getPropertyString(CONFIGURATION_WEBAPP_WEB_SERVER_WEBSOCKET_URI);

    webServerPort =
        configuration.getPropertyInteger(
            CONFIGURATION_WEBAPP_WEB_SERVER_PORT, WEB_SERVER_PORT_DEFAULT);
    WebServerService webServerService =
        activity
            .getSpaceEnvironment()
            .getServiceRegistry()
            .getService(WebServerService.SERVICE_NAME);
    webServer =
        webServerService.newWebServer(
            String.format("%sWebServer", activity.getName()), webServerPort, activity.getLog());

    String webServerHost =
        configuration.getPropertyString(
            InteractiveSpacesEnvironment.CONFIGURATION_HOST_ADDRESS, WEB_SERVER_DEFAULT_HOST);

    webContentPath = "/" + activity.getName();
    webContentUrl = "http://" + webServerHost + ":" + webServer.getPort() + webContentPath;

    webInitialPage =
        webContentUrl
            + "/"
            + configuration.getPropertyString(
                BasicWebBrowserActivityComponent.CONFIGURATION_INITIAL_PAGE, DEFAULT_INITIAL_PAGE);

    String contentLocation = configuration.getPropertyString(CONFIGURATION_WEBAPP_CONTENT_LOCATION);
    if (contentLocation != null) {
      webContentBaseDir =
          new File(activity.getActivityFilesystem().getInstallDirectory(), contentLocation);

      webServer.addStaticContentHandler(webContentPath, webContentBaseDir);
    }

    for (StaticContent content : staticContent) {
      webServer.addStaticContentHandler(content.getUriPrefix(), content.getBaseDir());
    }

    for (DynamicContent content : dynamicContent) {
      webServer.addDynamicContentHandler(
          content.getUriPrefix(), content.isUsePath(), content.getRequestHandler());
    }

    if (webSocketHandlerFactory != null) {
      setWebServerWebSocketHandlerFactory();
    }

    if (httpFileUploadListener != null) {
      webServer.setHttpFileUploadListener(httpFileUploadListener);
    }
  }
  @Override
  public void shutdown() {
    remoteSpaceControllerClient.removeRemoteSpaceControllerClientListener(this);

    if (webServer != null) {
      webServer.shutdown();
      webServer = null;
    }
  }
  @Override
  public WebServerActivityComponent addStaticContent(String uriPrefix, File baseDir) {
    if (webServer != null) {
      webServer.addStaticContentHandler(uriPrefix, baseDir);
    } else {
      staticContent.add(new StaticContent(uriPrefix, baseDir));
    }

    return this;
  }
  @Override
  public WebServerActivityComponent addDynamicContent(
      String uriPrefix, boolean usePath, HttpDynamicRequestHandler handler) {
    if (webServer != null) {
      webServer.addDynamicContentHandler(uriPrefix, usePath, handler);
    } else {
      dynamicContent.add(new DynamicContent(handler, uriPrefix, usePath));
    }

    return this;
  }
  @Override
  public WebServerActivityComponent setHttpFileUploadListener(
      HttpFileUploadListener httpFileUploadListener) {
    this.httpFileUploadListener = httpFileUploadListener;

    if (webServer != null) {
      webServer.setHttpFileUploadListener(httpFileUploadListener);
    }

    return this;
  }
  @Override
  public void startup() {
    int port =
        spaceEnvironment
            .getSystemConfiguration()
            .getPropertyInteger(
                MasterWebsocketManager.CONFIGURATION_MASTER_WEBSOCKET_PORT,
                MasterWebsocketManager.CONFIGURATION_MASTER_WEBSOCKET_PORT_DEFAULT);

    webServer =
        new NettyWebServer(
            "master", port, spaceEnvironment.getExecutorService(), spaceEnvironment.getLog());

    webSocketFactory =
        new BasicMultipleConnectionWebServerWebSocketHandlerFactory(
            this, spaceEnvironment.getLog());

    webServer.setWebSocketHandlerFactory("", webSocketFactory);

    webServer.startup();

    remoteSpaceControllerClient.addRemoteSpaceControllerClientListener(this);
  }
  @Override
  public void shutdownComponent() {
    long start = System.currentTimeMillis();
    getLog().info("Shutting down web server activity component");

    if (webServer != null) {
      webServer.shutdown();
      webServer = null;
    }

    if (getLog().isInfoEnabled()) {
      getLog()
          .info(
              String.format(
                  "Web server activity component shut down in %s msecs",
                  System.currentTimeMillis() - start));
    }
  }
 /** Set the web server web socket handler with the proper wrapped factory. */
 private void setWebServerWebSocketHandlerFactory() {
   webServer.setWebSocketHandlerFactory(
       webSocketUriPrefix, new MyWebServerWebSocketHandlerFactory(webSocketHandlerFactory, this));
 }
 @Override
 public void startupComponent() {
   webServer.startup();
   getLog().info("web server component started up");
 }