Spring Framework
  1. Spring Framework
  2. SPR-8410 Content negotiation improvements
  3. SPR-7632

Allow valid file extension paths for content negotiation to be specified

    Details

    • Type: Sub-task Sub-task
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Complete
    • Affects Version/s: 3.0.6
    • Fix Version/s: 3.2 M2
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      false

      Description

      Allow valid file extension paths to be specified in DispatcherServlet. My use case is

      @RequestMapping(value = "/jobs/{jobName}", method = RequestMethod.GET)
      

      I need .html and .json to be valid extensions (stripped off by the dispatcher), but other . separated jobName values are legal and should be presented as they are (e.g. my.job or my.job.html both resolve to my.job).

      The current behaviour is simply to truncate at the first period. Even with a regex pattern {{

      {jobName:.*}

      }} we truncate the path, so the only way to make it work is to add HttpServletRequest to all controller methods and extract the parameter manually (back to Spring 2.5).

        Issue Links

          Activity

          Hide
          Dave Syer added a comment -

          An neat solution would be to allow the controller to access the removed portion of the path, e.g. with

          @RequestMapping(value = "/jobs/{jobName}", method = RequestMethod.GET)
          public String doSomething(@PathVariable String jobName, @PathExtension String ext) {
             ...
          }
          
          Show
          Dave Syer added a comment - An neat solution would be to allow the controller to access the removed portion of the path, e.g. with @RequestMapping(value = "/jobs/{jobName}" , method = RequestMethod.GET) public String doSomething(@PathVariable String jobName, @PathExtension String ext) { ... }
          Hide
          Rossen Stoyanchev added a comment -

          Currently, you can turn suffix pattern matching on and off wholesale only through the HandlerMapping useSuffixPatternMatch property. When off the extension can be extracted like this:

          @RequestMapping(value = "/jobs/{jobName}.{ext:job}", method = RequestMethod.GET)
          public String doSomething(@PathVariable String jobName, @PathVariable String ext) {
             // ...
          }
          

          We may be able to do something about smarter suffix pattern matching with the content negotiation improvements planned for 3.2 (see SPR-8474 and its umbrella ticket SPR-8410). In which case you'd be able to do the above without turning off suffix pattern matching wholesale.

          Show
          Rossen Stoyanchev added a comment - Currently, you can turn suffix pattern matching on and off wholesale only through the HandlerMapping useSuffixPatternMatch property. When off the extension can be extracted like this: @RequestMapping(value = "/jobs/{jobName}.{ext:job}" , method = RequestMethod.GET) public String doSomething(@PathVariable String jobName, @PathVariable String ext) { // ... } We may be able to do something about smarter suffix pattern matching with the content negotiation improvements planned for 3.2 (see SPR-8474 and its umbrella ticket SPR-8410 ). In which case you'd be able to do the above without turning off suffix pattern matching wholesale.
          Hide
          Rossen Stoyanchev added a comment -

          Modified title (was: "Allow valid file extension paths to be specified in DispatcherServlet")

          Show
          Rossen Stoyanchev added a comment - Modified title (was: "Allow valid file extension paths to be specified in DispatcherServlet")
          Hide
          Rossen Stoyanchev added a comment - - edited

          This is now resolved. As long as you have configured valid file extensions through the newly added ContentNegotiationManager, those extensions will be the only ones recognized. See the commit comment for more details.

          Show
          Rossen Stoyanchev added a comment - - edited This is now resolved. As long as you have configured valid file extensions through the newly added ContentNegotiationManager, those extensions will be the only ones recognized. See the commit comment for more details.
          Hide
          sandip added a comment -

          I am using version 3.2.4 of spring and still facing same issue , do i need to do some more configurations ?

          Show
          sandip added a comment - I am using version 3.2.4 of spring and still facing same issue , do i need to do some more configurations ?
          Hide
          Rossen Stoyanchev added a comment -

          Besides configuring content negotiation itself, you also need to enable it (see this property).

          Show
          Rossen Stoyanchev added a comment - Besides configuring content negotiation itself, you also need to enable it (see this property ).

            People

            • Assignee:
              Rossen Stoyanchev
              Reporter:
              Dave Syer
              Last updater:
              Rossen Stoyanchev
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                29 weeks, 1 day ago

                Time Tracking

                Estimated:
                Original Estimate - 0.25d
                0.25d
                Remaining:
                Remaining Estimate - 0.25d
                0.25d
                Logged:
                Time Spent - Not Specified
                Not Specified