Monday, 4 June 2012

Project URL generation in Websphere portal server 8.0

You can redirect request processing to a specific project by generating URLs with the ProjectIdentificationService API, the REST API, or the Enabler API. Request processing operates either completely within the scope of a project or completely outside the scope of a project. You cannot switch projects during request processing.

When a request originates from within a project, the request URL contains a project identifier for that project. The project information is included only in the URL and is not bound to the session. The project identifier can be an object ID (OID), as used by the portal, or a universally unique identifier (UUID), as used by Web Content Manager. To direct request processing to a specific project, you must generate a URL for the project and then render the URL.

Sample code:
public void init() throws PortletException{
          try {
                Context ctx = new InitialContext();
                projectService = (ProjectIdentificationService)ctx.lookup(ProjectIdentificationService.JNDI_NAME);
                PortletServiceHome serviceHome = (PortletServiceHome)ctx.lookup(JNDI_NAME);
                stateService = (PortletStateManagerService)serviceHome.getPortletService(PortletStateManagerService.class);

                } catch(NameNotFoundException ex) {
                } catch (NamingException e) {
                      // TODO Auto-generated catch block

public String createPageURL(PortletRequest request, PortletResponse response) throws Exception {
                URLFactory urlFct=null;
           // get the needed factories
                  // construct a server context for the project
                String projid="1338867733125";
                ObjectID projoid=getObjectID(projid);
                  final ServerContext projectCtx = projectService.createServerContext(projoid, new MyServerContext());
                  // access the URL factory to create a URL
            PortletStateManager manager = stateService.getPortletStateManager(request, response);
            urlFct= (URLFactory) manager.getURLFactory(projectCtx);
                  // construct a URL to the current state
                  final EngineURL url = urlFct.newURL(Constants.SMART_COPY);
                  return url.writeDispose(new StringWriter()).toString();

      private ObjectID getObjectID(String uniqueNameStr){
          try {
            InitialContext ctx = new InitialContext();
            final Name uniqueName = new CompositeName("portal:uniquename");
            ObjectID oidForUniqueName = (ObjectID) ctx.lookup(uniqueName);
            return oidForUniqueName;
          } catch (Exception e) {
          return null;

 Using CSA,we can obtain Project URL through javascript

// get the current nav state
var state =;
var navState = state.NavigationStateModelFactory.getNavigationStateModel();

// get the URL generator
var urlGen = state.UrlGeneratorFactory.getURLGenerator();
urlGen.getURL(navState, function(url) { alert(url); }, { "project": "" } );

Click here to download the code.

No comments:

Post a Comment