Search code examples
spring-mvcservletstapestry

How to map DispatcherServlet on /foo/* while Tapestry is mapped on /*


I'm trying to make Tapestry and a DispatcherServlet coexist within my app but it's driving me nuts. I know I have to define the Servlet in the web.xml, assign it an URL and since Tapestry is assigned to /* I have to exclude the Servlet URL in the Tapestry AppModule.

public static void contributeIgnoredPathsFilter(
        final Configuration<String> configuration) {
    configuration.add("/bots/.*");
}

Then, in web.xml I have my servlet defined

<!-- Restlet adapter -->
<servlet>
    <servlet-name>BotService</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>BotService</servlet-name>
    <url-pattern>/bots/*</url-pattern>
</servlet-mapping>

And if it matters, the relevant config in applicationContext.xml for this has been set like this

<mvc:annotation-driven/>
<context:component-scan base-package="com.viktortech.automaton.rest" />

Of course schemas are OK, since jetty and the Dispatcher Servlet are starting up flawlessly. The issue is that no matters how I define the @RequestMapping annotation value, I get nothing but 404's trying to reach my controller classes (Which are all defined under the com.viktortech.automaton.rest package.

@Controller
public class WelcomeController {

     @ResponseBody
     @RequestMapping(value = "/bots/", method = RequestMethod.GET, headers = "Accept=*")
     public String plaintext(HttpServletResponse response) {
        response.setContentType("text/plain");
        response.setCharacterEncoding("UTF-8");
        return "HELLO";
    }

}

What am I doing wrong here? Thanks in advance


Solution

  • URL pattern in the servlet mapping provides part of the urls, so relatively, the URLs in the Controllers don't have to include the part of the URL specified in the maping.

    Only changing the Controller piece of code it would work like this, when accesing /bots/

    @RequestMapping(value = "/", method = RequestMethod.GET, headers = "Accept=*")
    

    As chrylis remarked, with the old piece of code, the url would be /bots/bots/