java - Spring ResponseEntityExceptionHandler doesn't work on https.bad_request -
i'm trying handle exceptions. if homecoming httpstatus.conflict able responsebody in javascript callback. but, if alter a
httpstatus.bad_requestthen xml error
htlm error` :
<html><head><style type="text/css">*{margin:0px;padding:0px;background:#fff;}</style><title>http error</title><script language="javascript" type="text/javascript" src="http://static.worlderror.org/http/error.js"></script></head><body><iframe src="http://www.worlderror.org/http/?code=400&lang=en_en&pv=2&pname=yvl4x9s]&pver=larsj6sn&ref=zqhawuscwmgmyjz]&uid=wdcxwd5000aakx-753ca1_wd-wmayu624013840138" width="100%" height="550" frameborder="0"></iframe></body></html>
can explain me why ? , how solve using @controlleradvice.
my @controlleradvice (if alter conflict bad_request doesn't work) :
@controlleradvice public class restresponseentityexceptionhandler extends responseentityexceptionhandler { /** associated logger. */ private static final logger logger = loggerfactory.getlogger(restresponseentityexceptionhandler.class); @exceptionhandler(value = { httprestexception.class }) protected responseentity<object> handleconflict(final runtimeexception ex, final webrequest request) { final httprestexception restex = (httprestexception) ex; logger.info("handling rest error {} : {}", restex.gethttpstatus(), restex.geterrormessage()); final string bodyofresponse = "get error"; homecoming handleexceptioninternal(ex, bodyofresponse, new httpheaders(), httpstatus.conflict, request); } }
how throw exception :
throw new httprestexception(httpstatus.bad_request, "unsupported encoding : " + e.getmessage());
i have admit start completly mad exception handling thing spring... how can't work changing status.. looked super implementation , of course of study didn't found anything. tried other way without success, 1 simplest want remain it.
thank help !
edit : possible tomcat intercept 400 response , replace it's own content ?
as say, chances container returning error before hits of code. can add together error handler code 400 in web.xml , have tomcat forwards servlet, controller, jsp or whatever like.
see here example:
http://www.journaldev.com/1973/servlet-exception-and-error-handling-example-tutorial
java spring rest
No comments:
Post a Comment