Search My Ramblings

Friday, November 2, 2012

Using Spring Portlet MVC 3.0 in Oracle Webcenter Portal (Spaces)

You may find yourself in the same quandary as me.  I want to stand up a portal quickly at an Oracle shop(client), so Webcenter Portal is currently the defacto choice as the solution, and in this case Spaces has been chosen for its ease of setup and collaboration (including built-in integration with BPM).  However, the client is not an ADF development shop, but is familiar with another web development framework like Spring MVC. Since the only way to expose portlets in Webcenter Portal 11g is using WSRP (Web Services for Remote Portlets), it shouldn't really matter what framework you use to develop the portlet as long as it is deployed using WSRP you can register it with Webcenter Portal and use it as you desire.  Note that there are plenty of more informed blogs and websites that provide the argument whether to use Webcenter Portal: Framework vs. Webcenter Portal: Spaces, as well as whether to extend your portal using either WSRP Portlets or ADF task flows.  I will defer to those sites on providing you those decisions to make, but if you have selected WSRP Portlets, here's how you can use your favorite IDE to develop them and deploy them properly to Webcenter Portal: Spaces.  Doing the same with Framework would entail similar steps, you would need to create a WSRP connection to the portlet producer from within JDeveloper and add the portlet to your page through JDeveloper instead of the Spaces web application. As a quick overview, I tried determining how to WSRP enable my portlet for some time before I stumbled onto the documentation within Oracle's 11g docs describing how this can be done via script as a pre-deployment step for any JSR-286 compliant portlet.  This instruction is within the administrator's guide and not the developer's guide, which made me realize their intention of separation of roles for deployment.  So I will document how to get a portlet into Webcenter Portal in several steps based on role to be consistent with this intention:
  1. Developer creates JSR-168/286 compliant portlet using their IDE and whatever framework they want
  2. Developer packages portlet up as EAR file for deployment
  3. Deployer updates EAR file using provided script to expose JSR-286 portlet as WSRP Portlet Producer EAR, and adds weblogic.xml to embedded WAR to specify shared library to include (otherwise deployment FAILS)
  4. Deployer deploys WSRP .ear to Webcenter Portlet Producers server.
  5. Webcenter Portal: Spaces Administrator registers WSRP v2 portlet producer in Webcenter Portlet: Spaces using WSDL URL.
  6. Webcenter Portal: Spaces page designer adds portlet to desired page and sets any default configurations.

0. Setup your IDE to support Portlet Development

In this case, I'm showcasing using Netbeans as the IDE, but you can also substitute Eclipse using plugins for portlet development as well.  For some reason, I've never liked Eclipse much, which puts me in a small minority, but I'm ok with that.  For Netbeans, I installed Netbeans v7.2.1 and then installed the Portal Pack 3.0.5 Beta plugin. I'm not going into too much detail here, but for Eclipse there are similar options for setting it up to enable portlet development, specifically using Spring Portlet MVC 3.0. 

1. Develop JSR-286 Compliant Portlets

Again, the purpose of this posting is not focused on the history of portlets, the reasons to create them, etc.  Nor will I go into details on how to develop JSR-286 portlets in Spring Portlet MVC, mostly because there are already excellent online resources for learning about this.  My recommendations for learning this, not necessarily in order: In Netbeans, you create a basic portlet application using Spring by the following steps:
  1. Create a new Java Enterprise Application project
    1. File, New Project...
    2. Java EE, then Enterprise Application
    3.  Name your enterprise application and leave everything else defaulted
    4. Select Oracle Weblogic Server as the Server, then uncheck the Create EJB Module and Create Web Application Module options.
    5. Click Finish
  2. Create the Web Application project for portlet/Spring Portlet MVC development
    1. File, New Project...
    2. Java Web, then Web Application
    3.  Name your application whatever makes sense, then select the Enterprise Application you created above, select the server type as Oracle Weblogic Server, and set your web context path
    4. For Frameworks, select "Portlet Support" and "Spring Web MVC".
  3. Right-click on the Enterprise Application project in the Projects view, then select the "Add Java EE Module" option, then select the Web Application you just created, and press OK.
  4. Voila, now add portlets to the web application by right-clicking on the project name and then selecting New, then Spring Portlet.  Complete the Class name that implements the Handler in Spring Portlet MVC, as well as the package to use, and then enter the portlet name that gets registered along with the other portlet metadata, then press Finish which will use the defaults values for configuration file for this portlet and JSP files for view, edit and help modes.

