spring-bootvaadinvaadin4springvaadin-pushvaadin-spring-boot

Vaadin @Push with Vaadin4Spring Security


Is anyone using Vaadin @Push with vaadin-spring-boot-starter and Vaadin4Spring Security extension?

Here is Vaadin related dependencies on our project:

  compile 'com.vaadin:vaadin-client-compiled:7.5.8'
  compile 'com.vaadin:vaadin-client:7.5.8'
  compile 'com.vaadin:vaadin-themes:7.5.8'
  compile 'com.vaadin:vaadin-server:7.5.8'
  compile 'com.vaadin:vaadin-push:7.5.8'

  // Official VaadinSpring Integration
  compile("com.vaadin:vaadin-spring-boot-starter:1.0.0")

  //Vaadin extentions - in the future more of those will go to official VaadinSpring Integration
  compile("org.vaadin.spring.extensions:vaadin-spring-ext-security:0.0.6.RELEASE")
  compile("org.vaadin.spring.extensions:vaadin-spring-ext-core:0.0.6.RELEASE")
  compile("org.vaadin.spring.extensions:vaadin-spring-ext-boot:0.0.6.RELEASE")
  compile("org.vaadin.spring.extensions:vaadin-spring-ext-test:0.0.6.RELEASE")

Here is the annotations on UI Class

@Theme("mytheme")
@Title(com.test.util.Constants.TITLE)
@EnableOAuth2Client
@SpringUI
@Push
public class MyVaadinUI extends UI {
...
}

And, Application.java ;

@EnableVaadinExtensions
@SpringBootApplication
@EnableConfigurationProperties
@EnableI18N
@EnableEventBus
@RestController
@EnableOAuth2Client
public class Application extends SpringBootServletInitializer {
  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }

  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(Application.class);
  }

  @Bean 
  public RequestContextListener requestContextListener(){
    return new RequestContextListener();
  } 

  @Bean
  public FilterRegistrationBean hiddenHttpMethodFilter() {
    HiddenHttpMethodFilter hiddenHttpMethodFilter = new HiddenHttpMethodFilter();
    FilterRegistrationBean registrationBean = new FilterRegistrationBean();
    registrationBean.setFilter(hiddenHttpMethodFilter);
    return registrationBean;
  }

  @Bean(name = "messageSource")
  public ResourceBundleMessageSource messageSource() {
    ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
    messageSource.setBasename("messages/messages");
    logger.debug("Returning messageSource: " + ((messageSource != null) ? messageSource.toString() : "NULL"));
    return messageSource;
  }

}

As soon as we call security.login(username.getValue(), password.getValue()); (security is org.vaadin.spring.security.VaadinSecurity;)

we get the below exception;

16:36:35.272 [http-nio-8080-exec-9] ERROR c.b.g.c.s.v.views.login.LoginBox/login Login ERROR occured during login.org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.httpService': Scope 'request' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.

I appreciate any help you can provide.


Solution

  • You are using Websockets, which do not use servlet requests and will not activate the "request" scope automatically.

    If you use @Push(transport=WEBSOCKET_XHR) it should work, as the websockets channel will then be used only for server -> client pushes and standard HTTP requests will be used for client -> server messages.