Spring 3.1.RC1 and PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE

Posted in spring forum with no response.

I have the following code snippet (from here), which is part of my pet project.

@Controller
@RequestMapping("/browse")
public class MediaBrowser {
   ...

    @RequestMapping("/**")
    public final ModelAndView listContents(final HttpServletRequest request) {

        String folder = (String) request.getAttribute(
                HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);
                ...
    }

I access the following url:

http://localhost:8080/myapp/browse

  • In spring 3.0.6.RELEASE, I got the folder variable as null, which is the expected value.
  • In spring 3.1.RC1, the folder variable is /browse.

Is this a bug or has something changed in spring-3.1?

Answers


As skaffman said, you probably shouldn't use PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE. Take a look at How to match a Spring @RequestMapping having a @pathVariable containing "/"? for an example of using AntPathMatcher to accomplish what you are trying


This looks very much like an internal implementation detail of the framework, one that you should not be relying on.

The javadoc for PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE says:

Note: This attribute is not required to be supported by all HandlerMapping implementations. URL-based HandlerMappings will typically support it, but handlers should not necessarily expect this request attribute to be present in all scenarios.

I wouldn't be surprised if the behaviour changed slightly between 3.0 and 3.1.


Need Your Help

Rails 2.3.5 threadsafe! breaks my migrations

ruby-on-rails migration thread-safety

I'm using jruby-1.5.3 with a rails 2.3.5 app. I've just started playing around with thread safety using:

App not finding resources after locale change in Android

android crash resources locale

I am working on a project which requires on the fly language changes. I am attempting to set the desired Locale but as soon as I do, the app crashes complaining that it cannot find Resources (thing...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.