@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 configureComponent( Configuration configuration, ActivityComponentContext componentContext) { super.configureComponent(configuration, componentContext); WebServerActivityComponent webServer = componentContext.getActivityComponent(WebServerActivityComponent.COMPONENT_NAME); StringBuilder initialUrlBuilder = new StringBuilder(); String configurationInitialPage = configuration.getRequiredPropertyString(CONFIGURATION_INITIAL_PAGE); configurationInitialPage = configurationInitialPage.trim(); if (isDisallowedPrefix(configurationInitialPage)) { throw new InteractiveSpacesException( String.format( "The initial page %s starts with an illegal prefix", configurationInitialPage)); } if (isExternalPrefix(configurationInitialPage)) { initialUrlBuilder.append(configurationInitialPage); } else { if (webServer == null) { throw new InteractiveSpacesException( String.format( "No activity component of type %s found", WebServerActivityComponent.COMPONENT_NAME)); } initialUrlBuilder .append(webServer.getWebContentUrl()) .append('/') .append(configurationInitialPage); } String queryString = configuration.getPropertyString(CONFIGURATION_INITIAL_URL_QUERY_STRING); if (queryString != null) { initialUrlBuilder.append("?").append(queryString); } initialUrl = initialUrlBuilder.toString(); browserDebug = configuration.getPropertyBoolean(CONFIGURATION_BROWSER_DEBUG, false); browserStartup = configuration.getPropertyBoolean(CONFIGURATION_BROWSER_STARTUP, true); }