![]() |
Portal J2EE Sample Poll Application |
Portal J2EE Sample Poll Application
This document describes how to utilize the Portal J2EE sample Poll application in conjunction with Sun ONE Application Server version 7.
This sample application document contains the following sections:
Overview
The Poll sample is a simple application that demonstrates a custom Portal Server JSP provider that access a stateless session EJB which allows the portal user to vote on a poll question. Starting with the Portal 6.1, custom portal providers can gain access to J2EE features such as JNDI, EJB, JDBC and JMS that are only available in J2EE containers. This allows Portal Server to provide content generated from any J2EE components and resources that are made available by the underlying J2EE compliant platform.This document assumes that the Portal Server 6.1 release is already deployed on Sun ONE Application Server 7.0 and that you have selected the default installation options with the sample desktop. You must also have superuser(root) privileges for the system where Portal Server is deployed.
A snapshot of the sample portal desktop with the poll sample is shown below. Note the channel titled "J2EE Sample - Poll" displays the current poll question.
![]()
Once the user has voted on the poll, the vote button in the channel will be changed to "Change Vote" , from then on till the poll is changed the user can only change the previous vote and this prevents multiple vote from the same user. The channel looks like the following:
![]()
The user can view the results either by clicking the "View Results" button or the results page is automatically displayed once the user votes. The desktop screen shot is given below
![]()
- Install Portal Server 6.1 or above release on Sun ONE Application Server 7.0. Make sure to install the sample portal since this sample depends on the sample desktop.
- Setup your system to leverage the Sun ONE Application Server 7.0 development environment. This includes setting the PATH environment to include the following directory:
<app_server_base_dir>/bin
- Install/Unpack Portal J2EE samples if not already done so. Navigate to the deployment root directory for Sun ONE Application Server 7.0 as follows:
cd <portalsample_basedir>/j2eesample/deploy/s1as
- Edit the common.properties file and review the default value for each property. The default property values are set according to the default installation options for Portal Server 6.2 release on Sun ONE Application Server. A description of each property and their default values are listed in the following table:
Property Description Default Value com.sun.aas.javaRoot The JDK directory. For default Sun ONE application server v7.0, this is /usr/j2se. However, Portal Server MAS installation will install JDK 1.4.1_01 and make modifications to the application server's configuration file to use this jdk. /usr/java_1.4.1_01 admin.host This is the hostname where the Sun ONE application server v7.0 admin server is running.
com.sun.aas.imqLib This is the directory where Sun ONE application server v7.0 finds the implementation of JMS provider. /usr/share/lib/imq admin.port This is the port number where the Sun ONE application server v7.0 admin server is listening to 4848 com.sun.aas.installRoot The base directory where Sun ONE application server v7.0 is installed into /opt/SUNWappserver7 admin.user The user id of the administrator account for the Sun ONE application server v7.0 admin server admin sunone.instance The server instance name where portal server is deployed server1 com.sun.aas.webServicesLib The directory where web services library files reside /usr/share/lib com.sun.aas.pointbaseRoot The base directory where pointbase is installed into /opt/SUNWappserver7/pointbase com.sun.dsame.installRoot
The base directory where Identity Server is installed into
/opt/SUNWam
com.sun.portal.installRoot
The base directory where Portal Server is installed into
/opt/SUNWps
com.sun.portal.deployuri The deployment uri used when deploying portal server on Sun ONE application server v7.0 /portal com.sun.portal.websrcRoot The portal server open WAR file root directory
/opt/SUNWps/web-src com.sun.portal.provider.classBaseDir The base directory where portal provider class files are deployed /etc/opt/SUNWps/desktop/classes com.sun.portal.templateBaseDir The base directory where provider templates and JSP are deployed /etc/opt/SUNWps/desktop com.sun.portal.desktopType The portal server deployed desktop type default sunone.instance.port The port number where the Sun ONE application server instance is listening to 80
- Navigate to the poll sample directory for Sun ONE Application Server 7.0 as follows:
cd <portalsample_basedir>/j2eesample/deploy/s1as/poll
- Compile the stateless poll EJB and the custom portal provider by giving the following command:
asant compile
- Package and create the EJB jar file by giving the following command:
asant jar
- Deploy the stateless poll EJB jar to the application server by giving the following command:
asant deployejb
- Deploy the custom portal JSP provider class file and its JSP file to the proper directories using the following command: (note that this requires super user privilege)
asant deployprovider
- Setup the database to store the poll question and the votes.
Make sure you have pointbase installed in your system. For more details please refer to appserver documentation related to pointbase.
cd <appserver_install_dir>/pointbase/server
- Start the database.
./StartServer.sh
- Move into the the client tools directory.
cd <appserver_install_dir>/pointbase/client_tools
Start the client console
./PB_console.sh
Create a new database named portal using the console.
![]()
- Create poll schema and tables and populate the tables with the data by running poll_table_data.sql (located at <portalsample_basedir>/j2eesample/deploy/s1as/poll) from the input findow. Open the file by selection File -> Open which will automatically fill the input window with the sql like the image show below.
![]()
- Execute the sql by selecting SQL -> Execute ALL.
- Create a new database connection pool by the name PollDSPool by executing the following commands:
- cd <portalsample_basedir>/j2eesample/deploy/s1as/poll
- asant create-jdbc-connection-pool_common (Make sure that you change the db.pwd entry in the build.xml file from the default value)
- Create a new jdbc resource to use PollDSPool by executing the following commands:
- asant create-jdbc-resource_common
- Make the necessary modifications to the portal server web.xml and sun-web.xml files to include references to the Poll EJB. These modifications should be made under the portal server open war file source directory. Modifications made in the portal server open war file source directory are guarantee to be effective even when a change such as a patch is applied to the portal server in the future. Locate the portal server open war file source directory and change directory to it. The default portal server open war file source directory is /opt/SUNWps/web-src. This may change depending on the specific directory where portal server is installed into. (note that this requires super user privilege)
cd /opt/SUNWps/web-src
- Create a new xml file named PollSample.xml under the subdirectory of WEB-INF/xml by copying an existing xml file in that directory and removing all the lines between the <web-app> and </web-app> tags in the PollSample.xml file. Append the following lines to PollSample.xml between the <web-app> and </web-app> tags and save the file:
<resource-ref>
<description>Poll Channel</description>
<res-ref-name>jdbc/poll</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<ejb-ref>
<ejb-ref-name>ejb/poll</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<home>com.sun.portal.sample.j2ee.poll.ejb.PollHome</home>
<remote>com.sun.portal.sample.j2ee.poll.ejb.Poll</remote>
</ejb-ref>
- Edit the sun-web.xml under the subdirectory of WEB-INF to append the following entries at the end of the file.
<resource-ref>
<res-ref-name>jdbc/poll</res-ref-name>
<jndi-name>jdbc/poll</jndi-name>
</resource-ref>
<ejb-ref>
<ejb-ref-name>ejb/poll</ejb-ref-name>
<jndi-name>ejb/poll</jndi-name>
</ejb-ref>
- Copy the stateless EJB poll client jar file, PollClient.jar ,to WEB-INF/lib inside the portal open war file source directory. The PollClient.jar file is generated by the application server as a result of the Poll EJB deployment. You can normally find this jar file at /var/opt/SUNWappserver7/domains/domain1/server1/applications/j2ee-modules/Poll_1 assuming the default application server installation.
- Copy the orange.gif file used by the poll result page to the images subdirectory inside the portal open war file source directory. orange.gif will be in the aforementioned directory.
- Redeploy the portal server by running the following command:
asant redeploy_portal_war
- Login to the appserver admin console and select server1 on the left pane and apply the new changes by clicking on the "Apply Changes" button on the right pane.
- Restart the application server.
asadmin stop-appserv
asadmin start-appserv
- Login to the Portal Server Admin Console and select the "Service Management" view at the top pane. Click the property icon next to "Desktop Service" in the left pane. Click "Edit XML" and append the content in the <portalsample_basedir>/j2eesample/src/com/sun/portal/sample/j2ee/poll/dp-PollProvider.xml into the textarea. This will make the provider available for use by a channel.
- In the Portal Server Admin Console, select the "Identity Management" view at the top pane. Select "Service" in the pulldown in the left pane. Click on the property next to "Desktop Service". Click on "Channel and Container Management" in the content. Under the channel section, create a new channel base on the "PollProvider" and name it "Poll". Save the channel. Under the container channels section, edit the "MyFrontPageTabPanelContainer" container and move the "Poll" channel to the available and selected channel list of the container. Save the changes.
- Login to portal server as a regular desktop user and bring up the desktop. You should see a channel named "Portal J2EE Sample -Poll" in the front page.
- Make certain that values in the common.properties file are set correctly to reflect your Portal Server installation on Sun ONE Application Server installation.
- You need to have superuser privilege in order to execute certain commands in the step by step guide.
- If you encounter problems when running the application, review the log files at <install-dir>/domains/domain1/<server-instance>/logs/server.log to learn what went wrong.
- The application admin console should show a Poll EJB module after the EJB jar file has been successfully deployed.
Copyright © 2002 Sun Microsystems, Inc. All rights reserved.