Portlet - Apache Pluto - Hello World Portlet

This is document just for documenting the steps for the helloworld sample which i did for learning pluto.

It takes two night for me succesfully deployed a helloworld in apache pluto portal server, i learned lots of thing in recently two night in learning using pluto even how the portlet should be configured in order to get it working in apache pluto.

so, below the steps for deploying a helloworld in apache pluto.

1. we should have successfully installed apache pluto open source portal server in our local.

2. create a helloword portleot application and its strcuture like below:

\---ch1_HelloWorld
    |   build-pluto.xml
    |   build.properties
    +---lib
    |       junit-4.7.jar
    |       portlet-api_2.0_spec-1.0.jar
    +---src
    |   \---chapter01
    |       \---code
    |           \---listing
    |                   HelloWorldPortlet.java
    \---WEB-INF
        |   portlet.xml
        |   web.xml
        \---jsp
        \---lib
 

3. let's start for each files mentioned in above structure

3.1 file chapter01.code.listing.HelloWorldPortlet

package chapter01.code.listing;

import java.io.IOException;
import java.io.PrintWriter;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

public class HelloWorldPortlet extends GenericPortlet {
	protected void doEdit(RenderRequest request, RenderResponse response)throws PortletException, IOException {
		response.setContentType("text/html");
		PrintWriter writer = new PrintWriter(response.getWriter());
		writer.println("You're now in Edit mode.");
	}

	protected void doHelp(RenderRequest request, RenderResponse response)throws PortletException, IOException {
		response.setContentType("text/html");
		PrintWriter writer = new PrintWriter(response.getWriter());
		writer.println("You're now in Help mode.");
	}

	protected void doView(RenderRequest request, RenderResponse response)throws PortletException, IOException {
		response.setContentType("text/html");
		PrintWriter writer = new PrintWriter(response.getWriter());
		writer.println("Hello world! You're in View mode.");
	}
}
 

3.2 file web.xml

<?xml version="1.0"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
	version="2.5">
	<display-name>Hello World portlet application</display-name>
	<servlet>
		<servlet-name>HelloWorldPortlet</servlet-name>
		<servlet-class>
			org.apache.pluto.container.driver.PortletServlet
		</servlet-class>
		<init-param>
			<param-name>portlet-name</param-name>
			<param-value>HelloWorldPortlet</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>VIEW</portlet-mode>
			<portlet-mode>EDIT</portlet-mode>
			<portlet-mode>HELP</portlet-mode>
		</supports>
		<portlet-info>
			<title>Hello, This is my first portlet application</title>
		</portlet-info>
	</servlet>
	<servlet-mapping>
		<servlet-name>HelloWorldPortlet</servlet-name>
		<url-pattern>/PlutoInvoker/HelloWorldPortlet</url-pattern>
	</servlet-mapping>
</web-app>

3.3 file portlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<portlet-app xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
	xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd">
	<portlet>
		<portlet-name>HelloWorldPortlet</portlet-name>
		<display-name>Hello World Portlet</display-name>
		<portlet-class>chapter01.code.listing.HelloWorldPortlet</portlet-class>
		<supports>
			<mime-type>text/html</mime-type>
			<portlet-mode>VIEW</portlet-mode>
			<portlet-mode>EDIT</portlet-mode>
			<portlet-mode>HELP</portlet-mode>
		</supports>
		<portlet-info>
			<title>Hello, This is my first portlet application</title>
		</portlet-info>
	</portlet>
</portlet-app>
 

3.4 file build.properties

pluto.portal.home=G:/Environment/Portal/pluto-2.0.3
 

