Issue 1:
Lukas Hämmerle opened SPR-7919 and commented

I have defined the following request mapping:

@RequestMapping(value = "/services/{serviceKey}/vos", method = RequestMethod.GET)

There is a problem if the value of {serviceKey} contains a "/", for example if {serviceKey}=http://example.com/foo

This makes sense of course since the requestmapping cannot easily know that the / is part of a PathVariable.

However, I would have assumed that if the URL is URL-encoded as "http%3A%2F%2Fexample.com%2Ffoo" this should not be a problem. But apparently this values for some reason cannot mapped properly because it reports:

"org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'dispatcher' processing GET request for [/core/services/http://example.com/foo/vos]"

If the already URL-encoded values is URL-encoded again to "http%253A%252F%252Fexample.com%252Ffoo", the mapping works:

"org.springframework.web.servlet.DispatcherServlet - DispatcherServlet with name 'dispatcher' processing GET request for [/core/services/http%3A%2F%2Fexample.com%2Ffoo/vos]"

So, my question is whether there is a way how to make Spring accept the URL encoded value "http%3A%2F%2Fexample.com%2Ffoo" as PathVariable or whether this is a bug.

I tested this on Tomcat 6 and Jetty 7.

Affects: 3.0.3

Issue Links:

#15727 URLs containing %2F (forward slash) are not mapped correctly to @RequestMapping methods

1 votes, 3 watchers

Issue 2:
Rodion opened SPR-11101 and commented

Controller method:

@RequestMapping(value = "/test_url_decoding/{param1}")
public String[] testUrlDecoding(@PathVariable("param1") String p1)

Call:

/test_url_decoding/a%2Fb

Expecting result: parameter p1 is set to "a/b".

Current result: 404 Not found.

Simular problem:

http://stackoverflow.com/questions/13482020/encoded-slash-2f-with-spring-requestmapping-path-param-gives-http-400

The problem was already discussed in https://jira.springsource.org/browse/SPR-7919

Suggested solution (setting decodeUrl of the HandlerMapping to false) does not work. The UrlPathHelper uses HttpServletRequest.getServletPath() method internally, which decodes the path.

Suggested implementation for non-decoding helper:

public class UrlPathHelperNonDecoding extends UrlPathHelper {

public UrlPathHelperFixed() {
super.setUrlDecode(false);
}

@Override
public void setUrlDecode(boolean urlDecode) {
if (urlDecode) {
throw new IllegalArgumentException("Handler does not support URL decoding.");
}
}

@Override
public String getServletPath(HttpServletRequest request) {
String servletPath = getOriginatingServletPath(request);
return servletPath;
}

@Override
public String getOriginatingServletPath(HttpServletRequest request) {
String servletPath = request.getRequestURI().substring(request.getContextPath().length());
return servletPath;
}
}

context.xml

<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
<property name="order" value="-1"></property>
<property name="urlPathHelper">
<bean class="com.yoochoose.frontend.spring.UrlPathHelperFixed"/>
</property>
</bean>

Affects: 3.2.5

Issue Links:

#12574 Request mapping using @PathVariable doesn't work with URL-encoded values

#20202 [doc] Document urlDecode=false implies alwaysUseFullPath=true

Referenced from: commits 12598f8, d55a173

Backported to: 3.2.8

3 votes, 10 watchers