Ensemble Pagelet Development

IDK Quickstart: Hello World Pagelet - Java

This simplified Hello World pagelet example displays settings and content from a remote application in an AquaLogic Ensemble pagelet. This page provides instructions and sample code for Java developers.

Note: This example assumes you have installed the AquaLogic Interaction Development Kit (IDK) version 6.0. For details on installing the IDK, see the IDK Product Documentation.  

Step 1: Set Up a Custom IDK Project - Eclipse

The instructions for setting up a new project are different depending on whether or not you have WTP installed.

Eclipse with WTP

  1. Open Eclipse and click File | New | Other... | Web | Dynamic Web Project.

  2. For the Project Name, enter "idkProxy".  

  3. Choose a Target Runtime from the drop-down list. If you have not previously configured a server runtime, click New... to configure your Tomcat setup.  

  4. Click Finish to complete the Dynamic Web Project wizard.

  5. Import the IDK Web project template:

    1. Right-click the project in the Project Explorer and click Import | General | File System.

    2. To define the From directory field, navigate to the IDK root directory and select the \devkit\WEB-INF folder.

    3. Change the Into folder field to idkProxy/WebContent/WEB-INF.

    4. Click Finish.

Note: The Eclipse Web project view hides the imported JARs stored in WEB-INF/lib and puts those files under ./Java Resources/src/Libraries/Web App Libraries.

Eclipse Stand-Alone (without WTP)

  1. Open Eclipse and click File | New| Project. Click Next.

  2. For the Project Name, enter "idkProxy". Click Next and Finish.

  3. In the Package Explorer in Eclipse, right-click on the new project and click Properties | Java Build Path | Libraries | Add External Jars.

  4. Select the *.jar files from the IDK installation directory under the idk\6.0\devkit\java\WEB-INF\lib directory. Click OK.

Step 2: Create a Pagelet (.jsp)

In the new idkProxy project, create a new JSP page for the pagelet (pagelet.jsp).

The pagelet code shown below instantiates the IDK and uses the IProxyContext interface to retrieve IProxyRequest and IProxyUser objects to access information about the user and the settings associated with the pagelet.

Note: There is no need to include html, head and body tags; the display is handled by the Consumer resource.

 

<%@ page language="java" import="com.bea.alui.proxy.*" %>

<%

String Att1 = "no setting";
String Att2 = "no setting";
String sessionVariable = "no setting";

//get the idk
IProxyContext proxyContext = ProxyContextFactory.getInstance().createProxyContext(request, response);
IProxyRequest proxyRequest = proxyContext.getProxyRequest();

IProxyUser proxyUser = proxyRequest.getUser();

String userName = proxyUser.getUserName();
int userID = proxyUser.getUserID();

Att1 = proxyRequest.getSetting("Att1");
Att2 = proxyRequest.getSetting("Att2");
sessionVariable = proxyRequest.getSetting("sessionVar");

b
yte[] payload = proxyRequest.getPayload().getText();
String payloadStr = new String(payload);

%>

<p>User name: <%=userName%><br/>
User ID:
<%=userID%><br/>
Attribute 1:
<%=Att1%><br/>
Attribute 2:
<%=Att2%><br/>
Session variable:
<%=sessionVariable%><br/>

P
ayload: <textarea name=xml cols=80 rows=6> <%=payloadStr%> </textarea>

</p> 

 

Step 3: Deploy and Debug Your Custom Project

The instructions for debugging are also different depending on whether or not you have WTP installed.

Eclipse with WTP

These instructions use Tomcat as an example.

  1. Define the server in Eclipse:

    1. Click File | New | Other | Server | Server and click Next.

    2. Select the server type as Tomcat v5.0 and click Next.

    3. Select the Tomcat v5.0 installation directory and click Next.

    4. Add the idkProxy project to the list of configured Tomcat projects and click Finish.

  2. Run and debug the application:

    1. In Project Explorer, right-click the idkProxy project and click Debug As | Debug On Server.

    2. Select the existing server and click Finish.

  3. When Tomcat starts in a new Servers tab, hit http://localhost:8080/idkProxy/servlet/AxisServlet to ensure that Axis has deployed correctly and the Web service APIs are correctly configured.

