我有一个运行在Tomcat 7上的spring mvc应用程序,该应用程序带有通过URIEncoding =“ UTF-8”配置的http和ajp连接器。我的REST控制器片段:
@Controller @RequestMapping("") public class ClientRestApi { private final String API_PREFIX = "/api/1.0/client"; ... @RequestMapping(value = API_PREFIX + "/{clientId}", method = RequestMethod.GET) @ResponseBody public ClientDetails get(@PathVariable String clientId, HttpServletRequest request) { log.info("Client API GET [" + clientId + "] | " + request.getRequestURI()); ... } }
http://www.example.pl/api/1.0/client/abc
http://www.example.pl/%07api/1.0/client/abc
http://www.example.pl/%0bapi/1.0/client/abc
http://www.example.pl/ap%0bi/1.0/client/abc
在应用程序日志中,我可以看到(对于前3个请求):
ClientRestApi - Client API GET [abc] | /api/1.0/client/abc ClientRestApi - Client API GET [abc] | /%07api/1.0/client/abc ClientRestApi - Client API GET [abc] | /%0bapi/1.0/client/abc
我的问题是为什么我的 错误 例子是错误的? 为什么不是http 404?
在应用程序的web.xml文件中,我具有UTF-8编码的CharacterEncodingFilter过滤器。我从未在应用程序中遇到过任何错误编码的问题。
编辑:从扩展日志中,请求http://www.example.pl/%0bapi/1.0/client/abc给出:
DEBUG RequestMappingHandlerMapping - Looking up handler method for path /^Kapi/1.0/client/abc TRACE RequestMappingHandlerMapping - Found 1 matching mapping(s) for [/^Kapi/1.0/client/abc] : [{[/api/1.0/client/{ clientId}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}] DEBUG RequestMappingHandlerMapping - Returning handler method [public ClientDetails ...ClientRestApi.get(java.lang.String,javax.servlet.http.HttpServletRequest)]
AntPathMatcher标记路径,默认情况下修剪所有段(有关String.trim,请参阅Javadoc)。此行为可以控制。因为您可以使用带有setTrimTokens(false)的AntPathMatcher配置RequestMappingHandlerMapping。