Monday, December 1, 2014

Portlet: Deploy Portlet (JSR 286) using JDEV

In this blog we are going to deploy our previously created portlet  ( here ) and view its output

We are going to deploy our portlet in weblogic which is WSRP producer also. It means it can expose our JSR 286 based portlet as WSRP 2.0.
WSRP is web service for remote portlet. If we expose our JSR 286 portlet as WSRP 2.0 then our portlets can be used not only in java portals but in any other portasl (.NET) based etc.

To expose your portlet as WSRP we can follow these steps.
1. Create connection to weblogic server on Resource Pallete. 
   (I have a stand alone weblogic server running locally in my jdev and I would be deploying my portlets on it)

     As we are deploying on stand alone server it must behave as a portlet producer. For that we need to extend weblogic with 'Oracle Portlet Producer' as shown below

2. Create deployment profile:
      a. Select project properties > Deployment > New
      b. Provide Archive Type (war) and name for deployment profile
      c. Just say OK in war profile

3. Deploy war:
     a. Right click on project and select Deploy and then deployment profile
      b. Select 'Deploy to Application Server option'
      c. Select your server on which you want to deploy
      d. Select 'Yes' for WSRP option

Once deployment is successful, you will see a url like


 Now launch that url on a browser
Page provides a url 'WSRP v2 WSDL'. This url points to a WSDL, which exposes all portlets of application using a WSDL. We need this URL to test this portlet.

If we want to deploy it on integrated server, we can start integrated server and then deploy using a deployment profile as suggested above.
But to test it we need to run integrated server from the application which has portal page. As we can only have one integrated server running at a time I would suggest following steps

1. Create a new ADF application.
2. Start Integrated server when this new application is selected.
3. Open JSR 286 application and deploy it on already running integrated server.
4. Again open ADF application and create WSRP connection with deployed JSR286 application.
5. Create a page in ADF application and drag and drop portlet from connection on page directly.

We will test deployed portlet in our next blog.

Portlet: Create portlet (JSR 286) using JDEV

In this blog we are going to create a basic standard based portlet (JSR 286) using JDEV.

Why do we need portlet: Portlet is a way to share your UI content in multiple application. Let say you have an application which shows employee hierarchy. You may be interested to show that particular part in other applications as well. In such cases these common UI which need to appear in multiple application can be created using portlet and then all applications can consume them.

What is JSR 286: . JSR 286 is java specification for portlets. I would say there are mainly two parties involved here. 1. Developers 2. Portlet producer. Portlet producer is a server which handles request and provide response like a web container. For example weblogic, jboss etc. Now all these java servers need to know if a request comes, how will they know its for which portlet, which class needs to be instantiated and which method of class needs to be called to get response. Developers also need to implement those classes. So there is a need of standard so that portlet developed on one java server can freely run on any other java server supporting JSR 286. Standards are something like this
1. Have a portlet.xml file in WEB-INF folder
2. Define your portlet in this xml file. Every portlet will point to a class.
3. Class must implement javax.portlet.Portlet interface. (As default implementation is already provided by java in javax.portlet.GenericPortlet class. We can directly extend it)
4. If you are implementing Portlet interface then you need to implement init, processAction, render, destroy method
5. If you are extending GenericPortlet then you can directly write doDispatch, doView, doEdit etc method. These methods will be called based on portlet mode.

There are many others but its enough to start with.

Similarity with Servlet Specifications: JSR 286 is a bit similar to Servlet specifications.
1. We define our servlet in web.xml, which is inside WEB-INF folder
2. Every servlet entry points to a class.
3. Class needs to implement javax.servlet.Servlet interface (or extent javax.servlet.http.HttpServlet)
4. If you are implementing Servlet interface you need to implement init, service etc methods
3. If you are extending javax.servlet.http.HttpServlet then you can directly write doGet, doPost etc.

Creating JSR 286 portlet:
JDEV provides mainly three ways of creating portlets
1. Using Oracle-PDK Java Portlet
2. Using Standard based java portlet (JSR286)
3. Exposing ADF tasflows as portlet.

We are going to create standard based portlets (JSR 286).
Note: JSR 286 is new standard for portlet development. It is also called Portlet 2.0 standards. Before this we had JSR 168. In old JDEV version you will see JSR 168 only.

        Click next - next - next - finish in other stops

We are kind of done with our initial portlet. Lets check entries created by JDEV
1. Project structure:

2. portlet.xml:

3. doDispatch method of GenericPortlet transfers all request to doDispatch method first. If we override this it means all request to the portlet will come to this method. Lets see default generated code of this method.

4. view.jsp:

5. edit.jsp:

6. processAction method of This method is called when end user clicks OK/Apply button when portlet is in edit mode.

With that our whole code is ready.

But to test it we need to deploy our portlet on a portlet producer. We will do it in next blog.

In a nutshell request response cycles will be something like