001: /*
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: PortletServlet.java 6408 2008-01-25 13:38:39Z docentt $
004: */
005: package org.gridsphere.provider.portlet.jsr;
006:
007: import org.apache.commons.logging.Log;
008: import org.apache.commons.logging.LogFactory;
009: import org.gridsphere.portlet.impl.*;
010: import org.gridsphere.portlet.service.spi.PortletServiceFactory;
011: import org.gridsphere.portletcontainer.ApplicationPortlet;
012: import org.gridsphere.portletcontainer.PortletPreferencesManager;
013: import org.gridsphere.portletcontainer.PortletStatus;
014: import org.gridsphere.portletcontainer.impl.ApplicationPortletImpl;
015: import org.gridsphere.portletcontainer.impl.PortletWebApplicationImpl;
016: import org.gridsphere.portletcontainer.impl.descriptor.*;
017: import org.gridsphere.portletcontainer.impl.descriptor.types.TransportGuaranteeType;
018: import org.gridsphere.services.core.persistence.PersistenceManagerRdbms;
019: import org.gridsphere.services.core.persistence.PersistenceManagerService;
020: import org.gridsphere.services.core.portal.PortalConfigService;
021: import org.gridsphere.services.core.registry.PortletManagerService;
022: import org.gridsphere.services.core.registry.PortletRegistryService;
023: import org.gridsphere.services.core.security.auth.AuthModuleService;
024: import org.gridsphere.services.core.user.User;
025: import org.gridsphere.services.core.setup.PortletsSetupModuleService;
026:
027: import javax.portlet.*;
028: import javax.servlet.Servlet;
029: import javax.servlet.ServletConfig;
030: import javax.servlet.ServletContext;
031: import javax.servlet.ServletException;
032: import javax.servlet.http.*;
033: import java.io.IOException;
034: import java.io.InputStream;
035: import java.io.PrintWriter;
036: import java.io.StringWriter;
037: import java.util.*;
038: import java.util.ResourceBundle;
039:
040: public class PortletServlet extends HttpServlet implements Servlet,
041: ServletConfig, HttpSessionAttributeListener,
042: HttpSessionListener, HttpSessionActivationListener {
043:
044: private transient Log log = LogFactory.getLog(PortletServlet.class);
045:
046: private transient PortletRegistryService registryService = null;
047: private transient PortalConfigService configService = null;
048:
049: private PortletWebApplicationImpl portletWebApp = null;
050:
051: private PortletContext portletContext = null;
052:
053: private Map<String, Portlet> portlets = null;
054: private Map<String, String> portletclasses = null;
055: private Map<String, ApplicationPortlet> portletApps = null;
056: private Map<String, PortletConfig> portletConfigHash = null;
057:
058: private Map<String, String> userKeys = new HashMap<String, String>();
059: private List<String> securePortlets = new ArrayList<String>();
060:
061: private transient PersistenceManagerService pms = (PersistenceManagerService) PortletServiceFactory
062: .createPortletService(PersistenceManagerService.class, true);
063:
064: public void init(ServletConfig config) throws ServletException {
065: super .init(config);
066: log.info("in init of PortletServlet");
067: portlets = new Hashtable<String, Portlet>();
068: portletclasses = new Hashtable<String, String>();
069: portletApps = new Hashtable<String, ApplicationPortlet>();
070: portletConfigHash = new Hashtable<String, PortletConfig>();
071: }
072:
073: public void loadJSRPortletWebapp() {
074: registryService = (PortletRegistryService) PortletServiceFactory
075: .createPortletService(PortletRegistryService.class,
076: true);
077: configService = (PortalConfigService) PortletServiceFactory
078: .createPortletService(PortalConfigService.class, true);
079:
080: ServletContext ctx = this .getServletContext();
081:
082: portletWebApp = new PortletWebApplicationImpl(ctx, Thread
083: .currentThread().getContextClassLoader());
084: if (portletWebApp.getWebApplicationStatus().equals(
085: PortletStatus.FAILURE))
086: return;
087:
088: Collection<ApplicationPortlet> appPortlets = portletWebApp
089: .getAllApplicationPortlets();
090: for (ApplicationPortlet appPortlet : appPortlets) {
091: String portletClass = appPortlet
092: .getApplicationPortletClassName();
093: String portletName = appPortlet.getApplicationPortletName();
094: try {
095: // instantiate portlet classes
096: Portlet portletInstance = (Portlet) Class.forName(
097: portletClass).newInstance();
098:
099: portletApps.put(portletName, appPortlet);
100:
101: //portlets.put(portletClass, portletInstance);
102: portlets.put(portletName, portletInstance);
103:
104: // mappings between names and classes
105: portletclasses.put(portletClass, portletName);
106: log.debug("Creating new portlet instance: "
107: + portletClass);
108:
109: // put portlet web app in registry
110:
111: } catch (Exception e) {
112: String msg = "Unable to create jsr portlet instance: "
113: + portletClass;
114: log.error(msg, e);
115: appPortlet
116: .setApplicationPortletStatus(PortletStatus.FAILURE);
117: appPortlet.setApplicationPortletStatusMessage(msg);
118: portletWebApp
119: .setWebApplicationStatusMessage("FAILURE to instantiate one or more portlet instances");
120: portletWebApp
121: .setWebApplicationStatus(PortletStatus.FAILURE);
122: } finally {
123: registryService.addWebApplication(portletWebApp);
124: }
125: }
126:
127: UserAttribute[] userAttrs = portletWebApp.getUserAttributes();
128: if (userAttrs != null) {
129: String key = null;
130: for (int i = 0; i < userAttrs.length; i++) {
131: key = userAttrs[i].getName().getContent();
132: userKeys.put(key, "");
133: }
134: }
135:
136: SecurityConstraint[] secConstraints = portletWebApp
137: .getSecurityConstraints();
138: if (secConstraints != null) {
139: for (int i = 0; i < secConstraints.length; i++) {
140: PortletCollection portlets = secConstraints[i]
141: .getPortletCollection();
142: PortletName[] names = portlets.getPortletName();
143: UserDataConstraint userConstraint = secConstraints[i]
144: .getUserDataConstraint();
145: TransportGuaranteeType guaranteeType = userConstraint
146: .getTransportGuarantee();
147: if (guaranteeType.equals(TransportGuaranteeType.NONE)) {
148: names = null;
149: }
150: if (names != null) {
151: for (int j = 0; j < names.length; j++) {
152: securePortlets.add(names[j].getContent());
153: }
154: }
155: }
156: }
157:
158: // create portlet context
159: portletContext = new PortletContextImpl(ctx);
160:
161: // load in any authentication modules if found-- this is a GridSphere extension
162:
163: AuthModuleService authModuleService = (AuthModuleService) PortletServiceFactory
164: .createPortletService(AuthModuleService.class, true);
165: InputStream is = getServletContext().getResourceAsStream(
166: "/WEB-INF/authmodules.xml");
167: if (is != null) {
168: String authModulePath = this .getServletContext()
169: .getRealPath("/WEB-INF/authmodules.xml");
170: log.info("loading authentication modules from: "
171: + authModulePath);
172: authModuleService.loadAuthModules(authModulePath, Thread
173: .currentThread().getContextClassLoader());
174: } else {
175: log.debug("no auth module descriptor found");
176: }
177:
178: // load in any portlets setup modules if found-- this is a GridSphere extension
179:
180: PortletsSetupModuleService portletsSetupModuleService = (PortletsSetupModuleService) PortletServiceFactory
181: .createPortletService(PortletsSetupModuleService.class,
182: true);
183: is = getServletContext().getResourceAsStream(
184: "/WEB-INF/portletssetupmodules.xml");
185: if (is != null) {
186: String portletsSetupModulePath = this .getServletContext()
187: .getRealPath("/WEB-INF/portletssetupmodules.xml");
188: if (portletWebApp.getWebApplicationStatus().equals(
189: PortletStatus.FAILURE)) {
190: log
191: .debug("portlets setup modules from: "
192: + portletsSetupModulePath
193: + " will not be loaded due to webapp loading failure");
194: return;
195: }
196: log.info("loading portlets setup modules from: "
197: + portletsSetupModulePath);
198: portletsSetupModuleService.loadPortletsSetupModules(
199: portletsSetupModulePath, portletWebApp, portlets,
200: Thread.currentThread().getContextClassLoader());
201: } else {
202: log.debug("no portlets setup module descriptor found");
203: }
204: }
205:
206: public void service(HttpServletRequest request,
207: HttpServletResponse response) throws ServletException,
208: IOException {
209: // if no lifecycle method exists, redirect to error page!
210: String method = (String) request
211: .getAttribute(SportletProperties.PORTLET_LIFECYCLE_METHOD);
212: if (method == null) {
213: response.sendRedirect("/"
214: + configService.getProperty("gridsphere.deploy")
215: + "/"
216: + configService.getProperty("gridsphere.context")
217: + "?" + SportletProperties.LAYOUT_PAGE_PARAM + "="
218: + "ErrorLayout" + "&"
219: + "errorPage=unauthorized.jsp");
220: return;
221: }
222:
223: if (method.equals(SportletProperties.LOAD)) {
224: loadJSRPortletWebapp();
225: return;
226: } else if (method.equals(SportletProperties.INIT)) {
227: if (portletWebApp.getWebApplicationStatus().equals(
228: PortletStatus.FAILURE))
229: return;
230: Set set = portlets.keySet();
231: Iterator it = set.iterator();
232: while (it.hasNext()) {
233: String portletName = (String) it.next();
234: ApplicationPortletImpl appPortlet = (ApplicationPortletImpl) portletApps
235: .get(portletName);
236: Portlet portlet = (Portlet) portlets.get(portletName);
237: log
238: .debug("in PortletServlet: service(): Initializing portlet "
239: + portletName);
240: PortletDefinition portletDef = portletWebApp
241: .getPortletDefinition(portletName);
242: PortletConfig portletConfig = new PortletConfigImpl(
243: getServletConfig(), portletDef, Thread
244: .currentThread()
245: .getContextClassLoader());
246: try {
247: portlet.init(portletConfig);
248: portletConfigHash.put(portletName, portletConfig);
249: } catch (Exception e) {
250: appPortlet
251: .setApplicationPortletStatus(PortletStatus.FAILURE);
252: StringWriter sw = new StringWriter();
253: PrintWriter pout = new PrintWriter(sw);
254: e.printStackTrace(pout);
255: appPortlet
256: .setApplicationPortletStatusMessage("Unable to initialize portlet "
257: + portletName
258: + "\n\n"
259: + sw.getBuffer());
260: log.error(
261: "in PortletServlet: service(): Unable to INIT portlet "
262: + portletName, e);
263: // PLT.5.5.2.1 Portlet that fails to initialize must not be placed in active service
264: it.remove();
265: portletWebApp
266: .setWebApplicationStatus(PortletStatus.FAILURE);
267: portletWebApp
268: .setWebApplicationStatusMessage("Failed to initialize one or more portlets");
269: }
270: }
271:
272: PortletManagerService manager = (PortletManagerService) PortletServiceFactory
273: .createPortletService(PortletManagerService.class,
274: true);
275: manager.addPortletWebApplication(portletWebApp);
276: return;
277: } else if (method.equals(SportletProperties.DESTROY)) {
278: Iterator it = portlets.keySet().iterator();
279: while (it.hasNext()) {
280: String portletName = (String) it.next();
281: Portlet portlet = (Portlet) portlets.get(portletName);
282: log
283: .debug("in PortletServlet: service(): Destroying portlet "
284: + portletName);
285: try {
286: portlet.destroy();
287: it.remove();
288: } catch (RuntimeException e) {
289: log.error(
290: "Caught exception during portlet destroy",
291: e);
292: }
293: }
294: return;
295: } else if (method.equals(SportletProperties.LOGIN)) {
296:
297: } else if (method.equals(SportletProperties.LOGOUT)) {
298: request.getSession(true).invalidate();
299: }
300:
301: // There must be a portlet ID to know which portlet to service
302: String pid = (String) request
303: .getAttribute(SportletProperties.PORTLETID);
304: String cid = (String) request
305: .getAttribute(SportletProperties.COMPONENT_ID);
306:
307: if (pid == null) {
308: // it may be in the request parameter
309: pid = request.getParameter(SportletProperties.PORTLETID);
310: if (pid == null) {
311: log
312: .debug("in PortletServlet: service(): No PortletID found in request!");
313: return;
314: }
315: request.setAttribute(SportletProperties.PORTLETID, pid);
316: }
317:
318: log.debug("have a portlet id " + pid + " component id= " + cid);
319:
320: String portletName = "";
321: int idx = pid.indexOf("#");
322: Portlet portlet = null;
323: if (idx > 0) {
324: portletName = pid.substring(idx + 1);
325: // this hack uses the portletclasses hash that identifies classname to portlet mappings
326: } else {
327: portletName = (String) portletclasses.get(pid);
328: }
329: if (portletName == null) {
330: log
331: .debug("Check the layout descriptors to make sure the portlet identified as "
332: + pid
333: + " matches with the class and/or portlet name of the portlet.xml");
334: return;
335: }
336: portlet = (Portlet) portlets.get(portletName);
337: request.setAttribute(SportletProperties.PORTLET_CONFIG,
338: portletConfigHash.get(portletName));
339:
340: ApplicationPortlet appPortlet = registryService
341: .getApplicationPortlet(pid);
342:
343: if (appPortlet == null) {
344: log
345: .error("Unable to get portlet from registry identified by: "
346: + pid);
347: return;
348: }
349:
350: // perform user conversion from gridsphere to JSR model
351: User user = (User) request
352: .getAttribute(SportletProperties.PORTLET_USER);
353: Map<String, String> userInfo = new HashMap<String, String>();
354: ;
355: String userId = null;
356: if (user != null) {
357: userId = user.getID();
358: userInfo.putAll(userKeys);
359: if (userInfo.containsKey("user.name"))
360: userInfo.put("user.name", user.getUserName());
361: if (userInfo.containsKey("user.id"))
362: userInfo.put("user.id", user.getID());
363: if (userInfo.containsKey("user.email"))
364: userInfo.put("user.email", user.getEmailAddress());
365: if (userInfo.containsKey("user.organization"))
366: userInfo.put("user.organization", user
367: .getOrganization());
368: if (userInfo.containsKey("user.lastlogintime"))
369: userInfo.put("user.lastlogintime", String.valueOf(user
370: .getLastLoginTime()));
371: if (userInfo.containsKey("user.name.full"))
372: userInfo.put("user.name.full", user.getFullName());
373: if (userInfo.containsKey("user.name.first"))
374: userInfo.put("user.name.first", user.getFirstName());
375: if (userInfo.containsKey("user.name.last"))
376: userInfo.put("user.name.last", user.getLastName());
377: if (userInfo.containsKey("user.timezone"))
378: userInfo.put("user.timezone", (String) user
379: .getAttribute(User.TIMEZONE));
380: if (userInfo.containsKey("user.locale"))
381: userInfo.put("user.locale", (String) user
382: .getAttribute(User.LOCALE));
383: if (userInfo.containsKey("user.theme"))
384: userInfo.put("user.theme", (String) user
385: .getAttribute(User.THEME));
386:
387: if (userInfo.containsKey("user.login.id"))
388: userInfo.put("user.login.id", user.getUserName());
389:
390: Enumeration e = user.getAttributeNames();
391: while (e.hasMoreElements()) {
392: String key = (String) e.nextElement();
393: if (userInfo.containsKey(key))
394: userInfo.put(key, (String) user.getAttribute(key));
395: }
396:
397: request.setAttribute(PortletRequest.USER_INFO, userInfo);
398: }
399:
400: // portlet preferences
401: PortalContext portalContext = appPortlet.getPortalContext();
402: request.setAttribute(SportletProperties.PORTAL_CONTEXT,
403: portalContext);
404: if (portlet == null) {
405: log
406: .error("in PortletServlet: service(): No portlet matching "
407: + pid + " found!");
408: return;
409: }
410:
411: request.removeAttribute(SportletProperties.SSL_REQUIRED);
412: if (securePortlets.contains(pid)) {
413: request.setAttribute(SportletProperties.SSL_REQUIRED,
414: "true");
415: }
416:
417: if (method.equals(SportletProperties.SERVICE)) {
418:
419: String action = (String) request
420: .getAttribute(SportletProperties.PORTLET_ACTION_METHOD);
421: if (action != null) {
422: log.debug("in PortletServlet: action is not NULL");
423: if (action.equals(SportletProperties.DO_TITLE)) {
424: RenderRequest renderRequest = new RenderRequestImpl(
425: request, portletContext);
426: RenderResponse renderResponse = new RenderResponseImpl(
427: request, response);
428: renderRequest.setAttribute(
429: SportletProperties.RENDER_REQUEST,
430: renderRequest);
431: renderRequest.setAttribute(
432: SportletProperties.RENDER_RESPONSE,
433: renderResponse);
434: log.debug("in PortletServlet: do title " + pid);
435: try {
436: doTitle(portlet, renderRequest, renderResponse);
437: } catch (Exception e) {
438: log.error("Error during doTitle:", e);
439: request.getSession(true).setAttribute(
440: SportletProperties.PORTLETERROR + pid,
441: new PortletException(e));
442: }
443: } else if (action
444: .equals(SportletProperties.WINDOW_EVENT)) {
445: // do nothing
446: } else if (action
447: .equals(SportletProperties.ACTION_PERFORMED)) {
448: // create portlet preferences manager
449: log.debug("in PortletServlet: do processAction "
450: + pid);
451: PortletPreferencesManager prefsManager = appPortlet
452: .getPortletPreferencesManager(pid, userId,
453: false);
454: request
455: .setAttribute(
456: SportletProperties.PORTLET_PREFERENCES_MANAGER,
457: prefsManager);
458:
459: processAction(portlet, portalContext, request,
460: response, cid, pid);
461: }
462: } else {
463: // create portlet preferences manager
464: PortletPreferencesManager prefsManager = appPortlet
465: .getPortletPreferencesManager(pid, userId, true);
466: request.setAttribute(
467: SportletProperties.PORTLET_PREFERENCES_MANAGER,
468: prefsManager);
469:
470: render(portlet, request, response, pid);
471:
472: }
473: } else {
474: log.error("in PortletServlet: service(): No "
475: + SportletProperties.PORTLET_LIFECYCLE_METHOD
476: + " found in request!");
477: }
478: }
479:
480: protected void processAction(Portlet portlet,
481: PortalContext portalContext, HttpServletRequest request,
482: HttpServletResponse response, String cid, String pid)
483: throws ServletException {
484:
485: ActionRequestImpl actionRequest = new ActionRequestImpl(
486: request, portletContext);
487: ActionResponse actionResponse = new ActionResponseImpl(request,
488: response);
489:
490: String webappname = portletWebApp.getWebApplicationName();
491: PersistenceManagerRdbms pm = pms
492: .getPersistenceManagerRdbms(webappname);
493:
494: try {
495:
496: if (pm != null) {
497: log
498: .debug("Starting a database transaction for webapp: "
499: + webappname);
500: pm.beginTransaction();
501: }
502:
503: log.debug("in PortletServlet: action handling portlet "
504: + pid);
505:
506: // INVOKE PORTLET ACTION
507: portlet.processAction(actionRequest, actionResponse);
508: Map params = ((ActionResponseImpl) actionResponse)
509: .getRenderParameters();
510: request.setAttribute(SportletProperties.RENDER_PARAM_PREFIX
511: + pid + "_" + cid, params);
512: log.debug("placing render params in session : key= "
513: + SportletProperties.RENDER_PARAM_PREFIX + pid
514: + "_" + cid);
515:
516: // Commit and cleanup
517: log.info("Committing the database transaction");
518:
519: if (pm != null)
520: pm.endTransaction();
521:
522: } catch (Throwable ex) {
523: //log.error("Error during processAction:", ex);
524: request.setAttribute(SportletProperties.PORTLETERROR + pid,
525: ex);
526:
527: if (pm != null) {
528: pm.endTransaction();
529: try {
530: if (pm != null)
531: pm.rollbackTransaction();
532: } catch (Throwable rbEx) {
533: log
534: .error(
535: "Could not rollback transaction after exception!",
536: rbEx.getCause());
537: }
538: }
539: // Let others handle it... maybe another interceptor for exceptions?
540: //throw new ServletException(ex.getCause());
541: } finally {
542: try {
543: redirect(request, response, actionRequest,
544: actionResponse, portalContext);
545: } catch (IOException e) {
546: log.error("Unable to handle redirect", e);
547: }
548: }
549:
550: }
551:
552: protected void render(Portlet portlet, HttpServletRequest request,
553: HttpServletResponse response, String pid)
554: throws ServletException {
555: RenderRequest renderRequest = new RenderRequestImpl(request,
556: portletContext);
557: RenderResponse renderResponse = new RenderResponseImpl(request,
558: response);
559:
560: renderRequest.setAttribute(SportletProperties.RENDER_REQUEST,
561: renderRequest);
562: renderRequest.setAttribute(SportletProperties.RENDER_RESPONSE,
563: renderResponse);
564:
565: log.debug("in PortletServlet: rendering portlet " + pid);
566: if (renderRequest
567: .getAttribute(SportletProperties.RESPONSE_COMMITTED) == null) {
568: String webappname = portletWebApp.getWebApplicationName();
569: PersistenceManagerRdbms pm = pms
570: .getPersistenceManagerRdbms(webappname);
571: try {
572: if (pm != null)
573: pm.beginTransaction();
574: portlet.render(renderRequest, renderResponse);
575: if (pm != null)
576: pm.endTransaction();
577:
578: } catch (UnavailableException e) {
579: try {
580: portlet.destroy();
581: } catch (Exception d) {
582: log
583: .error(
584: "in PortletServlet(): destroy caught exception: ",
585: d);
586: }
587: } catch (Throwable ex) {
588: //log.error("in render: caught exception: ", ex);
589:
590: try {
591: if (pm != null) {
592: log
593: .info("Committing database transaction for webapp: "
594: + portletWebApp
595: .getWebApplicationName());
596: pm.endTransaction();
597: pm.rollbackTransaction();
598: }
599: } catch (Throwable rbEx) {
600: throw new ServletException(
601: "Could not rollback transaction after exception!",
602: rbEx);
603: }
604:
605: throw new ServletException(ex);
606: }
607: }
608: }
609:
610: protected void doTitle(Portlet portlet, RenderRequest request,
611: RenderResponse response) throws IOException,
612: PortletException {
613: Portlet por = (Portlet) portlet;
614: if (por instanceof GenericPortlet) {
615: GenericPortlet genPortlet = ((GenericPortlet) portlet);
616: if (genPortlet.getPortletConfig() == null)
617: throw new PortletException(
618: "Unable to get PortletConfig from Portlet");
619: ResourceBundle resBundle = genPortlet.getPortletConfig()
620: .getResourceBundle(request.getLocale());
621: String title = resBundle.getString("javax.portlet.title");
622: response.setContentType("text/html");
623: PrintWriter out = response.getWriter();
624: out.println(title);
625: }
626: }
627:
628: protected void doGet(HttpServletRequest req, HttpServletResponse res)
629: throws ServletException, IOException {
630: super .doGet(req, res);
631: }
632:
633: protected void doPut(HttpServletRequest req, HttpServletResponse res)
634: throws ServletException, IOException {
635: super .doPut(req, res);
636: }
637:
638: protected void doPost(HttpServletRequest req,
639: HttpServletResponse res) throws ServletException,
640: IOException {
641: super .doPost(req, res);
642: }
643:
644: protected void doTrace(HttpServletRequest req,
645: HttpServletResponse res) throws ServletException,
646: IOException {
647: super .doTrace(req, res);
648: }
649:
650: protected void doDelete(HttpServletRequest req,
651: HttpServletResponse res) throws ServletException,
652: IOException {
653: super .doDelete(req, res);
654: }
655:
656: protected void redirect(HttpServletRequest servletRequest,
657: HttpServletResponse servletResponse,
658: ActionRequest actionRequest, ActionResponse actionResponse,
659: PortalContext portalContext) throws IOException {
660: if (actionResponse instanceof ActionResponseImpl) {
661: ActionResponseImpl aResponse = (ActionResponseImpl) actionResponse;
662: String location = aResponse.getRedirectLocation();
663:
664: if (location != null) {
665: javax.servlet.http.HttpServletResponse redirectResponse = servletResponse;
666: while (redirectResponse instanceof javax.servlet.http.HttpServletResponseWrapper) {
667: redirectResponse = (javax.servlet.http.HttpServletResponse) ((javax.servlet.http.HttpServletResponseWrapper) redirectResponse)
668: .getResponse();
669: }
670:
671: log.debug("redirecting to location= " + location);
672:
673: servletRequest.setAttribute(
674: SportletProperties.PORTAL_REDIRECT_PATH,
675: location);
676: //redirectResponse.sendRedirect(location);
677:
678: } else {
679:
680: // redirect as a GET render url back to the portal
681: PortletURL url = new PortletURLImpl(servletRequest,
682: servletResponse, true);
683: Map params = aResponse.getRenderParameters();
684: url.setParameters(params);
685: servletRequest.setAttribute(
686: SportletProperties.PORTAL_REDIRECT_PATH, url
687: .toString());
688: }
689:
690: }
691: }
692:
693: /**
694: * Record the fact that a servlet context attribute was added.
695: *
696: * @param event The session attribute event
697: */
698: public void attributeAdded(HttpSessionBindingEvent event) {
699:
700: log.debug("attributeAdded('" + event.getSession().getId()
701: + "', '" + event.getName() + "', '" + event.getValue()
702: + "')");
703:
704: }
705:
706: /**
707: * Record the fact that a servlet context attribute was removed.
708: *
709: * @param event The session attribute event
710: */
711: public void attributeRemoved(HttpSessionBindingEvent event) {
712:
713: log.debug("attributeRemoved('" + event.getSession().getId()
714: + "', '" + event.getName() + "', '" + event.getValue()
715: + "')");
716:
717: }
718:
719: /**
720: * Record the fact that a servlet context attribute was replaced.
721: *
722: * @param event The session attribute event
723: */
724: public void attributeReplaced(HttpSessionBindingEvent event) {
725:
726: log.debug("attributeReplaced('" + event.getSession().getId()
727: + "', '" + event.getName() + "', '" + event.getValue()
728: + "')");
729:
730: }
731:
732: /**
733: * Record the fact that a session has been created.
734: *
735: * @param event The session event
736: */
737: public void sessionCreated(HttpSessionEvent event) {
738: log.debug("in PS sessionCreated('" + event.getSession().getId()
739: + "')");
740: //sessionManager.sessionCreated(event);
741: }
742:
743: /**
744: * Record the fact that a session has been destroyed.
745: *
746: * @param event The session event
747: */
748: public void sessionDestroyed(HttpSessionEvent event) {
749: //sessionManager.sessionDestroyed(event);
750: //loginService.sessionDestroyed(event.getSession());
751: log.debug("in PS sessionDestroyed('"
752: + event.getSession().getId() + "')");
753:
754: //HttpSession session = event.getSession();
755: //User user = (User) session.getAttribute(SportletProperties.PORTLET_USER);
756: //System.err.println("user : " + user.getUserID() + " expired!");
757: //PortletLayoutEngine engine = PortletLayoutEngine.getDefault();
758: //engine.removeUser(user);
759: //engine.logoutPortlets(event);
760: }
761:
762: /**
763: * Record the fact that a session has been created.
764: *
765: * @param event The session event
766: */
767: public void sessionDidActivate(HttpSessionEvent event) {
768: log.debug("sessionDidActivate('" + event.getSession().getId()
769: + "')");
770: //sessionManager.sessionCreated(event);
771: }
772:
773: /**
774: * Record the fact that a session has been destroyed.
775: *
776: * @param event The session event
777: */
778: public void sessionWillPassivate(HttpSessionEvent event) {
779: //sessionManager.sessionDestroyed(event);
780: //loginService.sessionDestroyed(event.getSession());
781: log.debug("sessionWillPassivate('" + event.getSession().getId()
782: + "')");
783: //HttpSession session = event.getSession();
784: //User user = (User) session.getAttribute(SportletProperties.USER);
785: //System.err.println("user : " + user.getUserID() + " expired!");
786: //PortletLayoutEngine engine = PortletLayoutEngine.getDefault();
787: //engine.removeUser(user);
788: //engine.logoutPortlets(event);
789: }
790:
791: }
|