When troubleshooting Portal issues, traces are certainly helpful, but sometimes you just want a quick dump of specific information without having to dig through traces. Other times, you may want to quickly implement a proof of concept idea via some quick code, but don't want to deal with the hassle of creating the portlet, deploying it, and redeploying .... every ... single ... time ... you ... want ... to ... make ... a ... small ... change ... to ... your ... code.
A quicker solution to this would be to place the same code in a JSP file, upload the JSP file to your Portal server, and then have the JSP execute. This won't expose all of the available functionality that JSR168/286 portlets would normally offer, but, offers the benefit of quickly testing out your code. WebSphere Portal 6.0, 6.1 and 7.0 all ship with a portlet called the Blurb portlet which can read your JSP and execute the contents within it. Normally, the Blub portlet is utilized to display a welcome message when you login to the Portal, but, given it can read any JSP file you configure it to utilize, we can modify its intended purpose slightly to debug our Portal.
Simple Test Case
Let's take a simple Hello World test case.
1) Open up your favorite text editor (no need for an IDE!)
2) Copy and paste the following into the text editor:
3) Save the file as helloworld.jsp.
4) Copy the helloworld.jsp file to the following location on your Portal server:
On my AIX system, the full path is:
5) Open up a web browser. Login to the Portal server as an administrator. Navigate to the Administration section.
6) In the Manage Pages section, Go to Content Root > Home label and create a new page, call it "helloworldtest".
7) Still in manage pages, on the right-hand side of the "helloworldtest" page, click on the Pencil icon for "Edit Page Layout"
8) Click the + sign to add portlet, search for "Welcome". Click the checkbox next to the"Welcome to WebSphere Portal", and click OK to add it to the page. Click Done to complete the procedure.
9) Navigate to the newly created "helloworldtest" under the "Home" label. You'll observe the portlet is not yet configured. Let's go ahead and do that now.
10) Click the drop-down arrow in the top-right corner, then click "Edit Shared Settings"
11) Update the path to show
12) Click Save. Observe the results of your code in the JSP file!
PUMA API Sample Code
Hello World! gives us an introduction to invoking code with the JSP. Let's try something more interesting ... say using the PUMA API to get all users and groups.
1) Create a new page named pumaapitest
2) Create a new file named pumaapitest.jsp with following code and upload to the Portal server in same folder:
<%@ page import="com.ibm.portal.um.*" %>
<%@ page import="javax.naming.*"%>
<%@ page import="java.util.*"%>
final String BR = "<br><br>";
out.print("Starting to gathering info"); out.print(BR);
Context ctx = null;
PumaHome pumaHome = null;
PumaProfile pumaProfile = null;
PumaProfile pumaProfileForContext = null;
PumaLocator pumaLocator = null;
PumaController pumaController = null;
ctx = new InitialContext();
pumaHome = (PumaHome)ctx.lookup(PumaHome.JNDI_NAME);
pumaProfile = pumaHome.getProfile();
pumaController = pumaHome.getController();
pumaLocator = pumaHome.getLocator();
List userList = new ArrayList();
List myList = new ArrayList();
userList = pumaLocator.findUsersByAttribute("uid","*");
if (userList.size() == 0)
out.print("No users found from search!"); out.print(BR);
out.print("Found a total number of users " + userList.size()); out.print(BR);
for (int i = 0; i < userList.size(); i++)
out.print("User number " + (i+1) + " has the following attributes " + pumaProfile.getAttributes((User)userList.get(i), myList)); out.print("<br>");
List groupList = new ArrayList();
myList = new ArrayList();
groupList = pumaLocator.findGroupsByAttribute("cn","*");
if (groupList.size() == 0)
out.print("No groups found from search!"); out.print(BR);
out.print("Found a number of groups " + groupList.size()); out.print(BR);
for (int i = 0; i < groupList.size(); i++)
out.print("Group number " + (i+1) + " has the following attributes " + pumaProfile.getAttributes((Group)groupList.get(i), myList)); out.print(BR);
out.print("Exception occured!!! " + e); out.print(BR);
3) Add the "Welcome" portlet to the page, configure the portlet to point to /jsp/pumaapitest.jsp
4) Observe results and notes from author of this blog entry:
- My test Portal only has the
default / out of the box user and group. In a larger Portal connected
to an LDAP, this sample could would query for uid=* and cn=* for users
and groups respectively. On the sample code, formatting could probably
use some improvements, as could error catching and handling, but, the
proof of concept was implemented fairly quickly.
- Also, should
your code fail to compile (missing semicolons for instance), you will
observe an HTTP 500 error on the page with debug output of where the
compile error is in the code. Upload the corrected version of the code,
reload the page, no more HTTP 500.
- In a production system, it is
NOT recommended to use the Blurb portlet for this purpose. However,
for testing purposes, this offers a quicker means to potentially try out
some new options within the Portal that would have otherwise been
difficult to allocate the time to code via a portlet. Future blog
postings will cover some more advanced uses of this debugging technique,
including pulling information from the portlet request, dumping browser
cookies, session information, rememberme, etc. Stay tuned!