Exception handler customization
It is possible to customize the exception handling screen per realm. The default exception handler is installed as a global resource configuration within Yanel. In order to create and install a custom exception handler, the following steps need to be taken.
Overview
- Create your new exception handler: Create a new resource type that inherits from org.wyona.yanel.impl.resources.BasicGenericExceptionHandlerResource. The basic exception handler is an extension of the BasicXMLResource class, so simply override the getContentXML(String viewId) function in order to output your custom error message. You have access to the exception that was thrown through the variable e. The source code can be found at YANEL/src/impl/java/org/wyona/yanel/impl/resources/BasicGenericExceptionHandlerResource.java.
- Overwrite the global resource configuration for the exception handler within your realm by creating the file REALM/src/webapp/global-resource-configs/generic-exception-handler_yanel-rc.xml within your realm.
After that, your own exception handler should be called whenever an exception is thrown.
In more detail
Example custom exception handler
package org.wyona.yanel.resources.konakart.shared; import org.wyona.yanel.core.attributes.viewable.View; import org.wyona.yanel.impl.resources.BasicGenericExceptionHandlerResource; import javax.servlet.http.HttpServletResponse; public class KonakartExceptionHandler extends BasicGenericExceptionHandlerResource { /** * Get view. */ @Override public View getView(String viewId) throws Exception { View view = new View(); view.setResponse(false); HttpServletResponse response = getEnvironment().getResponse(); response.sendError(503, "The shop is currently unavailable."); return view; } }
Example exception handler resource configuration
<?xml version="1.0"?> <yanel:resource-config xmlns:yanel="http://www.wyona.org/yanel/rti/1.0"> <yanel:rti name="konakart-exception-handler" namespace="http://www.wyona.com/yanel/resource/konakart/1.0"/> <yanel:custom-config> <views xmlns="http://www.wyona.org/yanel/rti/1.0"> <view id="default"> <mime-type>application/xhtml+xml</mime-type> </view> <view id="xml"> <mime-type>application/xml</mime-type> </view> </views> </yanel:custom-config> </yanel:resource-config>
Your comments are much appreciated
Is the content of this page unclear or you think it could be improved? Please add a comment and we will try to improve it accordingly.