Setting VaadinServlet Init-Parameters when using vaadin-spring (and no web.

Hey guys,

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:

org.atmosphere.cpr.AtmosphereInterceptor acolson.atmosphere.RecoverSecurityContextAtmosphereInterceptor

If I add it to it is ignored.

You should be able to give it as an annotation in you Servlet that extends VaadinServlet using the

@WebServlet(value = “/*”, asyncSupported = true, initParams = {
@WebInitParam(name = “org.atmosphere.cpr.AtmosphereInterceptor”, value = “acolson.atmosphere.RecoverSecurityContextAtmosphereInterceptor”)})

For more information on this see:

Thanks for the hint - I tried it but it seems to be not working the way I’m doing it:

public class Application
public static void main(String args) throws Throwable
{, args);

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
    protected void servletInitialized() throws ServletException {

[/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.

Any hints what I’m doing wrong?

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:

public static class MyVaadinSpringServlet extends SpringVaadinServlet {
public init(ServletConfig config) throws ServletException {
final ServletContext context = servletConfig.getServletContext();
// Set own initParameters here.

    protected void servletInitialized() throws ServletException {

[/code]This is probably as much as I can help with in this case as I’m not familiar with the add-on.
Hope this helps.

I already tried that - unfortunately it leads to an “Allocate exception”:

2015-05-18 10:31:17.270 ERROR 13708 --- [nio-8080-exec-5]
  : 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(
    at org.apache.catalina.core.ApplicationContextFacade.setInitParameter(
    at com.fumm.Application$MyVaadinSpringServlet.init(
    at org.apache.catalina.core.StandardWrapper.initServlet(
    at org.apache.catalina.core.StandardWrapper.allocate(
    at org.apache.catalina.core.StandardWrapperValve.invoke(
    at org.apache.catalina.core.StandardContextValve.invoke(
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(
    at org.apache.catalina.core.StandardHostValve.invoke(
    at org.apache.catalina.valves.ErrorReportValve.invoke(
    at org.apache.catalina.core.StandardEngineValve.invoke(
    at org.apache.catalina.connector.CoyoteAdapter.service(
    at org.apache.coyote.http11.AbstractHttp11Processor.process(
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(
    at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$ Source)
    at org.apache.tomcat.util.threads.TaskThread$
    at 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!

Perhaps you could override the createDeploymentConfiguration?

@Override protected DeploymentConfiguration createDeploymentConfiguration(Properties initParameters) {
    return super.createDeploymentConfiguration(initParameters);

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:

public class MyVaadinServletConfiguration extends VaadinServletConfiguration
ServletRegistrationBean vaadinServletRegistration()
return createServletRegistrationBean();

protected void addInitParameters(
        ServletRegistrationBean servletRegistrationBean)
    addInitParameter(servletRegistrationBean, "org.atmosphere.cpr.AtmosphereInterceptor", "acolson.atmosphere.RecoverSecurityContextAtmosphereInterceptor");    
    addInitParameter(servletRegistrationBean, ApplicationConfig.JSR356_MAPPING_PATH, "/VAADIN");

private void addInitParameter(
        ServletRegistrationBean servletRegistrationBean, String paramName,
        String propertyValue) {
    if (propertyValue != null) {
        getLogger().info("Set servlet init parameter [{}]

= [{}]
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?