| Last Update: | March 20, 2003 |
| Status: | Production |
| Version: | PDK Release 2, (9.0.2 and later) |
When you have successfully deployed and registered the PDK samples, you can build portlets from existing Java, JSP, and Servlet applications. To deploy Java components in OC4J (based on J2EE), you need to package your classes, libraries, and any additional files needed to execute your component and deploy your .ear file to OC4J. Oracle9i JDeveloper simplifies this process by automatically packaging and deploying your component.
There are a few basic steps to build a Java portlet based on an existing application:
Create or use an existing Java, JSP, or Servlet already deployed to OC4J.
Include the necessary PDK libraries in your classpath.
Update the file web.xml to point to the PDK Provider Adapter.
Update the sample provider definition file with your component information.
Point the PDK Provider Adapter to your provider definition file.
Package and deploy your portlet.
This article describes how to manually use Oracle9i JDeveloper and the PDK to build Java portlets from existing Java components. Using Oracle9i JDeveloper eliminates the need to manually package and deploy your portlets to OC4J. In this example we use a ManagedRenderer called RenderManager to easily render an existing Java Servlet (this is used in the provider.xml). For more information on Renderers, or the PDK Framework, review the article A Primer on the PDK Provider Framework.
This article is based on an existing Java Servlet. To use an existing JSP or Java class instead, review Other Java Components later in this article.
Note: This article describes how to manually build portlets using Oracle9i JDeveloper, you can also review Building Porltets Using the Java Portlet Wizard which describes how to use build, test, and deploy portlets using a wizard-based declarative UI.
You have already installed the samples downloaded with the PDK and understand the steps required to display a Java portlet on a portal page. For more information on installing the sample, please review the article Installing the PDK Framework and Samples.
You are using OC4J to execute and display Servlets used by the PDK.
You are already familiar with Oracle9i JDeveloper and know how to build and deploy Java components using Oracle9i JDeveloper.
You can use an existing Servlet or the sample provided below. The sample is a standard "HelloWorld" Servlet and it does not require special Oracle9iAS Portal or PDK imports or references. This article assumes you are using this sample.
Note: If you are using your own compiled Servlet class that has already been deployed to OC4J, please skip to the Updating Your Project for the PDK section and make any necessary name adjustments.
Enter the following portlet code in a project using Oracle9i JDeveloper. Provide the name HelloServlet.java.
import javax.servlet.*;
Import javax.servlet.http.*;
public class Time extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
doGet(req, res);
}
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
PrintWriter out = res.getWriter();
out.println("Welcome to My Java Component!");
}
}
Right mouse click on your current project.
Select Project Settings.
Click Libraries under Development and move Servlet Runtime to the selected classes.
Note: Your portlet code must compile without any errors to be successfully deployed.
In the Navigator, under Connection, right mouse click on Application Server.
In the popup menu, click New Connection, and follow the steps for the Connection Wizard. Provide the name and type of connection:
Enter the administrator username and password of the OC4J instance where you are deploying your Java component. Check the 'Deploy Password' checkbox to store the username and password.
Enter the URL of the host running OC4J. This is based on Oracle Remote Method Invocation (ORMI) protocol, so the URL should resemble:
ormi://hostname:port#
Enter the directory where the admin.jar is located for OC4J.
Test your connection. You should receive a 'Success' status. If you did not receive this status, go back and check your settings.
Create a Deployment Profile.
Right mouse click on your project and select New...
Under the Deployment Profiles Category, select J2EE Web Module (WAR file).
Select he name and the location of the deployment profile, or leave the default.
This creates two entries under your project, a deployment profile and the file web.xml.
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<!-- A demo servlet, add servlets below -->
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
</web-app>
Exit status of Oracle9iAS admin tool: 0-----Deployment finished. -----
You should now be able to access you Java component with the following URL:
http://host.domain:port/<application>/servlet/HelloServlet
Now that the existing Java component is deployed using Oracle9i JDeveloper, you can update your project quickly and easily to display it as a portlet in Oracle9iAS Portal. These are the steps involved:
Add the PDK libraries required
Update web.xml
Enter information in the provider definition and point the PDK Provider Adapter to the provider definition.
Right mouse click on your project and select Project Settings.
Select the PDK libraries to include in your project. You may need to create the libraries first:
You need to include one or more of these libraries upon deployment. If your OC4J instance is the same one being used for Oracle9iAS Portal, then you should only need pdkjava.jar, otherwise include all of the libraries.
Right mouse click on the deployment profile and select Settings.
Check the libraries you want to include upon deployment.
Update web.xml so that OC4J calls the PDK Provider Adapter. This web.xml enables Oracle9iAS Portal to communicate directly with the PDK Provider Adapter. The Adapter uses the XML provider definition to render your Java component as a portlet.
<?xml version = '1.0' encoding = 'UTF-8'?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<display-name>Web-App1</display-name>
<description>Web-App1 Sue</description>
<servlet>
<servlet-name>SOAPServlet</servlet-name>
<display-name>SOAPServlet</display-name>
<description>Extended Portal SOAP Server</description>
<servlet-class>oracle.webdb.provider.v2.adapter.SOAPServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SOAPServlet</servlet-name>
<url-pattern>/providers</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SOAPServlet</servlet-name>
<url-pattern>/providers/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>50</session-timeout>
</session-config>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
</web-app>
Use a text editor, save the following information as "provider.xml" in the directory: %OC4J_HOME%\applications\<application>\<application>\WEB-INF\providers\myportlet\.
For example: C:\9iAS\Apache\oc4j\j2ee\home\applications\myservlet\myservlet\WEB-INF\providers\myportlet
The names of the directories \providers\myportlet is not important as long as it matches the information in the _default.properties file (see Step 7 below). Update the information in bold. The <showPage> tag must point to your Java Servlet.
<?Xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?providerDefinition version="3.1"?>
<provider class="oracle.portal.provider.v2.DefaultProviderDefinition">
<session>true</session>
<useOldStyleHeaders>false</useOldStyleHeaders>
<portlet class="oracle.portal.provider.v2.DefaultPortletDefinition">
<id>1</id>
<name>MyServletPortlet</name>
<title>My Servlet Portlet</title>
<description>This is my Servlet Portlet</description>
<timeout>30</timeout>
<timeoutMessage>My Servlet Portlet Timed Out</timeoutMessage>
<acceptContentType>text/html</acceptContentType>
<showEdit>false</showEdit>
<showEditToPublic>false</showEditToPublic>
<showEditDefault>false</showEditDefault>
<showPreview>false</showPreview>
<showDetails>false</showDetails>
<hasHelp>false</hasHelp>
<hasAbout>false</hasAbout>
<renderer class="oracle.portal.provider.v2.render.RenderManager">
<contentType>text/html</contentType>
<showPage>/servlet/HelloServlet</showPage>
</renderer>
</portlet>
</provider>
Create a directory called deployment under %OC4J_HOME%\applications\<application>\<application>\WEB-INF\.
For example: C:\9iAS\Apache\oc4j\j2ee\home\applications\myservlet\myservlet\WEB-INF\deployment
Use a text editor to save the following information as "_default.properties" in the deployment directory. Make sure definition specifies the location of your provider.xml file.
serviceClass=oracle.webdb.provider.v2.adapter.soapV1.ProviderAdapter
loaderClass=oracle.portal.provider.v2.http.DefaultProviderLoader
showTestPage=true
definition=providers/myportlet/provider.xml
autoReload=true
Right mouse click on your deployment profile and deploy your project.
http://host.domain/<application>/providers
web.xml provides a URL pattern to /providers/* that allows you to use the above URL instead of the standard: http://host.domain/<application>/servlet/SOAPServlet. Use the URL above to register your provider.
You should see a successful test page when you access the URL in Step 9.
Once you have successfully tested your new provider, register the provider with Oracle9iAS Portal:
Click Builder in the top right hand corner of the Oracle9iAS Portal Home Page, then click Register a Portlet Provider in the Provider portlet.
Enter the following provider information:
Name: MyHelloServletProvider.
Display Name: My Hello Servlet Provider.
Timeout: 100.
Timeout Message: My Hello Servlet Provider Timed Out.
Implementation Style: Web.
Provider Login Frequency: Never.
http://{host}:{port}/<application>/providers (same as used above).
When you have registered your provider you can add your new Java portlet to a page. Please refer to the Oracle9iAS Portal online documentation for more information. You have now successfully built your own Java portlet using Oracle9i JDeveloper and an existing Java component.
You may want to build a portlet from an existing JSP or Java application. Most of the steps are the same, however updates to your XML provider definition file depend on the Java component. This is illustrated in the examples below.
Below is an XML provider definition for an existing JSP application called "myjspportlet.jsp". The differences within the provider definition from a servlet to a JSP are noted in bold below. The steps to create a Java portlet from a JSP application are:
Place your JSP is a directory under your .war root such as %OC4J_HOME%\applications\<application>\<application>\htdocs\myjsp. Point to this location from the XML provider definition.
Create an XML provider definition as demonstrated below.
Finally, register the Provider and display your portlet on a page as described in Registering Your Provider.
<?Xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?providerDefinition version="3.1"?>
<provider class="oracle.portal.provider.v2.DefaultProviderDefinition">
<session>true</session>
<portlet class="oracle.portal.provider.v2.DefaultPortletDefinition">
<id>3</id>
<name>MyJSPPortlet</name>
<title>My JSP Portlet</title>
<shortTitle>JSPPortlet</shortTitle>
<description>This is my JSP Portlet</description>
<timeout>10000</timeout>
<timeoutMessage>JSP Portlet timed out</timeoutMessage>
<showEdit>false</showEdit>
<showEditDefault>false</showEditDefault>
<showPreview>false</showPreview>
<showDetails>false</showDetails>
<hasHelp>false</hasHelp>
<hasAbout>false</hasAbout>
<acceptContentType>text/html</acceptContentType>
<renderer class="oracle.portal.provider.v2.render.RenderManager">
<contentType>text/html</contentType>
<showPage>/htdocs/myjsp/myjspportlet.jsp</showPage>
</renderer>
</portlet>
</provider>
Take a look at any of the JSP portlets in the PDK Framework Samples provider.xml for more information on using the different ManagedRenderers.
Below is an XML provider definition for an existing Java application called "MyJavaApp.class". The differences within the provider definition from a servlet to a Java application are noted in bold below. The steps to create a Java portlet from a Java application are:
Place your Java class in your OC4J classpath.
Update your project in JDeveloper as described in Updating Your Project For The PDK.
Finally, register the Provider and display your portlet on a page as described in Registering Your Provider.
<?Xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?providerDefinition version="3.1"?>
<provider class="oracle.portal.provider.v2.DefaultProviderDefinition">
<session>true</session>
<portlet class="oracle.portal.provider.v2.DefaultPortletDefinition">
<id>3</id>
<name>MyJavaPortlet</name>
<title>My Java Portlet</title>
<shortTitle>JAVAPortlet</shortTitle>
<description>This is my Java Portlet</description>
<timeout>10000</timeout>
<timeoutMessage>Java Portlet timed out</timeoutMessage>
<showEdit>false</showEdit>
<showEditDefault>false</showEditDefault>
<showPreview>false</showPreview>
<showDetails>false</showDetails>
<hasHelp>false</hasHelp>
<hasAbout>false</hasAbout>
<acceptContentType>text/html</acceptContentType>
<renderer class="oracle.portal.provider.v2.render.RenderManager">
<contentType>text/html</contentType>
<showPage class="oracle.portal.provider.v2.render.http.JavaRenderer"/>
<className>MyJavaApp</className>
<renderMethod>methodName</renderMethod>
</showPage></renderer>
</portlet>
</provider>
| Revision History: |
|
| Oracle Corporation World Headquarters 500 Oracle Parkway Redwood Shores, CA 94065, USA http://www.oracle.com/ |
Worldwide Inquiries: 1-800-ORACLE1 Fax 650.506.7200 |
Copyright and Corporate Info |