Eclipse Stand-Alone (without WTP)

  1. Deploy the IDK in your application server. For BEA WebLogic or Apache Tomcat, follow the instructions below. For IBM WebSphere, you must create a .war or .ear file that is compatible with WebSphere. You must first create an appropriate server-config.wsdd using the IDK DeployServlet or the supplied service wsdd files. See the WebSphere documentation for detailed instructions. 

    1. Create a folder called \idkProxy in the application server's \webapps directory. (For example, if Tomcat is installed in C:\tomcat, the path might be C:\tomcat\webapps\idkProxy.)

    2. Navigate to the IDK installation directory and copy the WEB-INF and its \LIB subfolder from \idk\6.0\devkit\ folder to the new \webapps\idkProxy directory in the application server. This loads Apache AXIS into the application server.

    3. Confirm that Apache AXIS is available by opening the following page in a Web browser: http://<hostname:port>/idkProxy/servlet/AxisServlet (change <hostname:port> to fit your application server, for example, localhost:8080 for Tomcat). The browser should display the message "And now... Some Services" and a list of installed services.

  2. Compile the class that implements the IDK interface and copy the entire package structure to the appropriate location in your Web application, usually the \WEB-INF\classes directory.

  3. Start your application server. In most cases, you must restart your application server after copying a file.

Step 4: Deploying a Pagelet in Ensemble

To deploy the pagelet in Ensemble, follow the steps below.

Note: These steps are for IDK version 6.0 and AquaLogic Ensemble 1.0.

    1. Create a new Producer resource in Ensemble.

      1. Go to Applications | Resources and click Create New. Name the new resource "idkProxy".

      2. On the Connections tab, for the Internal URL Prefix, enter the URL to the remote server location that hosts the pagelet (http://<hostname>:<port#>/idkProxy/). For the External URL Prefix, enter "/idkProxyProducer/".

      3. Click Save.

    2. Create a new pagelet using the Producer resource you just created.

      1. Go to Applications | Pagelets and click Create New. Name the new pagelet "idkProxy". For the Library, enter "idkProxyLib".

      2. Choose the parent resource; click Select and choose the idkProxy resource you created in step 1.

      3. On the Location tab, for the URL Suffix, enter the name of the pagelet on the remote server (pagelet.jsp).

      4. On the Parameters tab, add the two parameters used by the pagelet: Att1 and Att2. For the Type, enter String.

      5. Click Save.

      6. Go to the General tab and copy the sample code for the pagelet (you will need it in step 4 below).

    3. In the /idkProxy directory, create a new HTML page called "consumer.html" and paste in the sample code copied in the previous step. The embedded pt:ensemble.inject tag retrieves the content from the resource/pagelet you created in the previous steps. This example uses the ALI Scripting Framework to set the session preference used in pagelet.jsp.

      The HTML page is required to display the pagelet content in Ensemble. The HTML page can be hosted on any server accessible to Ensemble; this example uses a single web application (idkProxy) for simplicity.   
       

    4. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

      <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

      <title>IDK Proxy Pagelet</title>

      </head>

      <body>

      <script type="text/javascript">

      function setPrefs()
      {
      var prefName = 'sessionVar';
      var prefValue = 'my session pref';

      PTPortlet.setSessionPref(prefName,prefValue);
      }

      </script>

      <pt:ensemble.inject xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/' pt:name="idkProxyLib:idkProxy" Att1="value1" Att2="value2">

      <xml>

           <payload>Here is the xml payload!</payload>

      </xml>

      </pt:ensemble.inject>

      </body>
      </html>

      Note: You must include the namespace xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/' in the pt:ensemble.inject tag or the tag will not work.

    1. Create a new Consumer resource in Ensemble. This resource will host the consumer.html page that consumes the resource/pagelet.  

      1. Go to Applications | Resources and click Create New. Name the new resource "idkProxyConsumer".

      2. On the Connections tab, for the Internal URL Prefix, enter the URL to the remote server location that hosts the consumer.html page (http://<hostname>:<port#>/idkProxy/). For the External URL Prefix, enter "/idkProxyConsumer/".

      3. Click Save.

    2. To view the pagelet in Ensemble, hit the consumer.html page on the Consumer resource: http://<Ensemble_proxy_host>:<Ensemble_proxy_port>/idkProxyConsumer/consumer.html.
      Note: By default, new pagelets and resources are only accessible by the "administrator" user. For additional information on configuration, see the Ensemble documentation.

To deploy this pagelet as a portlet in the AquaLogic Interaction portal, you could register the pagelet.jsp file as a Pagelet Web Service object. Payload functionality is not supported in the ALI portal. For details on the main differences between pagelet and portlet development, see Pagelet vs. Portlet.