Ensemble Pagelet Development

IDK Quickstart: Hello World Pagelet - .NET

This simplified Hello World example displays settings and content from a remote application in an AquaLogic Ensemble pagelet. This page provides instructions and sample code for .NET 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 - Visual Studio

The steps below are for the Visual Studio .NET IDE.

  1. Start Visual Studio and click File | New Project | C# Projects | ASP.NET Web Service. Type an intuitive name in the Location field.

  2. Delete Service1.asmx and Web.config.

  3. In the new project, click File | Add Existing Item.

  4. Browse to the \devkit folder in the IDK installation directory.

  5. In the File Types mask, click All Files.

  6. Select all the .asmx files and Web.config. Do not select the \bin directory.

  7. Click Open. You will be prompted to create a class file for each .asmx file; click No for each file.

  8. Add the IDK assemblies:

    1. In the Solution Explorer (usually in the upper right), you should see the project you created in Step 1.

    2. Right-click References and click Add Reference.

    3. Browse to the \devkit\bin folder in the IDK installation directory.

    4. Select all the .dll files (Ctrl+A). These are the assemblies that resolve the references in the *.asmx files.

    5. Click Open | OK.

    6. In the Solution Explorer References, you should now see edk, openfoundation, etc.

  9. Click File | Add New Item to create new classes and complete your project.

Step 2: Create a Pagelet

As noted above, this example creates a pagelet that displays information from the proxy, including setting values. .NET pagelets use a code-behind page (.aspx.cs) to retrieve settings and a Web form (.aspx) to display the portlet.  

The code-behind page 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.

 

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Plumtree.Remote.Portlet;
using System.Xml;
using System.Text;
using Bea.Alui.Proxy;

namespace IDKProxyWS

{

/// <summary>
/// Summary description.
/// </summary>

public class IDKPagelet : System.Web.UI.Page
{
public String name;
public bool isGuest;
public int userID;
public String envType;
public String payload;
public String Att1,Att2;
public String SessionVar;

     private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
InitializeCSP();
}

     private void InitializeCSP()
{

IProxyRequest proxyRequest;
IProxyResponse proxyResponse;
IProxyUser proxyUser;
IProxyContext proxyContext;
ProxyContextFactory factory;
HttpRequest request = HttpContext.Current.Request;
HttpResponse response = HttpContext.Current.Response;

           try
{

factory = ProxyContextFactory.getInstance();
proxyContext = factory.CreateProxyContext(request, response);
proxyRequest = proxyContext.GetProxyRequest();
proxyResponse = proxyContext.GetProxyResponse();
envType = proxyRequest.GetEnvironment().GetType().ToString();                     

proxyUser = proxyRequest.GetUser();
isGuest = proxyUser.IsAnonymous();
name= proxyUser.GetUserName();
userID = proxyUser.GetUserID();

Att1 = (String)proxyRequest.GetSetting("attr1");
Att2 = (String)proxyRequest.GetSetting("attr2");
Att2 = (String)proxyRequest.GetSetting("SessionVar");
 

byte[] bpayload = proxyRequest.GetPayload().GetText();
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
payload =  enc.GetString(bpayload);     
}
catch(Bea.Alui.Proxy.NotGatewayedException e)
{               
}

        }

  }

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{

//
// CODEGEN: This call is required by the ASP.NET Web Form
// Designer.
//

InitializeComponent();
base.OnInit(e);

          }

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{  

this.AddButton.Click += new
System.EventHandler(this.AddButton_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

}

}

The Web form that displays the pagelet (IDKPagelet.aspx) displays the information retrieved by the code-behind page (IDKPagelet.aspx.cs).

 

<%@ Page Language="c#" runat="server" CodeBehind="IDKPagelet.aspx.cs" AutoEventWireup="false" inherits="IDKProxyWS.IDKPagelet" %>

<%@ import Namespace="System.Collections" %>
<%@ import Namespace="System.Web" %>
<%@ import Namespace="System.Web.UI" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >

<html>
<head>
<title>IDKPagelet</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">            
</head>

<body MS_POSITIONING="GridLayout">
<span xmlns:pt='http://www.plumtree.com/xmlschemas/ptui/'>

Proxy Pagelet <BR>

<%

Response.Write("IDK Proxy Pagelet<BR>");
Response.Write("Environment Type " + envType + "<BR>");

Response.Write("Guest User? " + isGuest + "<BR>");
Response.Write("User Name: " + name + "<BR>");
Response.Write("User ID: " + userID + "<BR>");
Response.Write("<P>");

Response.Write("Pagelet Attributes:<BR>");
Response.Write("Attribute1: " + Att1 + "<BR>");
Response.Write("Attribute2: " + Att2 + "<BR>");
Response.Write("SessionVar: " + Att2 + "<BR>");
Response.Write("<P>");

Response.Write("Pagelet XML Payload:<BR>");
Response.Write("<textarea name=xml cols=80 rows=6>" + payload + "</textarea>");
Response.Write("<P>");

%>

</span>
</body>
</html>

 

Step 3: Deploying a Custom IDK Project in IIS

Note: These steps are for IDK version 6.0.

After Visual Studio is set up for development against the .NET IDK as described above, follow the steps below to deploy new services. 

  1. Compile the class that implements the interface.

  2. If you do not already have a virtual directory in IIS for your services, add one using the steps below:

    1. Click Start | Settings | Control Panel | Administrative Tools | Internet Services Manager (Internet Information Services).

    2. Select Default Web Site.

    3. Click Action | New | Virtual Directory and type the name of your Visual Studio Location. Click Next twice. Type the path to the home directory for the IDK: <installdir>\idk\6.0\devkit\dotnet.

    4. Check both the Read and Scripts only checkboxes if they are cleared (they should be checked by default). Click Next, then click Finish.

The class files will be compiled to the \bin folder in the <installdir>\idk\6.0\devkit\dotnet directory.

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 created in step 1. Go to Applications | Pagelets and click Create New.

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

      2. To choose the resource, click Select and choose the Producer resource you created in step 1 (idkProxy).

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

      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 you copied in the previous step. The embedded pt:ensemble.inject tag retrieves 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.