Spring MVC の非常に奇妙な動作を 1 つ発見しました。
私はメソッドを持つコントローラを持っています:
@RequestMapping (value = "/delete/{id:.*}", method = RequestMethod.DELETE)
public ResponseEntity<Response> delete(@PathVariable (value = "id") final String id) {
HttpStatus httpStatus = HttpStatus.OK;
final Response responseState = new Response( ResponseConstants.STATUS_SUCCESS );
try {
POJO pojo = mediaFileDao.findById( id );
if (pojo != null) {
delete(pojo);
} else {
httpStatus = HttpStatus.NOT_FOUND;
responseState.setError( "NOT_FOUND" );
}
} catch (Exception e) {
httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
responseState.setError( e.getMessage() );
}
return new ResponseEntity<>( responseState, httpStatus );
}
したがって、問題は、id にドット (例: "my_file.wav") が含まれている場合です。Spring はどのような場合でも HTTP 406 を返しますが、id にドットが含まれていない場合、Spring は responseState (json として) を返します。別の方法で修正しようとしました (@ResponseBody の追加、jackson のバージョンの変更、Spring の 4.0 へのダウングレード) が、結果はありませんでした。
誰でも私を助けることができますか?
更新Spring MVNのログを有効にして、これを見ました
ID にはドットが含まれます:
DEBUG org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver - Resolving exception from handler [public org.springframework.http.ResponseEntity<my.package.response.Response> my.package.Controller.deleteMediaFile(java.lang.String) throws java.lang.Exception]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
DEBUG org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver - Resolving exception from handler [public org.springframework.http.ResponseEntity<my.package.response.Response> my.package.Controller.deleteMediaFile(java.lang.String) throws java.lang.Exception]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
DEBUG org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver - Resolving exception from handler [public org.springframework.http.ResponseEntity<my.package.response.Response> my.package.Controller.deleteMediaFile(java.lang.String) throws java.lang.Exception]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
ID にドットが含まれていません:
DEBUG org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdviceChain - Invoking ResponseBodyAdvice chain for body=my.package.response.Response@1e66a392
DEBUG org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdviceChain - After ResponseBodyAdvice chain body=my.package.response.Response@1e66a392
解決