From 606de67aa29420c08bb465960a122e7b68eb7ab6 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 6 Oct 2020 11:50:06 +0200 Subject: [PATCH] added static property support to GUI and fix setting gui endpoint --- .../seb/sebserver/gui/RAPConfiguration.java | 5 ++- .../seb/sebserver/gui/RAPSpringConfig.java | 13 ++++-- .../StaticApplicationPropertyResolver.java | 43 +++++++++++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/StaticApplicationPropertyResolver.java diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/RAPConfiguration.java b/src/main/java/ch/ethz/seb/sebserver/gui/RAPConfiguration.java index a282b658..36f33841 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/RAPConfiguration.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/RAPConfiguration.java @@ -42,6 +42,9 @@ public class RAPConfiguration implements ApplicationConfiguration { public void configure(final Application application) { try { + final String guiEntrypoint = StaticApplicationPropertyResolver + .getProperty("sebserver.gui.entrypoint", "/gui"); + // TODO get file path from properties //application.addStyleSheet(RWT.DEFAULT_THEME_ID, "static/css/sebserver.css"); application.addStyleSheet(DEFAULT_THEME_NAME, "resource/theme/default.css"); @@ -54,7 +57,7 @@ public class RAPConfiguration implements ApplicationConfiguration { properties.put(WebClient.BODY_HTML, "Loading Application"); properties.put(WebClient.THEME_ID, DEFAULT_THEME_NAME); // properties.put(WebClient.FAVICON, "icons/favicon.png"); - application.addEntryPoint("/gui", new RAPSpringEntryPointFactory(), properties); + application.addEntryPoint(guiEntrypoint, new RAPSpringEntryPointFactory(), properties); } catch (final RuntimeException re) { throw re; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/RAPSpringConfig.java b/src/main/java/ch/ethz/seb/sebserver/gui/RAPSpringConfig.java index 3b24c2d3..6a2f0c71 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/RAPSpringConfig.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/RAPSpringConfig.java @@ -8,7 +8,9 @@ package ch.ethz.seb.sebserver.gui; -import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; +import javax.servlet.ServletContext; +import javax.servlet.ServletContextListener; + import org.eclipse.rap.rwt.engine.RWTServlet; import org.eclipse.rap.rwt.engine.RWTServletContextListener; import org.slf4j.Logger; @@ -22,8 +24,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.ReloadableResourceBundleMessageSource; -import javax.servlet.ServletContext; -import javax.servlet.ServletContextListener; +import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; @Configuration @GuiProfile @@ -37,8 +38,14 @@ public class RAPSpringConfig { @Value("${sebserver.gui.external.messages:messages}") private String externalMessagesPath; + @Bean + public StaticApplicationPropertyResolver staticApplicationPropertyResolver() { + return new StaticApplicationPropertyResolver(); + } + @Bean public ServletContextInitializer initializer() { + staticApplicationPropertyResolver(); return new RAPServletContextInitializer(); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/StaticApplicationPropertyResolver.java b/src/main/java/ch/ethz/seb/sebserver/gui/StaticApplicationPropertyResolver.java new file mode 100644 index 00000000..7528b3e0 --- /dev/null +++ b/src/main/java/ch/ethz/seb/sebserver/gui/StaticApplicationPropertyResolver.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2020 ETH Zürich, Educational Development and Technology (LET) + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +package ch.ethz.seb.sebserver.gui; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.core.env.Environment; + +public class StaticApplicationPropertyResolver implements ApplicationContextAware { + + private static final Logger log = LoggerFactory.getLogger(StaticApplicationPropertyResolver.class); + + private static ApplicationContext CONTEXT; + + public StaticApplicationPropertyResolver() { + // TODO Auto-generated constructor stub + } + + @Override + public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException { + CONTEXT = applicationContext; + } + + public static String getProperty(final String name, final String defaultValue) { + try { + final Environment env = CONTEXT.getBean(Environment.class); + return env.getProperty(name, defaultValue); + } catch (final Exception e) { + log.warn("Failed to get property: {} from static context. Return default value: {}", name, defaultValue); + return defaultValue; + } + } + +}