exception handling - ExceptionHandler returning JSON or XML not working in spring mvc 3 -
code this:
@controller public class testcontroller { @requestmapping(value = "/testerror", method = requestmethod.get) public @responsebody errorto testerror(httpservletrequest request,httpservletresponse response) { throw new abcexception("serious error!"); } @exceptionhandler(abcexception.class) public @responsebody errorto handleexception(abcexception ex, httpservletrequest request, httpservletresponse response) { response.setstatus(response.sc_bad_request); return new errorto(ex.getmessage()); } @requestmapping(value = "/test", method = requestmethod.get) public @responsebody errorto test(httpservletrequest request, httpservletresponse response) { errorto error = new errorto(); error.setcode(-12345); error.setmessage("this test error."); return error; } }
when tried curl -h "accept:application/json" -v "http://localhost.com:8080/testerror" got error: org.springframework.web.servlet.mvc.annotation.annotationmethodhandlerexceptionresolver - not find httpmessageconverter supports return type [class com.kibboko.poprocks.appservices.dtos.errorto] , [application/json]
but if try curl -h "accept:application/json" -v "http://localhost.com:8080/test", worked , returned json response. "application/xml" worked too.
is there special exception handler need take care of can work json or xml? thanks!
seems known spring bug (fixed in 3.1 m1)
Comments
Post a Comment