Author: alexsmirnov
Date: 2007-12-12 13:30:12 -0500 (Wed, 12 Dec 2007)
New Revision: 4795
Added:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/ExceptionHandler.java
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/ExceptionHandlerImpl.java
Modified:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java
Log:
Create pluggable exceptions handling
Modified:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java 2007-12-12
17:41:30 UTC (rev 4794)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/AjaxPortletBridge.java 2007-12-12
18:30:12 UTC (rev 4795)
@@ -38,7 +38,10 @@
public class AjaxPortletBridge extends AbstractAjaxBridge implements Bridge {
private static final Log log = LogFactory.getLog(AjaxPortletBridge.class);
+ private static final String EXCEPTION_HANDLER_CLASS_PARAMETER =
ExceptionHandler.class.getName();
private PortletConfig portletConfig;
+
+ private ExceptionHandler exceptionHandler;
/*
* (non-Javadoc)
@@ -71,6 +74,7 @@
} catch (FacesException e) {
throw new PortletException("Initialization error", e);
}
+ exceptionHandler = createExceptionHandler(config);
if (log.isDebugEnabled()) {
log.debug("Done portlet initialisation for "
+ config.getPortletName());
@@ -78,6 +82,30 @@
// getPortletContext().setAttribute(PORTLET_CONFIG, config);
}
+ protected ExceptionHandler createExceptionHandler(PortletConfig config) {
+ String exceptionHandlerClassName =
config.getInitParameter(EXCEPTION_HANDLER_CLASS_PARAMETER);
+ ExceptionHandler handler = null;
+ if(null != exceptionHandlerClassName){
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ if(null == classLoader){
+ classLoader = this.getClass().getClassLoader();
+ }
+ try {
+ Class<ExceptionHandler> exceptionHandlerClass = (Class<ExceptionHandler>)
classLoader.loadClass(exceptionHandlerClassName);
+ handler = exceptionHandlerClass.newInstance();
+ } catch (ClassNotFoundException e) {
+ handler = new ExceptionHandlerImpl();
+ } catch (InstantiationException e) {
+ handler = new ExceptionHandlerImpl();
+ } catch (IllegalAccessException e) {
+ handler = new ExceptionHandlerImpl();
+ }
+ } else {
+ handler = new ExceptionHandlerImpl();
+ }
+ return handler;
+ }
+
public void doFacesRequest(ActionRequest request, ActionResponse response)
throws BridgeException {
initRequest(request, response, Bridge.PortletPhase.ActionPhase);
@@ -99,7 +127,7 @@
} catch (Exception e) {
// TODO - handle exception.
log.error("Error processing execute lifecycle", e);
- throw new BridgeException("Error processing execute lifecycle ", e);
+ exceptionHandler.processActionException(facesContext, windowState, e);
} finally {
facesContext.release();
}
@@ -109,6 +137,8 @@
throws BridgeException {
initRequest(request, response, Bridge.PortletPhase.RenderPhase);
FacesContext facesContext = getFacesContext(request, response);
+ PortletViewState windowState = PortletStateHolder.getInstance(
+ facesContext).getWindowState(facesContext);
try {
if (null == response.getContentType()) {
String contenttype = request.getResponseContentType();
@@ -134,14 +164,7 @@
// Ignore MissingResourceException
}
}
- // PrintWriter writer = response.getWriter();
String namespace = response.getNamespace();
- // Write anchor for update portlet pages by ajax.
- // TODO - configure html element and style/class.
- // writer.println("<div id='" + namespace + "'>");
- // writer.flush();
- PortletViewState windowState = PortletStateHolder.getInstance(
- facesContext).getWindowState(facesContext);
windowState.restoreRequest(facesContext, true);
if (null == facesContext.getViewRoot()) {
execute(facesContext);
@@ -185,7 +208,7 @@
response.reset();
// TODO - handle exception
log.error("Error processing execute lifecycle", e);
- throw new BridgeException("Error processing execute lifecycle ", e);
+ exceptionHandler.processRenderException(facesContext, windowState, e);
} finally {
facesContext.release();
}
Added:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/ExceptionHandler.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/ExceptionHandler.java
(rev 0)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/ExceptionHandler.java 2007-12-12
18:30:12 UTC (rev 4795)
@@ -0,0 +1,32 @@
+package org.ajax4jsf.portlet;
+
+import javax.faces.context.FacesContext;
+import javax.portlet.faces.BridgeException;
+
+import org.ajax4jsf.portlet.application.PortletViewState;
+
+/**
+ * @author asmirnov
+ *
+ */
+public interface ExceptionHandler {
+
+ /**
+ * Process JSF exceptions at the portlet action phase
+ * @param context
+ * @param windowState
+ * @param e
+ * @throws BridgeException
+ */
+ public void processActionException(FacesContext context, PortletViewState windowState,
Exception e) throws BridgeException;
+
+ /**
+ * Process JSF exceptions at the portlet render phase.
+ * @param context
+ * @param windowState
+ * @param e
+ * @throws BridgeException
+ */
+ public void processRenderException(FacesContext context, PortletViewState windowState,
Exception e) throws BridgeException;
+
+}
Property changes on:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/ExceptionHandler.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author
Added:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/ExceptionHandlerImpl.java
===================================================================
---
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/ExceptionHandlerImpl.java
(rev 0)
+++
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/ExceptionHandlerImpl.java 2007-12-12
18:30:12 UTC (rev 4795)
@@ -0,0 +1,34 @@
+/**
+ *
+ */
+package org.ajax4jsf.portlet;
+
+import javax.faces.context.FacesContext;
+import javax.portlet.faces.BridgeException;
+
+import org.ajax4jsf.portlet.application.PortletViewState;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class ExceptionHandlerImpl implements ExceptionHandler {
+
+ /* (non-Javadoc)
+ * @see
org.ajax4jsf.portlet.ExceptionHandler#processActionException(javax.faces.context.FacesContext,
org.ajax4jsf.portlet.application.PortletViewState, java.lang.Exception)
+ */
+ public void processActionException(FacesContext context,
+ PortletViewState windowState, Exception e) throws BridgeException {
+ throw new BridgeException("Error processing action lifecycle",e);
+
+ }
+
+ /* (non-Javadoc)
+ * @see
org.ajax4jsf.portlet.ExceptionHandler#processRenderException(javax.faces.context.FacesContext,
org.ajax4jsf.portlet.application.PortletViewState, java.lang.Exception)
+ */
+ public void processRenderException(FacesContext context,
+ PortletViewState windowState, Exception e) throws BridgeException {
+ throw new BridgeException("Error processing render lifecycle",e);
+ }
+
+}
Property changes on:
trunk/extensions/portletbridge/portletbridge-impl/src/main/java/org/ajax4jsf/portlet/ExceptionHandlerImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Revision Author