@Test public void testConfigure() { int testPort = WebServerActivityResourceConfigurator.WEB_SERVER_PORT_DEFAULT + 100; String webSocketUri = "foo/bar/bletch"; String initialUrl = "snafu"; String query = "oorgle"; configuration.setValue("space.activity.webapp.web.server.port", Integer.toString(testPort)); configuration.setValue("space.activity.webapp.content.location", "webapp"); configuration.setValue("space.activity.webapp.web.server.websocket.uri", webSocketUri); configuration.setValue("space.activity.webapp.url.initial", initialUrl); configuration.setValue("space.activity.webapp.url.query_string", query); configurator.configure(null, activity, webServer); Mockito.verify(webServer).setPort(testPort); Mockito.verify(webServer).addStaticContentHandler("/" + activityName, new File(installDirectory, "webapp")); Assert.assertEquals(webSocketUri, configurator.getWebSocketUriPrefix()); String webBaseUrl = "http: String webContentUrl = webBaseUrl + "/" + activityName; Assert.assertEquals(webBaseUrl, configurator.getWebBaseUrl()); Assert.assertEquals(webContentUrl, configurator.getWebContentUrl()); Assert.assertEquals(webContentUrl + "/" + initialUrl + "?" + query, configurator.getWebInitialPage()); }
@Override public void configure(String resourceName, Activity activity, WebServer webServer) { resourceName = resourceName != null ? resourceName.trim() : ""; String configurationPrefix = resourceName.isEmpty() ? WebActivityConfiguration.CONFIGURATION_PREFIX_WEBAPP : WebActivityConfiguration.CONFIGURATION_PREFIX_WEBAPP + "." + resourceName; Configuration configuration = activity.getConfiguration(); webSocketUriPrefix = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_WEBSOCKET_URI); webServerPort = configuration.getPropertyInteger(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_PORT, WEB_SERVER_PORT_DEFAULT); webServer.setPort(webServerPort); String serverName = (resourceName.isEmpty()) ? String.format("%sWebServer", activity.getName()) : String.format("%s_%s_WebServer", activity.getName(), resourceName); webServer.setServerName(serverName); boolean secure = configuration.getPropertyBoolean(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_SECURE, false); webServer.setSecureServer(secure); if (secure) { String certificatePath = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_SSL_CERTIFICATE); String privateKeyPath = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_SSL_PRIVATE_KEY); boolean hasCertificatePath = certificatePath != null && !certificatePath.trim().isEmpty(); boolean hasPrivateKeyPath = privateKeyPath != null && !privateKeyPath.trim().isEmpty(); if (hasCertificatePath && hasPrivateKeyPath) { webServer.setSslCertificates(new File(certificatePath.trim()), new File(privateKeyPath.trim())); } else if (hasCertificatePath ^ hasPrivateKeyPath) { throw new SimpleInteractiveSpacesException( "Both a certificate chain file and a private key file must be supplied."); } } boolean debugMode = configuration.getPropertyBoolean(WebActivityConfiguration.CONFIGURATION_WEBAPP_DEBUG, false); webServer.setDebugMode(debugMode); crossOriginAllowed = configuration.getPropertyBoolean(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_ENABLE_CROSS_ORIGIN, WEB_SERVER_DEFAULT_ENABLE_CROSS_ORIGIN); String webServerHost = configuration.getPropertyString(InteractiveSpacesEnvironment.CONFIGURATION_HOST_ADDRESS, WEB_SERVER_DEFAULT_HOST); webContentPath = "/" + activity.getName(); webBaseUrl = ((secure) ? "https" : "http") + ": webContentUrl = webBaseUrl + webContentPath; StringBuilder webInitialPageBuilder = new StringBuilder(); webInitialPageBuilder .append(webContentUrl) .append(WebActivityConfiguration.WEB_PATH_SEPARATOR) .append( configuration.getPropertyString(configurationPrefix + WebActivityConfiguration.CONFIGURATION_SUFFIX_INITIAL_PAGE, WebActivityConfiguration.DEFAULT_INITIAL_PAGE)); String queryString = configuration.getPropertyString(configurationPrefix + WebActivityConfiguration.CONFIGURATION_SUFFIX_INITIAL_URL_QUERY_STRING); if (queryString != null) { webInitialPageBuilder.append(WebActivityConfiguration.WEB_QUERY_STRING_SEPARATOR).append(queryString.trim()); } webInitialPage = webInitialPageBuilder.toString(); String contentLocation = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_CONTENT_LOCATION); if (contentLocation != null) { webContentBaseDir = new File(activity.getActivityFilesystem().getInstallDirectory(), contentLocation); webServer.addStaticContentHandler(webContentPath, webContentBaseDir); } }
WebServerActivityResourceConfigurator implements ActivityResourceConfigurator<WebServer> { @Override public void configure(String resourceName, Activity activity, WebServer webServer) { resourceName = resourceName != null ? resourceName.trim() : ""; String configurationPrefix = resourceName.isEmpty() ? WebActivityConfiguration.CONFIGURATION_PREFIX_WEBAPP : WebActivityConfiguration.CONFIGURATION_PREFIX_WEBAPP + "." + resourceName; Configuration configuration = activity.getConfiguration(); webSocketUriPrefix = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_WEBSOCKET_URI); webServerPort = configuration.getPropertyInteger(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_PORT, WEB_SERVER_PORT_DEFAULT); webServer.setPort(webServerPort); String serverName = (resourceName.isEmpty()) ? String.format("%sWebServer", activity.getName()) : String.format("%s_%s_WebServer", activity.getName(), resourceName); webServer.setServerName(serverName); boolean secure = configuration.getPropertyBoolean(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_SECURE, false); webServer.setSecureServer(secure); if (secure) { String certificatePath = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_SSL_CERTIFICATE); String privateKeyPath = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_SSL_PRIVATE_KEY); boolean hasCertificatePath = certificatePath != null && !certificatePath.trim().isEmpty(); boolean hasPrivateKeyPath = privateKeyPath != null && !privateKeyPath.trim().isEmpty(); if (hasCertificatePath && hasPrivateKeyPath) { webServer.setSslCertificates(new File(certificatePath.trim()), new File(privateKeyPath.trim())); } else if (hasCertificatePath ^ hasPrivateKeyPath) { throw new SimpleInteractiveSpacesException( "Both a certificate chain file and a private key file must be supplied."); } } boolean debugMode = configuration.getPropertyBoolean(WebActivityConfiguration.CONFIGURATION_WEBAPP_DEBUG, false); webServer.setDebugMode(debugMode); crossOriginAllowed = configuration.getPropertyBoolean(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_ENABLE_CROSS_ORIGIN, WEB_SERVER_DEFAULT_ENABLE_CROSS_ORIGIN); String webServerHost = configuration.getPropertyString(InteractiveSpacesEnvironment.CONFIGURATION_HOST_ADDRESS, WEB_SERVER_DEFAULT_HOST); webContentPath = "/" + activity.getName(); webBaseUrl = ((secure) ? "https" : "http") + ": webContentUrl = webBaseUrl + webContentPath; StringBuilder webInitialPageBuilder = new StringBuilder(); webInitialPageBuilder .append(webContentUrl) .append(WebActivityConfiguration.WEB_PATH_SEPARATOR) .append( configuration.getPropertyString(configurationPrefix + WebActivityConfiguration.CONFIGURATION_SUFFIX_INITIAL_PAGE, WebActivityConfiguration.DEFAULT_INITIAL_PAGE)); String queryString = configuration.getPropertyString(configurationPrefix + WebActivityConfiguration.CONFIGURATION_SUFFIX_INITIAL_URL_QUERY_STRING); if (queryString != null) { webInitialPageBuilder.append(WebActivityConfiguration.WEB_QUERY_STRING_SEPARATOR).append(queryString.trim()); } webInitialPage = webInitialPageBuilder.toString(); String contentLocation = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_CONTENT_LOCATION); if (contentLocation != null) { webContentBaseDir = new File(activity.getActivityFilesystem().getInstallDirectory(), contentLocation); webServer.addStaticContentHandler(webContentPath, webContentBaseDir); } } }
WebServerActivityResourceConfigurator implements ActivityResourceConfigurator<WebServer> { @Override public void configure(String resourceName, Activity activity, WebServer webServer) { resourceName = resourceName != null ? resourceName.trim() : ""; String configurationPrefix = resourceName.isEmpty() ? WebActivityConfiguration.CONFIGURATION_PREFIX_WEBAPP : WebActivityConfiguration.CONFIGURATION_PREFIX_WEBAPP + "." + resourceName; Configuration configuration = activity.getConfiguration(); webSocketUriPrefix = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_WEBSOCKET_URI); webServerPort = configuration.getPropertyInteger(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_PORT, WEB_SERVER_PORT_DEFAULT); webServer.setPort(webServerPort); String serverName = (resourceName.isEmpty()) ? String.format("%sWebServer", activity.getName()) : String.format("%s_%s_WebServer", activity.getName(), resourceName); webServer.setServerName(serverName); boolean secure = configuration.getPropertyBoolean(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_SECURE, false); webServer.setSecureServer(secure); if (secure) { String certificatePath = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_SSL_CERTIFICATE); String privateKeyPath = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_SSL_PRIVATE_KEY); boolean hasCertificatePath = certificatePath != null && !certificatePath.trim().isEmpty(); boolean hasPrivateKeyPath = privateKeyPath != null && !privateKeyPath.trim().isEmpty(); if (hasCertificatePath && hasPrivateKeyPath) { webServer.setSslCertificates(new File(certificatePath.trim()), new File(privateKeyPath.trim())); } else if (hasCertificatePath ^ hasPrivateKeyPath) { throw new SimpleInteractiveSpacesException( "Both a certificate chain file and a private key file must be supplied."); } } boolean debugMode = configuration.getPropertyBoolean(WebActivityConfiguration.CONFIGURATION_WEBAPP_DEBUG, false); webServer.setDebugMode(debugMode); crossOriginAllowed = configuration.getPropertyBoolean(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_ENABLE_CROSS_ORIGIN, WEB_SERVER_DEFAULT_ENABLE_CROSS_ORIGIN); String webServerHost = configuration.getPropertyString(InteractiveSpacesEnvironment.CONFIGURATION_HOST_ADDRESS, WEB_SERVER_DEFAULT_HOST); webContentPath = "/" + activity.getName(); webBaseUrl = ((secure) ? "https" : "http") + ": webContentUrl = webBaseUrl + webContentPath; StringBuilder webInitialPageBuilder = new StringBuilder(); webInitialPageBuilder .append(webContentUrl) .append(WebActivityConfiguration.WEB_PATH_SEPARATOR) .append( configuration.getPropertyString(configurationPrefix + WebActivityConfiguration.CONFIGURATION_SUFFIX_INITIAL_PAGE, WebActivityConfiguration.DEFAULT_INITIAL_PAGE)); String queryString = configuration.getPropertyString(configurationPrefix + WebActivityConfiguration.CONFIGURATION_SUFFIX_INITIAL_URL_QUERY_STRING); if (queryString != null) { webInitialPageBuilder.append(WebActivityConfiguration.WEB_QUERY_STRING_SEPARATOR).append(queryString.trim()); } webInitialPage = webInitialPageBuilder.toString(); String contentLocation = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_CONTENT_LOCATION); if (contentLocation != null) { webContentBaseDir = new File(activity.getActivityFilesystem().getInstallDirectory(), contentLocation); webServer.addStaticContentHandler(webContentPath, webContentBaseDir); } }  }
WebServerActivityResourceConfigurator implements ActivityResourceConfigurator<WebServer> { @Override public void configure(String resourceName, Activity activity, WebServer webServer) { resourceName = resourceName != null ? resourceName.trim() : ""; String configurationPrefix = resourceName.isEmpty() ? WebActivityConfiguration.CONFIGURATION_PREFIX_WEBAPP : WebActivityConfiguration.CONFIGURATION_PREFIX_WEBAPP + "." + resourceName; Configuration configuration = activity.getConfiguration(); webSocketUriPrefix = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_WEBSOCKET_URI); webServerPort = configuration.getPropertyInteger(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_PORT, WEB_SERVER_PORT_DEFAULT); webServer.setPort(webServerPort); String serverName = (resourceName.isEmpty()) ? String.format("%sWebServer", activity.getName()) : String.format("%s_%s_WebServer", activity.getName(), resourceName); webServer.setServerName(serverName); boolean secure = configuration.getPropertyBoolean(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_SECURE, false); webServer.setSecureServer(secure); if (secure) { String certificatePath = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_SSL_CERTIFICATE); String privateKeyPath = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_SSL_PRIVATE_KEY); boolean hasCertificatePath = certificatePath != null && !certificatePath.trim().isEmpty(); boolean hasPrivateKeyPath = privateKeyPath != null && !privateKeyPath.trim().isEmpty(); if (hasCertificatePath && hasPrivateKeyPath) { webServer.setSslCertificates(new File(certificatePath.trim()), new File(privateKeyPath.trim())); } else if (hasCertificatePath ^ hasPrivateKeyPath) { throw new SimpleInteractiveSpacesException( "Both a certificate chain file and a private key file must be supplied."); } } boolean debugMode = configuration.getPropertyBoolean(WebActivityConfiguration.CONFIGURATION_WEBAPP_DEBUG, false); webServer.setDebugMode(debugMode); crossOriginAllowed = configuration.getPropertyBoolean(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_ENABLE_CROSS_ORIGIN, WEB_SERVER_DEFAULT_ENABLE_CROSS_ORIGIN); String webServerHost = configuration.getPropertyString(InteractiveSpacesEnvironment.CONFIGURATION_HOST_ADDRESS, WEB_SERVER_DEFAULT_HOST); webContentPath = "/" + activity.getName(); webBaseUrl = ((secure) ? "https" : "http") + ": webContentUrl = webBaseUrl + webContentPath; StringBuilder webInitialPageBuilder = new StringBuilder(); webInitialPageBuilder .append(webContentUrl) .append(WebActivityConfiguration.WEB_PATH_SEPARATOR) .append( configuration.getPropertyString(configurationPrefix + WebActivityConfiguration.CONFIGURATION_SUFFIX_INITIAL_PAGE, WebActivityConfiguration.DEFAULT_INITIAL_PAGE)); String queryString = configuration.getPropertyString(configurationPrefix + WebActivityConfiguration.CONFIGURATION_SUFFIX_INITIAL_URL_QUERY_STRING); if (queryString != null) { webInitialPageBuilder.append(WebActivityConfiguration.WEB_QUERY_STRING_SEPARATOR).append(queryString.trim()); } webInitialPage = webInitialPageBuilder.toString(); String contentLocation = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_CONTENT_LOCATION); if (contentLocation != null) { webContentBaseDir = new File(activity.getActivityFilesystem().getInstallDirectory(), contentLocation); webServer.addStaticContentHandler(webContentPath, webContentBaseDir); } }  @Override void configure(String resourceName, Activity activity, WebServer webServer); String getWebBaseUrl(); String getWebContentUrl(); int getWebServerPort(); String getWebContentPath(); File getWebContentBaseDir(); String getWebSocketUriPrefix(); void setWebSocketUriPrefix(String webSocketUriPrefix); String getWebInitialPage(); boolean getCrossOriginAllowed(); }
WebServerActivityResourceConfigurator implements ActivityResourceConfigurator<WebServer> { @Override public void configure(String resourceName, Activity activity, WebServer webServer) { resourceName = resourceName != null ? resourceName.trim() : ""; String configurationPrefix = resourceName.isEmpty() ? WebActivityConfiguration.CONFIGURATION_PREFIX_WEBAPP : WebActivityConfiguration.CONFIGURATION_PREFIX_WEBAPP + "." + resourceName; Configuration configuration = activity.getConfiguration(); webSocketUriPrefix = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_WEBSOCKET_URI); webServerPort = configuration.getPropertyInteger(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_PORT, WEB_SERVER_PORT_DEFAULT); webServer.setPort(webServerPort); String serverName = (resourceName.isEmpty()) ? String.format("%sWebServer", activity.getName()) : String.format("%s_%s_WebServer", activity.getName(), resourceName); webServer.setServerName(serverName); boolean secure = configuration.getPropertyBoolean(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_SECURE, false); webServer.setSecureServer(secure); if (secure) { String certificatePath = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_SSL_CERTIFICATE); String privateKeyPath = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_SSL_PRIVATE_KEY); boolean hasCertificatePath = certificatePath != null && !certificatePath.trim().isEmpty(); boolean hasPrivateKeyPath = privateKeyPath != null && !privateKeyPath.trim().isEmpty(); if (hasCertificatePath && hasPrivateKeyPath) { webServer.setSslCertificates(new File(certificatePath.trim()), new File(privateKeyPath.trim())); } else if (hasCertificatePath ^ hasPrivateKeyPath) { throw new SimpleInteractiveSpacesException( "Both a certificate chain file and a private key file must be supplied."); } } boolean debugMode = configuration.getPropertyBoolean(WebActivityConfiguration.CONFIGURATION_WEBAPP_DEBUG, false); webServer.setDebugMode(debugMode); crossOriginAllowed = configuration.getPropertyBoolean(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_ENABLE_CROSS_ORIGIN, WEB_SERVER_DEFAULT_ENABLE_CROSS_ORIGIN); String webServerHost = configuration.getPropertyString(InteractiveSpacesEnvironment.CONFIGURATION_HOST_ADDRESS, WEB_SERVER_DEFAULT_HOST); webContentPath = "/" + activity.getName(); webBaseUrl = ((secure) ? "https" : "http") + ": webContentUrl = webBaseUrl + webContentPath; StringBuilder webInitialPageBuilder = new StringBuilder(); webInitialPageBuilder .append(webContentUrl) .append(WebActivityConfiguration.WEB_PATH_SEPARATOR) .append( configuration.getPropertyString(configurationPrefix + WebActivityConfiguration.CONFIGURATION_SUFFIX_INITIAL_PAGE, WebActivityConfiguration.DEFAULT_INITIAL_PAGE)); String queryString = configuration.getPropertyString(configurationPrefix + WebActivityConfiguration.CONFIGURATION_SUFFIX_INITIAL_URL_QUERY_STRING); if (queryString != null) { webInitialPageBuilder.append(WebActivityConfiguration.WEB_QUERY_STRING_SEPARATOR).append(queryString.trim()); } webInitialPage = webInitialPageBuilder.toString(); String contentLocation = configuration.getPropertyString(configurationPrefix + CONFIGURATION_SUFFIX_WEBAPP_CONTENT_LOCATION); if (contentLocation != null) { webContentBaseDir = new File(activity.getActivityFilesystem().getInstallDirectory(), contentLocation); webServer.addStaticContentHandler(webContentPath, webContentBaseDir); } }  @Override void configure(String resourceName, Activity activity, WebServer webServer); String getWebBaseUrl(); String getWebContentUrl(); int getWebServerPort(); String getWebContentPath(); File getWebContentBaseDir(); String getWebSocketUriPrefix(); void setWebSocketUriPrefix(String webSocketUriPrefix); String getWebInitialPage(); boolean getCrossOriginAllowed(); static final String CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_PORT; static final String CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_WEBSOCKET_URI; static final String CONFIGURATION_SUFFIX_WEBAPP_CONTENT_LOCATION; static final String CONFIGURATION_SUFFIX_WEBAPP_ENABLE_CROSS_ORIGIN; static final String CONFIGURATION_SUFFIX_WEBAPP_WEB_SERVER_SECURE; static final String CONFIGURATION_SUFFIX_WEBAPP_SSL_CERTIFICATE; static final String CONFIGURATION_SUFFIX_WEBAPP_SSL_PRIVATE_KEY; static final int WEB_SERVER_PORT_DEFAULT; static final String WEB_SERVER_DEFAULT_HOST; static final boolean WEB_SERVER_DEFAULT_ENABLE_CROSS_ORIGIN; }