Hi, I'm afraid this won't work. You'll need to wrap it in RuntimeException and unwrap it in your other filter.
On Thu, May 30, 2013 at 5:18 PM, Eusie <ygou....@gmail.com> wrote: > Hi Martin, > > Thanks for your reply. However, the case here is not about runtime > exceptions, instead I'd like to throw checked exceptions. > > The problem I could see is within WicketFilter, where you'll find this > line: > > if (!requestCycle.**processRequestAndDetach()) > > which processes requests. The reason why checked exceptions are not able > to be thrown is of the signature of processRequestAndDetach: > > public boolean processRequestAndDetach() { > } > > Where no exceptions can be thrown. > > Also regarding IExceptionMapper, it cannot throw any exception because of > the signature of its map() interface, see below: > > public class CustomExceptionMapperProvider implements > IProvider<IExceptionMapper> > { > @Override > public IExceptionMapper get() > { > return new IExceptionMapper(){ > > // Exception e cannot be re-thrown here because of the > signature of the interface below > @Override > public IRequestHandler map(Exception e) { > System.out.println("**CustomExceptionMapperProvider > caught: " + e.getMessage()); > // this is not allowed here: throw e; > return null; > }}; > } > } > > My question is, how would Wicket allow checked exceptions to be thrown? > > (By the way, I'm testing using Wicket version 6.3.) > > Many thanks, > Yuci > > > On 29/05/2013 13:41, Martin Grigorov wrote: > >> Hi, >> >> Wicket catches all runtime exceptions and gives them to all configured >> IRequestCycleListeners (#onException()). If none of them knows how to >> process the exception then the exception is given to IExceptionMapper (see >> Application#**newExceptionMapper). The default impl of this mapper is to >> show >> the configured IApplicationSettings#**getInternalErrorPage(). >> >> As a final resort you can provide your own IExceptionMapper that re-throws >> OAuth2AccessTokenRequiredExcep****tion. >> >> >> >> >> On Wed, May 29, 2013 at 2:41 PM, Eusie <ygou....@gmail.com> wrote: >> >> Hi, >>> >>> I am using Spring OAuth2ClientContextFilter to handle the OAuth Dance. In >>> the thread calling stack, OAuth2ClientContextFilter is in the upstream of >>> WicketFilter (See below the Error Message). >>> >>> When an access token is needed, I'd like to throw an >>> OAuth2AccessTokenRequiredExcep****tion exception in Wicket so as to ask >>> the >>> >>> upstream OAuth2ClientContextFilter to handle the exception to redirect >>> the >>> user to be authenticated. >>> >>> But the problem is Wicket Page seems not able to throw an exception as >>> below: >>> >>> public HomePage(final PageParameters parameters) throws Exception { >>> } >>> >>> ################### Error Message ################### >>> >>> Last cause: OAuth2 access denied. >>> WicketMessage: Can't instantiate page using constructor 'public >>> com.mycompany.HomePage(org.****apache.wicket.request.mapper.*** >>> *parameter.PageParameters) >>> >>> throws java.lang.Exception' and argument ''. Might be it doesn't exist, >>> may >>> be it is not visible (public). >>> >>> Stacktrace >>> >>> Root cause: >>> >>> org.springframework.security.****oauth2.client.** >>> OAuth2AccessTokenRequiredExcep****tion: OAuth2 access denied. >>> at com.mycompany.HomePage.<init>(****HomePage.java:22) >>> at java.lang.reflect.Constructor.****newInstance(Constructor.** >>> java:** >>> 513) >>> at org.apache.wicket.session.****DefaultPageFactory.newPage(** >>> DefaultPageFactory.java:170) >>> at org.apache.wicket.session.****DefaultPageFactory.newPage(** >>> DefaultPageFactory.java:75) >>> at org.apache.wicket.****DefaultMapperContext.**** >>> newPageInstance(** >>> DefaultMapperContext.java:133) >>> at org.apache.wicket.core.****request.handler.PageProvider.**** >>> resolvePageInstance(****PageProvider.java:278) >>> at org.apache.wicket.core.****request.handler.PageProvider.**** >>> getPageInstance(PageProvider.****java:166) >>> at org.apache.wicket.request.****handler.render.PageRenderer.** >>> getPage(PageRenderer.java:78) >>> at org.apache.wicket.request.****handler.render.** >>> WebPageRenderer.renderPage(****WebPageRenderer.java:94) >>> at org.apache.wicket.request.****handler.render.** >>> WebPageRenderer.respond(****WebPageRenderer.java:244) >>> at org.apache.wicket.core.****request.handler.** >>> RenderPageRequestHandler.****respond(****RenderPageRequestHandler.java:* >>> ***165) >>> at org.apache.wicket.request.****cycle.RequestCycle$** >>> HandlerExecutor.respond(****RequestCycle.java:830) >>> at org.apache.wicket.request.****RequestHandlerStack.execute(** >>> RequestHandlerStack.java:64) >>> at org.apache.wicket.request.****cycle.RequestCycle.execute(** >>> RequestCycle.java:253) >>> at org.apache.wicket.request.****cycle.RequestCycle.** >>> processRequest(RequestCycle.****java:210) >>> at org.apache.wicket.request.****cycle.RequestCycle.** >>> processRequestAndDetach(****RequestCycle.java:281) >>> at org.apache.wicket.protocol.****http.WicketFilter.** >>> processRequest(WicketFilter.****java:188) >>> at org.apache.wicket.protocol.****http.WicketFilter.doFilter(** >>> WicketFilter.java:245) >>> at org.apache.catalina.core.****ApplicationFilterChain.** >>> internalDoFilter(****ApplicationFilterChain.java:****235) >>> at org.apache.catalina.core.****ApplicationFilterChain.**** >>> doFilter(** >>> ApplicationFilterChain.java:****206) >>> at org.springframework.security.****web.FilterChainProxy$** >>> VirtualFilterChain.doFilter(****FilterChainProxy.java:312) >>> at org.springframework.security.****web.access.intercept.** >>> FilterSecurityInterceptor.****invoke(****FilterSecurityInterceptor.**** >>> java:116) >>> at org.springframework.security.****web.access.intercept.** >>> FilterSecurityInterceptor.****doFilter(****FilterSecurityInterceptor.** >>> java:83) >>> at org.springframework.security.****web.FilterChainProxy$** >>> VirtualFilterChain.doFilter(****FilterChainProxy.java:324) >>> at org.springframework.security.****oauth2.client.filter.** >>> OAuth2ClientContextFilter.****doFilter(****OAuth2ClientContextFilter.** >>> java:94) >>> >>> ##############################****####################### >>> >>> >>> While in Spring MVC, an exception can be thrown like this: >>> >>> @RequestMapping("/orcid/info") >>> public String orcidInfo(Model model, HttpSession session) throws >>> Exception { >>> } >>> >>> My question is: how can I throw an exception in Wicket, which will be >>> handled by another upstream filter, say OAuth2ClientContextFilter in this >>> case. >>> >>> Many thanks, >>> Yuci >>> >>> > > ------------------------------**------------------------------**--------- > To unsubscribe, e-mail: > users-unsubscribe@wicket.**apache.org<users-unsubscr...@wicket.apache.org> > For additional commands, e-mail: users-h...@wicket.apache.org > >