Borgy Manotoy
Borgy Manotoy

Reputation: 2038

Spring + Wicket REST Exception Handlers

I do not know how to start the question but let me give you some info of the application setup.

The project is spring + wicket and everything is OK. There are error pages (400, 401, 403... etc) setup that will be displayed when there are errors.

Now, there is a need to add some APIs using apache wicket and everything works now. Problem is, when I get an exception/error, the error page is displayed.

I wanted to create a specific exception and handler for the APIs and do not redirect to the error page.

In my other project which are mainly rest, I use like controller advice (Global exception handler) for handling errors.

Now, errors are redirected to specific error page (configured in web.xml). Changing the existing web.xml is not possible.

Is it possible not to touch the current web.xml... but I can create new exceptions and exception handlers for the API?

Please note that the APIs are created using wicketstuff rest (apache wicket).

TIA

Upvotes: 0

Views: 251

Answers (1)

martin-g
martin-g

Reputation: 17513

You can use a custom IRequestCycleListener that implements #onException(). If you want to handle the passed exception then return non-null IRequestHandler, otherwise return null and let the default handler to deal with it, i.e. the configured pages in web.xml.

To setup the listener do:

application.getRequestCycleListeners().add(new MyRequestCycleListener());

Upvotes: 0

Related Questions