Ho trovato uno strano comportamento di Spring MVC.Spring MVC return HTTP 406 su URL con punto
ho controller con metodo:
@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);
}
Quindi, problema è quando id contiene dot (ex "my_file.wav".) Molla riporta HTTP 406, in ogni caso, ma se id non contiene dot , Spring restituisce responseState (come json) mentre espeto. Ho provato a risolverlo in un modo diverso (aggiungi @ResponseBody, cambia la versione di jackson, esegui il downgrade di Spring a 4.0) ma senza alcun risultato.
Qualcuno può aiutarmi?
UPDATE abilito i registri per la primavera MVN e ho visto questo
ID contiene dot:
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 non contiene dot:
DEBUG org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdviceChain - Invoking ResponseBodyAdvice chain for [email protected]
DEBUG org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdviceChain - After ResponseBodyAdvice chain [email protected]
SOLUZIONE
Spring does not ignore file extension
SpringMVC: Inconsistent mapping behavior depending on url extension
La tua risposta è corretto, ma non mi aiuta. Spring ha ancora inviato HTTP 406. – Vartlok
ora prova a cambiare il requestmapping per essere semplicemente '@RequestMapping (value ="/delete/{id} ", method = RequestMethod.DELETE)' –
E ancora HTTP 406 – Vartlok