Sunday, August 22, 2010

Difference in wiring between websphere portal 6.0 and 6.1

Hi Friends,

I would like to share my experience with you on interportlet communications via wiring tool of websphere portal in 6.x. Recently we are migrating all jsr 168 portlet applications which were running on IBM WebSphere portal 6.0 version to 6.1 version. As I say, wiring as my favorite topic; I came accross very interesting fact that needs to be taken care of if you are doing portlet to portlet communication using wiring tool in websphere portal.

We had an application which passes multiple string parameters from source portlet to target portlet and was working fine on version 6.0. But when I tried deploying this portlet application on version 6.1, it started complaining during the deployment itself as the wsdl file through which the wiring was handled has multiple parameters passed on a single request.

So there was a code change required and we started passing a collection object instead of passing multiple String params. In short, please take care when you implement wiring with jsr 168 and follow the best practice by passing the collection objects instead of multiple string parameters.

Sample Code to retrieve IBM WebSphere Portal Users Group information using PUMA API

This is very useful sample code to retrieve user groups of websphere portal 6.0 using PUMA API. There are some changes in PUMA API in 6.1 but the basics still remains the same.

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.portlet.PortletRequest;
import javax.servlet.http.HttpServletRequest;
import com.ibm.portal.portlet.service.PortletServiceHome;
import com.ibm.portal.puma.Group;
import com.ibm.portal.puma.User;
import com.ibm.portal.um.PumaHome;
import com.ibm.portal.um.PumaLocator;
import com.ibm.portal.um.PumaProfile;
import com.ibm.wps.pe.pc.std.core.PortletUtils;

public class GroupInformation {
public List getUserGroups(PortletRequest prequest){
//Start get the servlet request from the portlet request
HttpServletRequest httpRequest = null;
      try{
         httpRequest = PortletUtils.getIncludeServletRequest(prequest);
}
catch (Exception e){
      e.printStackTrace();
}
//End
PortletServiceHome psh;
PumaHome pumahome = null;
List groupsNames = new ArrayList();
      try{
javax.naming.Context context = new javax.naming.InitialContext();
psh = (PortletServiceHome) context.lookup ("portletservice/com.ibm.portal.um.portletservice.PumaHome");
if (psh != null)
pumahome = (PumaHome) psh.getPortletService(PumaHome.class);
PumaProfile pumaprofile = (PumaProfile)pumahome.getProfile(httpRequest);
User user = (User) pumaprofile.getCurrentUser();
PumaLocator pumalocator = pumahome.getLocator(httpRequest);
List groups = pumalocator.findGroupsByPrincipal(user, false);
Iterator iter = groups.iterator();
while (iter.hasNext()){
Group grp = (Group) iter.next();
groupsNames.add(grp.getName());
}
      }
      catch (Exception e){
      e.printStackTrace();
      }
      return groupsNames;
      }
}