I am using the new vaadin-spring / vaadin-spring-boot addon and wonder how I can set some custom Init-parameters to Vaadin-Servlet when not using a web.xml (because old and ugly).
Specifically I want to set what I would have done with web.xml the following way:
Thanks for the hint - I tried it but it seems to be not working the way I’m doing it:
[code] @EnableAutoConfiguration @ComponentScan @Configuration @EnableJpaRepositories
public class Application
{
public static void main(String args) throws Throwable
{
SpringApplication.run(Application.class, args);
}
@Bean
public SpringVaadinServlet createMyVaadinServlet()
{
return new MyVaadinSpringServlet();
}
@WebServlet(value = "/ui", asyncSupported = true, initParams = {
@WebInitParam(name = "org.atmosphere.cpr.AtmosphereInterceptor", value = "acolson.atmosphere.RecoverSecurityContextAtmosphereInterceptor")})
public static class MyVaadinSpringServlet extends SpringVaadinServlet
{
@Override
protected void servletInitialized() throws ServletException {
super.servletInitialized();
}
}
}
[/code]I only overrride the servletInitialized to track if the right servlet is instantiated (it is) and to see which parameters are stored in ServletConfig of the VaadinServlet init-method.
Unfortunately I can’t find any parameter entries “org.atmosphere.cpr.AtmosphereInterceptor” or something similar in the parameters map of the StandardWrapperFacade.
Shouldn’t I see new WebInitParams there?
Also no method of RecoverSecurityContextAtmosphereInterceptor is ever called.
Hi.
I don’t know how I missed the fact that you are using the spring-vaadin add-on.
The only thing I can come up with on short notice would be to override the init method in
your VaadinSpringServlet like:
[code]
public static class MyVaadinSpringServlet extends SpringVaadinServlet { @Override
public init(ServletConfig config) throws ServletException {
final ServletContext context = servletConfig.getServletContext();
// Set own initParameters here.
context.setInitParameter(“org.atmosphere.cpr.AtmosphereInterceptor”,
“acolson.atmosphere.RecoverSecurityContextAtmosphereInterceptor”);
I already tried that - unfortunately it leads to an “Allocate exception”:
2015-05-18 10:31:17.270 ERROR 13708 --- [nio-8080-exec-5]
o.a.c.c.C.[.[.[.[myVaadinSpringServlet]
: Allocate exception for servlet myVaadinSpringServlet
java.lang.IllegalStateException: Initialization parameters can not be set after the context has been initialized
at org.apache.catalina.core.ApplicationContext.setInitParameter(ApplicationContext.java:1228)
at org.apache.catalina.core.ApplicationContextFacade.setInitParameter(ApplicationContextFacade.java:624)
at com.fumm.Application$MyVaadinSpringServlet.init(Application.java:45)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:837)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
I guess it has to be set in a different way - just can’t figure out how so far - but thanks for your help anyway!
Hm, it seems to do the trick (at least I can log in now again with Spring Security while Push is enabled).
Though I have the impression this is more a hack than a clean solution. I’m playing around with ServletContainerInitializer at the moment - will post if I find a different solution.
Many thanks for your help, though!
Overriding DeploymentConfiguration didn’t do the trick in the end.
Though I have a feeling about being not very clean the following approach worked for me:
[code] @Configuration @EnableConfigurationProperties(VaadinServletConfigurationProperties.class) @Import(VaadinServletConfiguration.class)
public class MyVaadinServletConfiguration extends VaadinServletConfiguration
{ @Bean
ServletRegistrationBean vaadinServletRegistration()
{
return createServletRegistrationBean();
}
= [{}]
",
paramName, propertyValue);
servletRegistrationBean.addInitParameter(paramName, propertyValue);
}
}
}
[/code]It would be absolutely great if one of the guys working on vaadin-spring / vaadin-spring-boot addon could give feedback on that solution.
Is it intended to add Init-Parameters that way to SpringVaadinServlet?