1 23 package org.infoglue.deliver.portal.dispatcher; 24 25 import java.util.Enumeration ; 26 import java.util.Properties ; 27 28 import javax.servlet.ServletConfig ; 29 import javax.servlet.ServletException ; 30 import javax.servlet.http.HttpServletRequest ; 31 import javax.servlet.http.HttpServletResponse ; 32 33 import org.apache.commons.logging.Log; 34 import org.apache.commons.logging.LogFactory; 35 import org.apache.pluto.PortletContainerServices; 36 import org.apache.pluto.portalImpl.core.PortletContainerEnvironment; 37 import org.apache.pluto.portalImpl.core.PortletContainerFactory; 38 import org.apache.pluto.portalImpl.factory.FactoryAccess; 39 import org.apache.pluto.portalImpl.services.ServiceManager; 40 import org.apache.pluto.portalImpl.services.factorymanager.FactoryManager; 41 import org.infoglue.deliver.portal.ServletConfigContainer; 42 43 51 public class PortalServletDispatcher extends DeliveryServletDispatcher { 52 53 private static final Log log = LogFactory.getLog(PortalServletDispatcher.class); 54 55 public static final String PORTLET_CONTAINER_NAME = "portal_container_name"; 56 57 private static String uniqueContainerName; 58 59 public void init(ServletConfig config) throws ServletException 60 { 61 log.debug("init of servlet"); 62 super.init(config); 64 65 ServletConfigContainer.getContainer().setServletConfig(config); 68 69 try 71 { 72 ServiceManager.init(config); 73 } 74 catch (Throwable exc) 75 { 76 log.error("Initialization failed!", exc); 77 throw (new javax.servlet.UnavailableException ("Initialization of one or more services failed.")); 78 } 79 80 try 81 { 82 ServiceManager.postInit(config); 83 } 84 catch (Throwable expos) 85 { 86 log.error("Post initialization failed!", expos); 87 throw (new javax.servlet.UnavailableException ("Post initialization of one or more services failed.")); 88 } 89 90 if (!PortletContainerFactory.getPortletContainer().isInitialized()) 91 { 92 uniqueContainerName = "pluto-" + System.currentTimeMillis(); 93 94 if (log.isInfoEnabled()) 95 log.info("Initializing PortletContainer [" + uniqueContainerName + "]..."); 96 97 PortletContainerEnvironment environment = new PortletContainerEnvironment(); 98 99 environment.addContainerService(org.apache.pluto.portalImpl.services.log.Log.getService()); 100 environment.addContainerService(FactoryManager.getService()); 101 environment.addContainerService(FactoryAccess.getInformationProviderContainerService()); 102 environment.addContainerService(FactoryAccess.getDynamicTitleContainerService()); 103 104 Properties properties = new Properties (); 105 106 try 107 { 108 PortletContainerFactory.getPortletContainer().init(uniqueContainerName, config, environment, properties); 109 } 110 catch (Throwable exc) 111 { 112 log.warn("Initialization of the portlet container failed!", exc); 113 } 117 } 118 else if (log.isInfoEnabled()) 119 { 120 log.info("PortletContainer already initialized"); 121 } 122 123 126 log.info("Ready to serve you."); 127 } 128 129 public void destroy() 130 { 131 super.destroy(); 132 133 if (log.isInfoEnabled()) 134 log.info("Shutting down portlet container. . ."); 135 try 136 { 137 PortletContainerFactory.getPortletContainer().shutdown(); 138 139 ServiceManager.destroy(getServletConfig()); 141 } 142 catch (Throwable t) 143 { 144 log("Destruction failed!", t); 145 } 146 } 147 148 public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException 149 { 150 if (log.isDebugEnabled()) 151 { 152 log.debug("\n******************************************** infogluePortal service()"); 153 Enumeration enumeration = req.getParameterNames(); 154 while (enumeration.hasMoreElements()) 155 { 156 String name = (String ) enumeration.nextElement(); 157 Object o = req.getParameter(name); 158 log.debug(name + "=" + o); 159 } 160 161 enumeration = req.getAttributeNames(); 162 while (enumeration.hasMoreElements()) 163 { 164 String name = (String ) enumeration.nextElement(); 165 Object o = req.getAttribute(name); 166 log.debug(name + "=" + o); 167 } 168 } 169 PortletContainerServices.prepare(uniqueContainerName); 171 req.setAttribute(PORTLET_CONTAINER_NAME, uniqueContainerName); 174 175 super.service(req, resp); 177 } 178 179 180 } | Popular Tags |