spring - How to checkin interceptor whether a controller triggered a redirect -


in spring mvc project added interceptor class, check, whether redirect has been triggered.

here controller-class:

@controller public class redirecttestercontroller {      @requestmapping (value="/page1")     public string showpage1(){          return "page1";     }      @requestmapping (value="/submit1")     public string submitpage1(){          return "redirect:/page2";     }      @requestmapping (value="/page2")     public string showpage2(){          return "page2";     }  } 

so if call e.g.

localhost:8080/mycontext/submit1

the method "submitpage1" executed.

now - server tells client, call

localhost:8080/mycontext/page2

which working.

so - want step process, after method "submitpage1"has been executed. in mind there should order/command in httpresponse, ask.

to check that, made breakpoint in interceptor class in method: "posthandle" - bit since then, have no idea how continue. tried read outputstream - doing crashes application. (leads exception --> outputstream has been called..).

isn't there easy solution ?

following example shows how test if view redirect:

@configuration public class mvcconfig extends webmvcconfigureradapter {      @override     public void addinterceptors(interceptorregistry registry) {         registry.addinterceptor(new handlerinterceptoradapter() {             @override             public void posthandle(httpservletrequest request, httpservletresponse response, object handler,                                    modelandview modelandview) throws exception {                 if (modelandview != null && stringutils.startswithignorecase(modelandview.getviewname(), "redirect:")) {                     // handle redirect...                 }             }         });     } } 

see: handlerinterceptoradapter, stringutils

spring mvc documentation: intercepting requests handlerinterceptor


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -