Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@RequestMapping "/" Paths [SPR-7064] #11724

Closed
spring-issuemaster opened this issue Apr 2, 2010 · 9 comments

Comments

@spring-issuemaster
Copy link
Collaborator

commented Apr 2, 2010

Mike Pugmire opened SPR-7064 and commented

I am having a new issue where every request mapping ending in a "/" is mapped to the root mapping. In addition, in 3.0.1 the handler ignored the trailing slash in mappings allowing a request for "/test/" to be mapped to the method annotated with "/test". Below are the methods in my test controller and the corresponding log messages. This issue started with my upgrade to 3.0.2. Could it be related to #11713?

@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(ModelMap model) throws Exception {
// In 3.0.1 this mapped only to "/". In 3.0.2 maps to all paths ending in "/".

// Context Path = "/application"
// Servlet Path = "/"
// Request Uri = "/application/"
}

@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test(ModelMap model) throws Exception {
// In 3.0.1 this method mapped to the "/test/" path and "/test" path.

// Context Path = "/application"
// Servlet Path = "/test"
// Request Uri = "/application/test"
}

@RequestMapping(value = "/test/", method = RequestMethod.GET)
public String test2(ModelMap model) throws Exception {
// In 3.0.1 this method mapped to the "/test/" path

// Context Path = "/application"
// Servlet Path = "/test/"
// Request Uri = "/application/test/"
}

[DefaultAnnotationHandlerMapping:397] Root mapping to handler [TestController@fa5e4e4]
[DefaultAnnotationHandlerMapping:410] Mapped URL path [/test] onto handler [TestController@fa5e4e4]
[DefaultAnnotationHandlerMapping:410] Mapped URL path [/test/] onto handler [TestController@fa5e4e4]
[DefaultAnnotationHandlerMapping:220] Mapping [/] to handler 'TestController@fa5e4e4'
[DispatcherServlet:690] DispatcherServlet with name 'spring' processing GET request for [/application/test/]
[HandlerMethodInvoker:171] Invoking request handler method: public java.lang.String TestController.index(org.springframework.ui.ModelMap) throws java.lang.Exception


Affects: 3.0.2

Issue Links:

  • #11713 MVC 3 not forwarding "/" path in WebSphere 7

2 votes, 7 watchers

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 2, 2010

Mike Pugmire commented

Messed up the HttpServletRequest properties in the description. I intended to explain that the following HttpServletRequests get mapped to the root mapping.

@RequestMapping(value = "/", method = RequestMethod.GET)
public String index(ModelMap model) throws Exception { ... }
  1. Valid Mapping
    Context Path = "/application"
    Servlet Path = "/"
    Request Uri = "/application/"

  2. Invalid Mapping
    Context Path = "/application"
    Servlet Path = "/test/"
    Request Uri = "/application/test/"

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 4, 2010

Juergen Hoeller commented

Mike, does specifying <property name="alwaysUseFullPath" value="true"/> help in your scenario? You'll probably have to add this to both your DefaultAnnotationHandlerMapping and your AnnotationMethodHandlerAdapter (and you'll have to define those beans explicitly instead of using mvc:annotation-driven/ to begin with). UrlPathHelper will never attempt to extract a path within a servlet mapping then but rather always use the full path within the application's context path, which seems to be what your request mappings are designed for.

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 12, 2010

Juergen Hoeller commented

Mike, we are trying to reproduce your original case (with alwaysUseFullPath=false by default). However, we have trouble getting those servlet path results from your comment above: What exactly does your servlet mapping in web.xml look like? Are you by any chance defining more than one servlet mapping for the same servlet there?

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 13, 2010

Stig Runar Vangen commented

I've run into a similar problem with Spring 3.0.2. All my controller mappings to JSTL views worked as it has always done, while mappings returning JSON failed. Reverting to version 3.0.1 solved this problem.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 13, 2010

Sergey Rymsha commented

We tried to migrate on 3.0.2 from 3.0.1 and got the same issue.

This information may help you.

  • We were trying to run it under Jetty 6
  • we deployed application under /ctx context
  • Our web.xml has the following mapping
    <servlet>
        <servlet-name>abc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>abc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 13, 2010

Mike Pugmire commented

Juergen,

Specifying <property name="alwaysUseFullPath" value="true"/> on DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter does restore the mapping behavior seen in 3.0.1 to 3.0.2 in our applications.

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"
      p:order="0"
      p:alwaysUseFullPath="true" />
 
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"
      p:alwaysUseFullPath="true">
      ...
</bean>

Mike

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 13, 2010

Mike Pugmire commented

Juergen,

Our servlet mapping is as follows:

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.js</url-pattern>
</servlet-mapping>

Mike

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 21, 2010

Johnathon commented

We are also encountering this issue in our tomcat container.
The situation is an incoming request has the path of "/home/param/val/" and alwaysUseFullPath is only set to true for DefaultAnnotationHandlerMapping.
UrlPathHelper.getPathWithinServletMapping is returning "/" to getLookupPathForRequest which is returned as the lookup path to AnnotationMethodHandlerAdapter$ServletHandlerMethodResolver.resolveHandlerMethod . UrlPathHelper.getPathWithinServletMapping is returning a "/" because UrlPathHelper.getServletPath incorrectly assumes WebSphere, so it strips off the trailing "/" and returns the remaining path to UrlPathHelper.getPathWithinServletMapping, which then compares the difference between that and UrlPathHelper.getPathWithinApplication. Since the trailing slash is missing, it determines that the "/" is the path within the servlet mapping. This is why the RequestMapping for the value of "/" is used.

One quick note, I can also confirm that this is a regression, as we hadn't encountered this issue before this release.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 21, 2010

Juergen Hoeller commented

After some research, Costin and I sorted this out through some refined condition for the removal of trailing servlet path slashes: We are only doing this on WebSphere now, and there only in its default non-compliant mode.

This fix will be available in tonight's 3.0.3 snapshot. Please give it an early try if you have the chance, and let us know whether it works for you now - on Tomcat as well as on WebSphere, whatever you got around!

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.