Issue Details (XML | Word | Printable)

Key: LEP-2297
Type: New Feature New Feature
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: SE Support
Reporter: Olaf Fricke
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
PUBLIC - Old Liferay Portal (Use Liferay Portal Standard Edition)

Custom servlets running in the ROOT context

Created: 06/Mar/07 02:35 AM   Updated: 09/Mar/07 10:25 AM
Return to search
Component/s: None
Affects Version/s: 4.2.1
Fix Version/s: 4.3.0

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive ServletDelegation.zip (3 kB)

Environment: Windows XP / Solaris, Liferay 4.2.0 Professional, Tomcat 5.5.17


 Description  « Hide
Liferay offers the possibility, to run a liferay servlet in the context of another web application. The class PortalServletWrapper does this trick. It is used for example by tunnel-web or cms-web.

Sometimes it is desirable to do the same trick the other way round: to let a custom servlet run in the context of the ROOT application. This allows for example the access to the same session. In fact, all custom portlets that are hot deployed into th eportal server are running in that way and can thus use some session attribute from the portal server (at least, if private-session-attributes is set to false in liferay-portal.xml).

I have created the classes PortalServletDelegationManager and PortalDelegateServlet to do that trick for servlets as well. The manager class will be running as servlet in the ROOT context. Its only purpose is to delegate matching requests to another servlet that is running in another context. In that servlet, getSession can be used to retrieve the session that is used by Liferay as well. It is important to put both classes into a place, where both the ROOT context and the application context uses the same instance (with respect to the classloader), because a static map is used. One such place is the common/classes folder of tomcat.

Both classes can be found in the attached archive.

The first class has to be configured in the web.xml of the ROOT application as servlet that listens for some context path (i.e. "delegate").
  <servlet>
    <servlet-name>DelegationManagerServlet</servlet-name>
    <servlet-class>de.hansemerkur.liferay.portal.servlet.PortalServletDelegationManager</servlet-class>
    <load-on-startup>0</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>DelegationManagerServlet</servlet-name>
    <url-pattern>/delegate/*</url-pattern>
  </servlet-mapping>

The second class has to be configured as servlet in the web.xml of some hot deploy portlet/servlet application. Two parameters are used to configure the delegation servlet: the first one defines the servlet class to that requests are delegated. The second (optional) parameter defines the sub context path for the delegation. If the second parameter is missing, the servlet name is used instead. In the given example, all requests to "/delegate/cognos" are delegated to the configured CognosServlet.
  <servlet>
    <servlet-name>cognos</servlet-name>
    <servlet-class>de.hansemerkur.liferay.portal.servlet.PortalDelegateServlet</servlet-class>
    <init-param>
      <param-name>servlet-class</param-name>
      <param-value>de.hansemerkur.mis2.report.servlet.CognosServlet</param-value>
    </init-param>
    <init-param>
      <param-name>sub-context</param-name>
      <param-value>cognos</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
  </servlet>


 All   Comments   Work Log   Change History   FishEye      Sort Order: Ascending order - Click to sort in descending order
Olaf Fricke made changes - 06/Mar/07 02:36 AM
Field Original Value New Value
Attachment ServletDelegation.zip [ 12012 ]
Brian Chan added a comment - 09/Mar/07 10:25 AM
Thanks Olaf.

Brian Chan made changes - 09/Mar/07 10:25 AM
Status Open [ 1 ] Closed [ 6 ]
Fix Version/s 4.3.0 [ 10170 ]
Resolution Fixed [ 1 ]
Michael Young made changes - 04/Feb/08 02:31 PM
Workflow jira [ 14796 ] Liferay [ 23157 ]
Michael Young made changes - 05/Feb/08 11:48 AM
Workflow Liferay [ 23157 ] Liferay Workflow [ 31401 ]
Michael Young made changes - 06/Feb/08 03:42 PM
Workflow Liferay Workflow [ 31401 ] Liferay [ 39841 ]
Michael Young made changes - 14/Feb/08 10:10 AM
Workflow Liferay [ 39841 ] Liferay Workflow [ 48323 ]
Ivan Cheung made changes - 31/Mar/08 10:41 PM
Workflow Liferay Workflow [ 48323 ] Liferay Workflow - version 1.1 [ 57146 ]
Ivan Cheung made changes - 31/Mar/08 11:18 PM
Workflow Liferay Workflow - version 1.1 [ 57146 ] Liferay Workflow [ 66060 ]
Ivan Cheung made changes - 02/Apr/08 07:39 PM
Workflow Liferay Workflow [ 66060 ] Liferay Workflow - version 1.1 [ 74987 ]
Michael Young made changes - 07/Oct/08 02:07 PM
Workflow Liferay Workflow - version 1.1 [ 74987 ] Liferay Workflow - version 1.2 [ 88267 ]
Michael Young made changes - 07/Oct/08 03:02 PM
Workflow Liferay Workflow - version 1.2 [ 88267 ] Liferay Workflow - version 1.3 [ 100046 ]
Ivan Cheung made changes - 07/Oct/08 10:47 PM
Workflow Liferay Workflow - version 1.3 [ 100046 ] Liferay Workflow - version 1.4 [ 111840 ]
Ivan Cheung made changes - 08/Oct/08 02:58 AM
Workflow Liferay Workflow - version 1.4 [ 111840 ] Liferay Workflow - version 1.5 [ 123630 ]
Michael Young made changes - 18/Nov/08 06:44 PM
Workflow Liferay Workflow - version 1.5 [ 123630 ] Liferay Workflow - version 1.6 [ 137051 ]
Michael Young made changes - 09/Dec/08 11:59 AM
Workflow Liferay Workflow - version 1.6 [ 137051 ] Liferay Workflow - version 1.7 [ 150698 ]
Michael Young made changes - 09/Dec/08 03:08 PM
Workflow Liferay Workflow - version 1.7 [ 150698 ] Liferay Workflow - version 1.8 [ 163923 ]
Michael Han made changes - 19/Sep/09 07:26 AM
Workflow Liferay Workflow - version 1.8 [ 163923 ] Greenhopper [ 183078 ]
Michael Han made changes - 10/Oct/09 04:41 PM
Workflow Greenhopper [ 183078 ] Liferay Workflow 2.2 [ 213258 ]
This list of changesets may be incomplete, as errors occured retrieving changesets from the following repositories:

       Repository plugins on http://svn.liferay.com.false/ failed: svn.liferay.com.false
       Repository portal on http://svn.liferay.com.false/ failed: svn.liferay.com.false