Sample: Portlet Template, or Editable Portlet (DisplayURL)
Error Handler ActionThe source code for the DisplayURL portlet's /** Copyright (c) 2003 by SAS Institute Inc., Cary, NC 27513. * All Rights Reserved. */ package com.sas.portal.portlets.displayurl; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.sas.apps.portal.PortalException; import com.sas.portal.Logger; import com.sas.portal.portlet.ErrorHandlerInterface; import com.sas.portal.portlet.NavigationUtil; import com.sas.portal.portlet.PortletContext; /** * Error handler for this portlet. It logs the exception and * returns ErrorPage.jsp for the portlet to display. */ public class ErrorHandler implements ErrorHandlerInterface { private final String _loggingContext = this.getClass().getName(); /** * Returns the URL for the portlet controller to call. * This is the name of * the error page JSP. * @param request the HttpServletRequest * @param response the HttpServeltResponse * @param context the PortletContext * @param exception the exception thrown by a portlet action * @return the URL to call */ public String service(HttpServletRequest request, HttpServletResponse response, PortletContext context, Exception thrownException) { //prepare the localized resources for use by the jsp. try { NavigationUtil.prepareLocalizedResources( "com.sas.portal.portlets.displayurl.Resources", request, context); } catch (java.io.IOException ioe) { Logger.error(ioe.getMessage(), _loggingContext, ioe); } //send error to server log in default locale. Logger.error(thrownException.getMessage(), _loggingContext, thrownException); //get msg in user's locale. String msg = null; try { PortalException ourException = (PortalException) thrownException; msg = ourException.getMessage(request.getLocale()); } catch (ClassCastException cce){ msg= ""; } if (msg == null) { //prevent showing the word null in a JSP msg = ""; } //make msg available for display on error jsp. context.setAttribute("Exception_message", msg); return (String)context.getAttribute("error-page"); } } |