2. Package Web Application Containing 1+ Portlets as EAR File

For Netbeans, I've made the following change to make using this as a WSRP portlet producer possible:
  • Since we selected Weblogic as the application server when we created the web application, it creates a WEB-INF/weblogic.xml file already.  If you don't include this step, your EAR file will not deploy successfully in Weblogic server, and you'll see strange errors about the Test page for the WSRP application.  We need to add the following library-ref XML fragment to the bottom of the existing weblogic.xml so it resembles:
Ideally this would be added in the subsequent step, which should allow *any* JSR 286 portlet to be WSRP-enabled, but I didn't take the time to create this using Ant or another method, which could be done to really streamline the process.  I think if you don't have a weblogic.xml the next step will create one with the above-mentioned library, but if one already exists it doesn't properly merge the library reference into the existing one.

3. Deployer Enables JSR-286 Portlet EAR as WSRP Producer for Webcenter Portal

This is where the rubber meets the road, as they say.  It took me a while to locate the magic to make this happen, but now I want to make it more transparent for everyone to use.  The essential step(s) you'll need to follow to deploy your portlet as a WSRP 2 portlet producer in Webcenter are documented at http://docs.oracle.com/cd/E23943_01/webcenter.1111/e12405/wcadm_portlet_prod.htm#CHDECJHI.  I have created a simple ant target that I use in Netbeans to do this step.  Note that I have installed JDeveloper 11.1.1.6 with the Webcenter extensions, which allows these libraries to be found locally on my system.  I did the following in my enterprise application project:
  1. Update the project.properties file to include 2 new properties at the bottom:
  2. oracle.home=C:\\Oracle\\Middleware jdev.home=${oracle.home}\\jdeveloper
  3. Add a build-wsrp target in the build.xml for the project, which uses the default target in the imported build-impl.xml so the bottom of the build.xml looks like:
  4. Now test it by right-clicking on the build.xml and then Run Target->Other Target->build-wsrp
  5. You should see BUILD SUCCESSFUL if you have the Output window enabled, and under the /dist folder a new ${pre-WSRP app file}POST.ear file that has been packaged as a WSRP portlet producer.

4. Deployer Deploys .ear to Webcenter Portlet Producer Server

It is recommended that custom portlet producers get deployed to a separate server named the Portlet Producer server, and can be created by following my blog post about how to extend the VirtualBox VM for Webcenter to include the Omniportlet and WebClipping portlet producers. You can deploy the EAR in a number of ways, including using Weblogic console, WLST, or Enterprise Manager.  Since this is a standard deployment task, you should be able to get it deployed using any of these ways without error nor detailed instructions here.  Consult the Webcenter Administrator's Guide for details if you're not sure at http://docs.oracle.com/cd/E23943_01/webcenter.1111/e12405/wcadm_portlet_prod.htm#CIHBCAED/.

5. Register WSRP Portlet Producer in Webcenter Spaces

For this I typically have followed the instructions located at http://docs.oracle.com/cd/E23943_01/webcenter.1111/e10149/config_svcs_prod_extapp.htm#WCSUG7783

6. Include Portlet on Portal Page

This is as simple as either creating a new page to test out your portlet, or editing an existing page, selecting "Add Content", then under Portlets, then Your Portlet Producer, then Your Portlet.  It should add to the page and display in view mode initially.

No comments: