2019-01-28 16:58:06 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 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 javax.servlet.ServletContext;
|
|
|
|
import javax.servlet.ServletContextListener;
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
|
|
|
|
import org.eclipse.rap.rwt.engine.RWTServlet;
|
|
|
|
import org.eclipse.rap.rwt.engine.RWTServletContextListener;
|
2019-09-04 16:01:04 +02:00
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
2019-01-28 16:58:06 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.boot.web.servlet.ServletContextInitializer;
|
|
|
|
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
|
|
|
|
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
2019-09-04 13:23:33 +02:00
|
|
|
import org.springframework.context.MessageSource;
|
2019-01-28 16:58:06 +01:00
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
2019-09-04 13:23:33 +02:00
|
|
|
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
|
2019-01-28 16:58:06 +01:00
|
|
|
|
|
|
|
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@GuiProfile
|
|
|
|
public class RAPSpringConfig {
|
|
|
|
|
2019-09-04 16:01:04 +02:00
|
|
|
private static final Logger log = LoggerFactory.getLogger(RAPSpringConfig.class);
|
|
|
|
|
2019-01-28 16:58:06 +01:00
|
|
|
@Value("${sebserver.gui.entrypoint}")
|
|
|
|
private String entrypoint;
|
|
|
|
|
2019-09-04 15:49:36 +02:00
|
|
|
@Value("${sebserver.gui.external.messages:messages}")
|
|
|
|
private String externalMessagesPath;
|
|
|
|
|
2019-01-28 16:58:06 +01:00
|
|
|
@Bean
|
|
|
|
public ServletContextInitializer initializer() {
|
2019-02-27 12:44:03 +01:00
|
|
|
return new RAPServletContextInitializer();
|
2019-01-28 16:58:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
public ServletListenerRegistrationBean<ServletContextListener> listenerRegistrationBean() {
|
|
|
|
final ServletListenerRegistrationBean<ServletContextListener> bean =
|
|
|
|
new ServletListenerRegistrationBean<>();
|
|
|
|
bean.setListener(new RWTServletContextListener());
|
|
|
|
return bean;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
public ServletRegistrationBean<RWTServlet> servletRegistrationBean() {
|
|
|
|
return new ServletRegistrationBean<>(new RWTServlet(), this.entrypoint + "/*");
|
|
|
|
}
|
|
|
|
|
2019-09-04 13:23:33 +02:00
|
|
|
@Bean
|
|
|
|
public MessageSource messageSource() {
|
2019-09-04 15:49:36 +02:00
|
|
|
final ReloadableResourceBundleMessageSource reloadableResourceBundleMessageSource =
|
|
|
|
new ReloadableResourceBundleMessageSource();
|
|
|
|
|
2019-09-05 08:37:18 +02:00
|
|
|
log.info(" +++ Register external messages resources from: {}", this.externalMessagesPath);
|
2019-09-04 16:01:04 +02:00
|
|
|
|
2019-09-04 15:49:36 +02:00
|
|
|
reloadableResourceBundleMessageSource.setBasenames(
|
|
|
|
this.externalMessagesPath,
|
|
|
|
"classpath:messages");
|
|
|
|
|
|
|
|
return reloadableResourceBundleMessageSource;
|
2019-09-04 13:23:33 +02:00
|
|
|
}
|
|
|
|
|
2019-02-27 12:44:03 +01:00
|
|
|
private static class RAPServletContextInitializer implements ServletContextInitializer {
|
|
|
|
@Override
|
|
|
|
public void onStartup(final ServletContext servletContext) throws ServletException {
|
|
|
|
servletContext.setInitParameter(
|
|
|
|
"org.eclipse.rap.applicationConfiguration",
|
|
|
|
RAPConfiguration.class.getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-28 16:58:06 +01:00
|
|
|
}
|