1

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.

turgos
  • 1,464
  • 1
  • 17
  • 28

1 Answers1

4

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.

Artur Signell
  • 1,694
  • 9
  • 9
  • Thank you for the reply Artur. This solution worked on Vaadin 7.6.1, but currently we are using version 7.5.8. We could not upgrade because one of the addon had an issue with 7.6. Seems like WEBSOCKET_XHR is not available on 7.5.8. Do you have any possible solution for Vaadin 7.5.8? Thank you again for your help. – turgos Feb 23 '16 at 00:22
  • LONG_POLLING is also HTTP based so that should work also in 7.5. For websockets and 7.5 you probably would need to initialize the Spring context yourself in an overridden VaadinService.requestStart – Artur Signell Feb 24 '16 at 12:18