Learn uportal-1

zhaozj2021-02-16  121

PortalSessionManager under Org.jasig.Portal is the entry class for Uportal

Package org.jasig.portal;

Import java.io.IOException; import java.net.url; import java.util.collections; import java.util.hashset; import java.util.raz; import java.util.rtom; Import java.util.set;

import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax .servlet.http.httpsession;

Import org.jasig.portal.channels.portlet.cportletadapter; import org.jasig.portal.jndi.jndimanager; import org.jasig.portal.services.logservice; import org.jasig.portal.utils.ResourceLoAder;

Extend HTTPSERVLET, as Portal Container Extends httpservlet {

Public static final string interface_tag_value = long.toHexString ((new random ()). nextlong ()); public static final string idempotent_url_tag = "idempotent";

private static boolean initialized = false; if the initialization private static ServletContext servletContext = null; private static PortalSessionManager instance = null; private static boolean fatalError = false; public static final ErrorID initPortalContext = new ErrorID ( "config", "JNDI", "Can not initialize JNDI CONTEXT ");

/ ** Return to instance * / public static final portalsessionManager getInstance () {Return Instance;}

// Following flag allows to disable features that prevent // repeated requests from going through. This is useful // when debugging and typing things in on a command line. // Otherwise, the flag should be set to false. Private static final boolean ALLOW_REPEATED_REQUESTS = PropertiesManager.getPropertyasBoolean ("Org.jasig.Portal.portalSessionManager.allow_repeated_requests); // Generate random number private static final random randomGenerator = new random ();

Static {logservice.log (logservice.info, "uportal started");

/ ** * Initialize the PortalSessionManager servlet * @throws ServletException * / public void init () throws ServletException {if (initialized!) {Instance = this; // Retrieve the servlet configuration object from the servlet container // and make sure it's available ServletConfig sc = getServletConfig (); if (sc == null) {throw new ServletException ( "PortalSessionManager.init (): ServletConfig object was returned as null");} // Supply PortletContainer with ServletConfig CPortletAdapter.setServletConfig (sc); servletContext = sc.getServletContext ();

try {JNDIManager.initializePortalContext ();} catch (Exception pe) {ExceptionHelper.genericTopHandler (initPortalContext, pe); fatalError = true;}! // Turn off URL caching if it has been requested if (PropertiesManager.getPropertyAsBoolean ( "org. jasig.portal.PortalSessionManager.url_caching ")) {// strangely, we have to instantiate a URLConnection to turn off caching, so we'll get something we know is there try {URL url = ResourceLoader.getResourceAsURL (PortalSessionManager.class," /properties/portal.properties "); URLConnection conn = url.openConnection (); conn.setDefaultUseCaches (false);} catch (Exception e) {LogService.log (LogService.WARN," PortalSessionManager.init (): Caught Exception trying To disable url caching ");}} // log ORDERLY Shutdown Time Runtime.getRuntime (). Addshutdownhook (" Uportal Shutdown Hook "{public void Run ) {Logservice.log (logservice.info, "uPortal stopped");}});

// flag what the portal has been initialized initialized = true;

// Get the SAX IMPLEMENTATION IF ("org.xml.sax.driver") == null) {System.SetProperty ("org.xml.sax.driver", PropertiesManager.getProperty ("ORG.XML. SAX.DRIVER ");}}}

/ ** * Process HTTP POST request * * @param req an incoming HttpServletRequest value * @param res an outgoing HttpServletResponse value * @exception ServletException if an error occurs * @exception IOException if an error occurs * / public void doPost (HttpServletRequest req, HttpServletResponse res) {doGet (req, res);}. / ** * Process HTTP GET request * * @param req an incoming HttpServletRequest * @param res an outgoing HttpServletResponse * @exception ServletException if an error occurs * @exception IOException if an error occurs * / public void doGet (HttpServletRequest req, HttpServletResponse res) {// Send the uPortal version in A Header Res.SetHeader ("uportal-version", "uportal_rel-2-3-3"); if (Fatalerror) {RES.SENDREDIRECT ("Error / Fatal.htm");} catch (ioException e) { Excep Tionhelper.GenericTopHandler (Errors.bug, E);} return;} httpsession session = req.getations ();

IF (session! = null) {set requesttags = null; boolean request_verified = false;

if (! ALLOW_REPEATED_REQUESTS) {// obtain a tag table synchronized (session) {requestTags = (Set) session.getAttribute ( "uP_requestTags"); if (requestTags == null) {requestTags = Collections.synchronizedSet (new HashSet ()) Session.setttribute ("UP_REQUESTTAGS", Requesttags);}} // determine current tag upfilespec upfs = new upfilespec (req); string tag = upfs.getatagid ();

// see if the tag was registered if (tag! = null) {request_verified = (tag.equals (idempotent_url_tag) || requesttags.remove (tag));}

LogService.log (Logservice.debug ("PortalSessionManager :: doget (): request verified:" required_verified);

try {UserInstance userInstance = null; try {// Retrieve the user's UserInstance object userInstance = UserInstanceManager.getUserInstance (req);} catch (Exception e) {ExceptionHelper.genericTopHandler (Errors.bug, e); ExceptionHelper.generateErrorPage (res, e Return;}

// fire away if (ALLOW_REPEATED_REQUESTS) {userInstance.writeContent (new RequestParamWrapper (req, true), res);} else {// generate and register a new tag String newTag = Long.toHexString (randomGenerator.nextLong ()); LogService .log (logservice.debug, "PortalSessionManager :: doget (): generated new tag /" newtag "/" for the session " Req.getSession (false) .GetId ()); // no need to check for Duplicates :) We'd Have To Wait A Lifetime of a Universes for this Time Happen if (! Requesttags.add (newtag)) {logservice.log (logservice.Error, "PortalSessionManager :: doget (): a duplicate tag Has been ! generated Time's up ");!} userInstance.writeContent (new RequestParamWrapper (req, request_verified), new ResponseSubstitutionWrapper (res, INTERNAL_TAG_VALUE, newTag));}} catch (Exception e) { ExceptionHelper.GenericTopHandler (ERRORS.BUG, E); ExceptionHelper.generateErrorPage (RES, E); Return;}

} else {// throw new servletException ("session object is null!");

}

/ ** * Gets a URL associated with the named resource. * Call this to access files with paths relative to the * document root. Paths should begin with a "/". * @Param resource relative to the document root * @return a URL associated with the named resource or null if the URL is not accessible * @throws java.net.MalformedURLException * / public static URL getResourceAsURL (String resource) {// Make sure resource string starts with a "/" if (! resource .startswith ("/")) resource = "/" resource; URL URL = NULL;

Try {url = servletContext.getResource (resource);} catch (java.net.malformedurlexception murle) {// if The URL IS BAD, JUST RETURN NULL} Return URL;}

/ ** * Gets an input stream associated with the named resource. * Call this to access files with paths relative to the * document root. Paths should begin with a "/". * @Param resource relative to the document root * @return an input stream assosiated with the named resource * / public static java.io.InputStream getResourceAsStream (String resource) {// Make sure resource string starts with a "/" if (! resource.startsWith ( "/")) resource = " / " resource;

Return servletContext.getResourceceAsStream (resource);

}

转载请注明原文地址:https://www.9cbs.com/read-13700.html

New Post(0)