3.5 file build-pluto.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="HelloWorldPortlet" default="rebuild" basedir=".">
	
	<property file="build.properties" />
	<property environment="env"/>
	
	<property name="AppName" value="HelloWorldPortlet"/>
	<property name="debug" value="on"/>
	<property name="dir.build" value="pluto_build"/>
	<property name="dir.src" value="src"/>
	<property name="dir.classes" value="pluto_classes"/>
	<property name="dir.lib" value="pluto_lib"/>
	<property name="dir.war" value="${basedir}/"/>
	<property name="dir.war.lib" value="${dir.war}/WEB-INF/lib"/>
	<property name="dir.driver" value="pluto_driver"/>
	<property name="portlet.api" value="portlet-api_2.0_spec-1.0.jar"/>
	<property name="pluto.home" value="${pluto.portal.home}"/>
	
	<target name="build" depends="build.war"/>
	
	<target name="rebuild" depends="clean,build"/>
	
	<target name="init">
		<mkdir dir="${dir.build}"/>
		<mkdir dir="${dir.classes}"/>
		<mkdir dir="${dir.lib}"/>
		<mkdir dir="${dir.driver}"/>
		<mkdir dir="${dir.war.lib}"/>
		<copy file="${pluto.home}/api/target/${portlet.api}" todir="${dir.lib}" failonerror="no"/>
	</target>
	
	<target name="env" depends="init">
		<echo message="Portlet Application: ${AppName} "/>
	</target>
	
	<target name="compile" depends="env">
		<javac srcdir="${dir.src}" destdir="${dir.classes}" includes="**/*.java" debug="${debug}">
			<classpath>
				<fileset dir="${dir.war.lib}">
					<include name="**/*.jar"/>
				</fileset>
				<fileset dir="${dir.lib}">
					<include name="**/*.jar"/>
				</fileset>
			</classpath>
		</javac>
	</target>
	
	<target name="build.jar" depends="compile">
		<jar jarfile="${dir.classes}/${AppName}.jar" compress="true">
			<fileset dir="${dir.classes}">
				<exclude name="*.jar"/>
			</fileset>
		</jar>
	</target>
	
	<target name="build.war" depends="build.jar">
		<jar jarfile="${dir.driver}/${AppName}.war">
			<fileset dir="${dir.war}/">
				<include name="**/WEB-INF/**"/>
			</fileset>
			<zipfileset dir="${dir.classes}" prefix="WEB-INF/lib">
				<include name="*.jar"/>
			</zipfileset>
		</jar>
	</target>
	
	<target name="clean">
		<delete dir="${dir.classes}" failonerror="false" />
		<delete dir="${dir.driver}" failonerror="false"/>
	</target>
	
</project>

4. after we have those code in the portlet project, we can successfully generate one portlet war application file HelloWorldPortlet.war.

5. we have to copy the HelloWorldPortlet.war file into <pluto_home>\PlutoDomain directory.

6. next, we have to create a file 'hello.xml' for deploy this portlet application under <pluto_home>\conf\Catalina\localhost

hello.xml
<Context path="hello" docBase="../PlutoDomain/HelloWorldPortlet.war" crossContext="true"></Context>
 

7. then, we have to configure the HelloWorldPortlet in pluto-portal-driver-config.xml in order to get it shown on the pluto portlet page; 

     file <pluto-portal-driver-config.xml> path: <pluto_home>\webapps\pluto\WEB-INF\pluto-portal-driver-config.xm

<?xml version="1.0" encoding="UTF-8"?>
<pluto-portal-driver
    xmlns="http://portals.apache.org/pluto/xsd/pluto-portal-driver-config.xsd"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://portals.apache.org/pluto/xsd/pluto-portal-driver-config.xsd
                        http://portals.apache.org/pluto/pluto-portal/2.0/pluto-portal-driver-config.xsd"
    version="1.1">
  <portal-name>pluto-portal-driver</portal-name>
  <portal-version>2.0.3</portal-version>
  <container-name>Pluto Portal Driver</container-name>
  <supports>
    <portlet-mode>view</portlet-mode>
    <portlet-mode>edit</portlet-mode>
    <portlet-mode>help</portlet-mode>
    <portlet-mode>config</portlet-mode>
    <window-state>normal</window-state>
    <window-state>maximized</window-state>
    <window-state>minimized</window-state>
  </supports>

   <render-config default="About Apache Pluto">
    <page name="About Apache Pluto" uri="/WEB-INF/themes/pluto-default-theme.jsp">
      <portlet context="/pluto" name="AboutPortlet"/>
      <portlet context="/testsuite" name="TestPortlet1"/>
      <portlet context="/hello" name="HelloWorldPortlet"/>
    </page>
    <page name="Test Page" uri="/WEB-INF/themes/pluto-default-theme.jsp">
      <portlet context="/testsuite" name="TestPortlet1"/>
      <portlet context="/testsuite" name="TestPortlet2"/>
      <portlet context="/hello" name="HelloWorldPortlet"/>
    </page>
    <page name="JSR 286 Tests" uri="/WEB-INF/themes/pluto-default-theme.jsp">
      <portlet context="/testsuite" name="286TestPortlet"/>
      <portlet context="/testsuite" name="286TestCompanionPortlet"/>
      <portlet context="/hello" name="HelloWorldPortlet"/>
    </page>
    <page name="Pluto Admin" uri="/WEB-INF/themes/pluto-default-theme.jsp">
      <portlet context="/pluto" name="PlutoPageAdmin"/>
      <portlet context="/pluto" name="AboutPortlet"/>
      <portlet context="/pluto" name="PlutoPageAdmin"/>
      <portlet context="/hello" name="HelloWorldPortlet"/>
    </page>
    <page name="Sample Portals" uri="/WEB-INF/themes/pluto-default-theme.jsp">
      <portlet context="/hello" name="HelloWorldPortlet"/>
    </page>
  </render-config>
</pluto-portal-driver>
 

8. after we done all above steps, then, start the pluto portal server, the helloworld portlet application will looks like below:

猜你喜欢

转载自houtao.iteye.com/blog/1766562