Migrating from addon SpringVaadinIntegration to Vaadin Spring (official)

Hi,
I have been using
SpringVaadinIntegration
with satisfaction. Now that an
official spring addon
is released, I’d like to migrate.
I followed the guide and everything works fine, except when I try to open a new BrowserWindow with the same UI, I get:

HTTP Status 404 - Request was not handled by any registered handler
BrowserWindow Request was not handled by any registered handler

my UI class:

[code]
@Component
@Theme(“mytheme”)
@SpringUI
public class MyUI extends UI
{
private static final long serialVersionUID = 1L;

@WebServlet(urlPatterns = {"/app/*", "/VAADIN/*"}, asyncSupported = true)
public static class Servlet extends SpringVaadinServlet {
    private static final long serialVersionUID = 1L;
}

@WebListener
public static class MyContextLoaderListener extends ContextLoaderListener {
}

@Configuration
@EnableVaadin
public static class MyConfiguration {
}

public MyUI() {
    super();
}
@Override
protected void init(VaadinRequest request) {
    VerticalLayout mainContent = getMainContent();
    setContent(mainContent);
}

[/code]my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>Test</display-name>
    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:log4j.properties</param-value>
    </context-param>
    <context-param>
        <description>Vaadin production mode</description>
        <param-name>productionMode</param-name>
        <param-value>false</param-value>
    </context-param>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/applicationContext.xml
            /WEB-INF/applicationContext-security.xml
            /WEB-INF/applicationContext-cache.xml    
        </param-value>
    </context-param>
    <filter>
        <filter-name>deviceResolverRequestFilter</filter-name>
        <filter-class>org.springframework.mobile.device.DeviceResolverRequestFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>deviceResolverRequestFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
     <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
     <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>Test Application</servlet-name>
        <init-param>
            <param-name>widgetset</param-name>
            <param-value>com.mydomain.AppWidgetSet</param-value>
        </init-param>
    </servlet>
    <servlet>
        <servlet-name>mobile</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>mobile</servlet-name>
        <url-pattern>/mobile/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

Button that opens new browser window

Button myButton = new Button("push me"); myButton.addMyClickListener(this); myButton.setData(Buttons.OPEN); BrowserWindowOpener opener = new BrowserWindowOpener(MyUI.class); opener.extend(myButton); hl.addComponent(myButton); In the console log I can’t see any error.
Spring release is 4.1.7
Spring security release is 4.0.1
Vaadin release is 7.5.2
Can anyone help me?
Thank you, Francesco

Hi Francesco,

each request gets to the instance of VaadinServlet.class and is processed in its method
service(HttpServletRequest request, HttpServletResponse response)
. In this method there is check whether the request is for static resource
request.getRequestURI().startsWith(request.getContextPath() + “/VAADIN/”)
and in the end of the method is called
getService().handleRequest(vaadinRequest, vaadinResponse)
method from VaadinService.class.

The method
handleRequest(vaadinRequest, vaadinResponse)
loops over request handlers and on each hander calls handleRequest(vaadinSession, request, response) method. This method is



called when a request needs to be handled. If a response is written, this method should return true to indicate that no more request handlers should be invoked for the request. (method comment)

If there is not found any handler that could handle the request the response is set to “Request was not handled by any registered handler.”

// Request not handled by any RequestHandler
response.sendError(HttpServletResponse.SC_NOT_FOUND, "Request was not handled by any registered handler.");

In my project I had problem when the url was other than default project url. The url
http://localhost:8080/my_project/
was ok but
http://localhost:8080/my_project/something
returned “HTTP Status 404 - Request was not handled by any registered handler.” response.

I have checked all my request handlers

com.vaadin.server.communication.PushRequestHandler,
com.vaadin.server.communication.ServletUIInitHandler
com.vaadin.server.ConnectorResourceHandler
com.vaadin.server.UnsupportedBrowserHandler
com.vaadin.server.communication.UidlRequestHandler
com.vaadin.server.communication.FileUploadHandler
com.vaadin.server.communication.HeartbeatHandler
com.vaadin.server.communication.PublishedFileHandler
com.vaadin.server.communication.SessionRequestHandler
com.vaadin.server.communication.ServletBootstrapHandler

and found out that problem was in the last one - ServletBootstrapHandler.

When
handleRequest(vaadinSession, request, response)
is called on ServletBootstrapHandler the flow gets through the SynchronizedRequestHandler’s method
handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
to BootstrapHandler’s method
synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response)
. In this method there is loop through list of UIProviders. In my former Spring project the UIProvider was instance of DefaultUIProvider.class. In my current project it is instance of SpringUIProvider.class. SpringUIProvider.class implementation of
getUIClass(UIClassSelectionEvent uiClassSelectionEvent)
method differs from the DefaultUIProvider.class. To work properly I had to add path value to @SpringUI annotation. In your case it would be

@Component
@Theme("mytheme")
@SpringUI(path = "/*")
public class MyUI extends UI

I am not sure if this solves your problem but I hope it at least points you out to the right direction.
Vit

Thank you Vit, your indication let me solve my problem. I noticed the url of the new opened window in my case was

http://mydomain/app/popup/MyUI so I added /app/popup/MyUI/* to urlPatterns:

@WebServlet(urlPatterns = {"/app/*","/app/popup/MyUI/*", "/VAADIN/*"}, asyncSupported = true) public static class Servlet extends SpringVaadinServlet { private static final long serialVersionUID = 1L; } and this solved the problem.

Thank you, Francesco