I am trying to pass the URL in Spring to the MVC controller method in @PathVariable, but I get the 400http response code and the request is rejected before it reaches the controller method.
My request is issued as:
curl 'https://127.0.0.1:8443//myapi/page/http%3A%2F%2Fwww.example.co.uk%2Ffolder%2Fpage_n0/info' -k -w "\nResponse code: %{http_code}\n"
Controller Method and Filter UTF-8:
@Bean
public FilterRegistrationBean filterRegistrationBean()
{
CharacterEncodingFilter filter = new CharacterEncodingFilter();
filter.setEncoding("UTF-8");
filter.setForceEncoding(true);
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(filter);
registrationBean.addUrlPatterns("/*");
return registrationBean;
}
@RequestMapping(value = {"/myapi/page/{url}/info"}, method = RequestMethod.GET)
public ResponseEntity<?> test(HttpServletRequest request, HttpServletResponse response, @PathVariable("url") String webPage)
{
ResponseEntity<?> results = new ResponseEntity<Map<String, Object>>(HttpStatus.OK);
return results;
}
I am using Tomcat 8.5.5, and nothing is contained in the log files (logging was set at DEBUG level), with the exception of the following entry in localhost_access_log.2016-10-04.txt:
127.0.0.1 - - [04/Oct/2016:09:04:24 +0100] "GET //myapi/page/http%/info HTTP/1.1" 400 -
In my test code, the transmitted URL is encoded with URLEncoder.encode(), so it must be correctly encoded.
In the remote debugger, I see that the registration code entered above CharacterEncodingFilteris entered so that the filter is registered.
URIEncoding="UTF-8" server.xml $CATALINA_HOME/conf.
, - , . @PathVariable, , - , , %.
!
Update:
, , Spring, AbstractHandlerMethodMapping UriUtils, URL-, @PathVariable. URL, , URL- URL- @PathVariable. Spring application/x-www.form-urlencoded URL-.
?