Vaadin steals all Url Patterns

I am trying to provide some REST Urls provided by spring MVC beside my Vaadin app - my web.xml is below. I only get 404s at /info - it seems like Vaadin steals all the url patterns.

If I remove Vaadin, I can reach /info and get content at that url. How to I get them to play nicely together?

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml
    </param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
    <description>Vaadin production mode</description>
    <param-name>productionMode</param-name>
    <param-value>false</param-value>
</context-param>

<servlet>

    <servlet-name>Vaadin Application Servlet</servlet-name>
    <servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
    <!-- replace standard applicationServlet with the ICEpush one -->
    <!--<servlet-class>org.vaadin.artur.icepush.ICEPushServlet</servlet-class>-->
    <init-param>
        <description>Vaadin application class to start</description>
        <param-name>application</param-name>
        <param-value>myapp.vaadin.MyVaadinApp</param-value>
    </init-param>
    <init-param>
        <param-name>widgetset</param-name>
        <param-value>myapp.gwt.MyAppWidgetSet</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>


<servlet-mapping>
    <servlet-name>Vaadin Application Servlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>Vaadin Application Servlet</servlet-name>
    <url-pattern>/VAADIN/*</url-pattern>
</servlet-mapping>



<servlet>
    <servlet-name>resturls</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/applicationContext.xml
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>resturls</servlet-name>
    <url-pattern>/info</url-pattern>
</servlet-mapping>

Does “[tt]
/info/*
[/tt]” work?

Mapping sub-paths this way to different servlets should work this way, according to JSR specs.

Mapping /* to the Vaadin app is OK
unless
you want to serve any files statically, such as an index.html (also if they are in a sub-directory), in which case you need to use /myapp/* for the Vaadin servlet (and /VAADIN/* for the Vaadin resources). If you want to leave this possibility open, you may want to do this in the first place, for the sake of preserving the app URL.

Note that if you map /* to the Vaadin app, you won’t need the /VAADIN/* mapping.

Yes Marko /info/* did work - thank you!

Howdy,

In case it’s not obvious how this works, a url pattern like “/info/a” does
not
match “/info” but it does match “/" since the wildcard would match with anything (in this case * == “info/a”). Given two patterns like "/” and “/info/*”, the rule is that the longest match wins, so the second one wins.

I’m currently using Vaadin as the UI front end on a service that provides REST URLs for various things. In my case I wanted to put the web app at /ui and have everything else be for the REST services. But, if a user comes to the main page, I want him/her to be shown the UI. This worked fine for me, and I’m sharing it in case anyone is curious about how the mapping works. A similar pattern, for instance, could be used to map /* to Vaadin but /login.jsp to a JSP if you’re using form-based authentication.

In my case, I’m using Java EE 6 so I have the Vaadin mappings in a servlet class like this. The mappings could just as easily be in web.xml:

    @WebServlet(urlPatterns = {"/ui/*", "/VAADIN/*"})
    public static class MyServlet extends AbstractApplicationServlet {
        // ...
    }

Then web.xml contains:

    <servlet>
        <!-- technically, a JSP is a servlet -->
        <servlet-name>index</servlet-name>
        <jsp-file>index.jsp</jsp-file>
    </servlet>
    <servlet>
        <!-- this is the Jersey REST servlet -->
        <servlet-name>ServletAdaptor</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- We'll map / to the welcome page and /* to our resources. -->
    <servlet-mapping>
        <servlet-name>index</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>ServletAdaptor</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

So I have it set up that /* will match to any REST resource I add, as long as it’s not /ui/*. When a user first comes to the site, s/he is directed to index.jsp, which is simply:

<%
    response.sendRedirect("ui");
%>

That’s probably a lot more than you want to know, but maybe it will help someone. If the UI is a minor part of the web application, then I like having it sit at a specific URL rather than using /* for it.

Cheers,
Bobby