dimecres, 13 de juliol del 2011

Liferay Portal Server: avoiding use of extension. JAR and sample for Liferay 5.2.3

Hi!

Since I posted my set of entries called "Liferay Portal Server: avoiding use of extension" (1, 2 and 3), I've received a rush of visits so, it looks like there is some interest in Zeep 'oTron. So I decided to package it and upload some samples.

My first sample is for Liferay 5.2.3 (bundled with Tomcat 6). So, if you want to try it, just download the zeep-o-tron-liferay_5_2_3.jar, deploy it, start your Liferay Portal Server, and test the sample (zeep-o-tron_demo_hook.war).

I've already explained how to install Zeep O'Tron in another post, but I'll repeat so that you don't need to look for it:
  1. Copy zeep-o-tron-liferay_5_2_3.jar in LIFERAY_HOME/tomcat-6.0.18/webapps/ROOT/WEB-INF/lib
  2. Edit web.xml and locate the servlet named 'Main Servlet'. Then, in that servlet definition:
    • comment out the servlet-class tag
    • add you own servlet-class tag with 'com.blogspot.aigloss.hook.hotdeploy.servlet.HotdeployMainServlet' as value
    • add an init-param with 'configFactory' as param-name, and 'com.blogspot.aigloss.hook.hotdeploy.config.ModuleConfigFactory' as param value
    • now, the Main Servlet from your web.xml, shoul look like this:
      <servlet>
         <servlet-name>Main Servlet</servlet-name>
         <!--servlet-class>com.liferay.portal.servlet.MainServlet</servlet-class-->
         <servlet-class>com.blogspot.aigloss.hook.hotdeploy.servlet.HotdeployMainServlet</servlet-class>
         <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>
         </init-param>
         <!--zeep o'tron -->
         <init-param>
            <param-name>configFactory</param-name>
            <param-value>com.blogspot.aigloss.hook.hotdeploy.config.ModuleConfigFactory</param-value>
         </init-param>
         <!--   -->
         <init-param>
            <param-name>debug</param-name>
            <param-value>0</param-value>
         </init-param>
         <init-param>
            <param-name>detail</param-name>
            <param-value>0</param-value>
         </init-param>
         <load-on-startup>1</load-on-startup>
      </servlet>
  3. Edit your portal-ext.properties and add 'com.blogspot.aigloss.hook.hotdeploy.portal.HookHotdeployListener' as a new hot.deploy.listener. If you have'nt defined any, you can just add the following:
  4. hot.deploy.listeners=\ com.liferay.portal.deploy.hot.PluginPackageHotDeployListener,\ com.liferay.portal.deploy.hot.HookHotDeployListener,\ com.liferay.portal.deploy.hot.LayoutTemplateHotDeployListener,\ com.liferay.portal.deploy.hot.PortletHotDeployListener,\ com.liferay.portal.deploy.hot.ThemeHotDeployListener,\ com.liferay.portal.deploy.hot.ThemeLoaderHotDeployListener,\ com.liferay.portal.deploy.hot.MessagingHotDeployListener,\ com.blogspot.aigloss.hook.hotdeploy.portal.HookHotdeployListener
Ok! Zeep O'Tron is already installed. Now, let's test the sample.
Open your browser, login, and go to a blank page. Add the Calendar portlet.
Now create an event and look at the server logs; back to the browser, click the recently created event and check out its details. Back to the calendar main page, and delete the event. Take a look at the logs again...
Nothing special, uh?!

Ok, let's deploy the sample. Just leave it in LIFERAY_HOME/deploy and let Liferay do its work...
Now repeat what you did again:

  1. Create an event and take a look at the logs....you find a message like this: 'THE CONFIGURATION FOR THIS ACTION HAS BEEN MODIFIED BY ZEEP O'TRON!!!!!' . Of course the sample overrides the action 'com.liferay.portlet.calendar.action.EditEventAction' to output that log to the console...
  2. Now let's take a look at the event's details...can't see the details? That's it! The sample overrides the Tiles configuration called 'portlet.calendar.view_event' to output that message on the screen instead of the event details...
  3. Finally, go back, and delete the event. Check out the logs...see that message?! Yes! As you can read in the message, the hook has overriden the spring bean called 'com.liferay.portlet.calendar.service.CalEventLocalService.impl'
Of course, later versions of Liferay already allow you to override spring services, just remember I developed this for Liferay 5.1.2. By the way, you can take advantage of overriding Struts and Tiles configurations. Of course, if you can override, you can add! 

Last but not least, since all this has been made from a hook, there is no need to demonstrate that all the classes used to override Struts actions, ans Spring beans have been added to Liferay's classloader...so you can take advantage of this too.

Hope you like it!

You can find a version for Liferay 6 (tested in LF 6.0.6) here!

Cap comentari:

Publica un comentari a l'entrada