Author: chris.laprun(a)jboss.com
Date: 2008-04-21 18:23:21 -0400 (Mon, 21 Apr 2008)
New Revision: 10683
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletControllerContext.java
Log:
- If a content provider is not found, failure happens: need a proper way to bubble the
error up without crashing Portal.
- Added logging.
- Minor refactoring.
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletControllerContext.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletControllerContext.java 2008-04-21
22:21:25 UTC (rev 10682)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletControllerContext.java 2008-04-21
22:23:21 UTC (rev 10683)
@@ -22,35 +22,38 @@
******************************************************************************/
package org.jboss.portal.core.controller.portlet;
+import org.apache.log4j.Logger;
+import org.jboss.portal.Mode;
+import org.jboss.portal.core.controller.ControllerCommand;
+import org.jboss.portal.core.controller.ControllerContext;
+import org.jboss.portal.core.impl.model.content.InternalContentProviderRegistry;
+import org.jboss.portal.core.impl.model.content.portlet.PortletContent;
+import org.jboss.portal.core.model.content.Content;
+import org.jboss.portal.core.model.content.ContentType;
+import org.jboss.portal.core.model.content.spi.ContentProvider;
+import org.jboss.portal.core.model.instance.Instance;
+import org.jboss.portal.core.model.instance.InstanceContainer;
+import org.jboss.portal.core.model.portal.Page;
+import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.core.model.portal.Window;
+import org.jboss.portal.core.navstate.NavigationalStateContext;
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.controller.PortletControllerContext;
import org.jboss.portal.portlet.controller.event.EventControllerContext;
import org.jboss.portal.portlet.controller.state.PageNavigationalState;
import org.jboss.portal.portlet.info.PortletInfo;
-import org.jboss.portal.portlet.spi.PortletInvocationContext;
-import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
import org.jboss.portal.portlet.invocation.ActionInvocation;
import org.jboss.portal.portlet.invocation.EventInvocation;
+import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.portlet.invocation.ResourceInvocation;
-import org.jboss.portal.portlet.PortletInvokerException;
-import org.jboss.portal.portlet.Portlet;
-import org.jboss.portal.core.model.portal.Page;
-import org.jboss.portal.core.model.portal.PortalObject;
-import org.jboss.portal.core.model.portal.Window;
-import org.jboss.portal.core.model.content.Content;
-import org.jboss.portal.core.model.content.spi.ContentProvider;
-import org.jboss.portal.core.model.instance.InstanceContainer;
-import org.jboss.portal.core.model.instance.Instance;
-import org.jboss.portal.core.impl.model.content.portlet.PortletContent;
-import org.jboss.portal.core.impl.model.content.InternalContentProviderRegistry;
-import org.jboss.portal.core.controller.ControllerContext;
-import org.jboss.portal.core.controller.ControllerCommand;
-import org.jboss.portal.core.navstate.NavigationalStateContext;
-import org.jboss.portal.Mode;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.spi.PortletInvocationContext;
import javax.servlet.http.Cookie;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.HashMap;
import java.util.Set;
/**
@@ -59,6 +62,7 @@
*/
public class ControllerPortletControllerContext implements PortletControllerContext
{
+ private final static Logger log =
Logger.getLogger(ControllerPortletControllerContext.class);
/** . */
private final ControllerContext controllerContext;
@@ -108,25 +112,43 @@
else
{
InternalContentProviderRegistry registry =
controllerContext.getController().getContentProviderRegistry();
- ContentProvider provider =
registry.getContentProvider(window.getContentType());
- instanceId = provider.getPortletInfo().getPortletName(Mode.VIEW);
+ ContentType contentType = window.getContentType();
+ ContentProvider provider = registry.getContentProvider(contentType);
+ if (provider != null)
+ {
+ instanceId = provider.getPortletInfo().getPortletName(Mode.VIEW);
+ }
+ else
+ {
+ log.debug("Couldn't find a ContentProvider for content type
'" + contentType + "'");
+ instanceId = null;
+ // todo: this condition should bubble up, this would happen when trying to
access a page referencing portlets
+ // for which no content provider is deployed (e.g. default page when cms
is not deployed)
+ }
}
- //
- Instance instance = instanceContainer.getDefinition(instanceId);
- if (instance != null)
+ if (instanceId != null)
{
- try
+ Instance instance = instanceContainer.getDefinition(instanceId);
+ if (instance != null)
{
- Portlet portlet = instance.getPortlet();
- infos.put(window.getName(), portlet.getInfo());
- instances.put(window.getName(), instance);
- windows.put(window.getName(), window);
+ try
+ {
+ Portlet portlet = instance.getPortlet();
+ infos.put(window.getName(), portlet.getInfo());
+ instances.put(window.getName(), instance);
+ windows.put(window.getName(), window);
+ }
+ catch (PortletInvokerException ignore)
+ {
+ log.debug("Couldn't get portlet from instance '" +
instance + "'", ignore);
+ }
}
- catch (PortletInvokerException ignore)
- {
- }
}
+ else
+ {
+ log.debug("Couldn't resolve instance id for window '" +
window.getName() + "'");
+ }
}
// State controller context
@@ -172,47 +194,18 @@
public PortletInvocationResponse invoke(ActionInvocation actionInvocation) throws
PortletInvokerException
{
- PortletInvocationFactory.contextualize(actionInvocation);
-
- //
- Window window = PortletInvocationFactory.getTargetWindow(actionInvocation);
-
- //
- Instance instance = instances.get(window.getName());
-
- //
- return instance.invoke(actionInvocation);
+ return internalInvoke(actionInvocation);
}
- /**
- * todo : handle cookies redistribution
- */
+ /** todo : handle cookies redistribution */
public PortletInvocationResponse invoke(List<Cookie> cookies, EventInvocation
eventInvocation) throws PortletInvokerException
{
- PortletInvocationFactory.contextualize(eventInvocation);
-
- //
- Window window = PortletInvocationFactory.getTargetWindow(eventInvocation);
-
- //
- Instance instance = instances.get(window.getName());
-
- //
- return instance.invoke(eventInvocation);
+ return internalInvoke(eventInvocation);
}
public PortletInvocationResponse invoke(ResourceInvocation resourceInvocation) throws
PortletInvokerException
{
- PortletInvocationFactory.contextualize(resourceInvocation);
-
- //
- Window window = PortletInvocationFactory.getTargetWindow(resourceInvocation);
-
- //
- Instance instance = instances.get(window.getName());
-
- //
- return instance.invoke(resourceInvocation);
+ return internalInvoke(resourceInvocation);
}
public EventControllerContext getEventControllerContext()
@@ -224,4 +217,18 @@
{
return stateControllerContext;
}
+
+ private PortletInvocationResponse internalInvoke(PortletInvocation actionInvocation)
throws PortletInvokerException
+ {
+ PortletInvocationFactory.contextualize(actionInvocation);
+
+ //
+ Window window = PortletInvocationFactory.getTargetWindow(actionInvocation);
+
+ //
+ Instance instance = instances.get(window.getName());
+
+ //
+ return instance.invoke(actionInvocation);
+ }
}
Show replies by date