Tuesday, September 11, 2012

Consume Portlets from WAS using WSRP

Now as we know we can deploy the portlets on WAS as it comes with portlet container here I will explain how the portlets deployed on WAS can be exposed from WAS as a web service and can be consumed by portal using WSRP.

Noe : WAS server used here is a standalone WAS 7 (server1) instance and not the one on which portal server runs over.

Now  if you look on of my older post it describes how you install the war file containing portlets on WAS so in this post I will assume that you are ready with that stuff.


So after installing the war files in the WAS we need to expose the portlets from was as a webservice for this we need to deploy a special EAR from IBM (Consider it as an out of box),this ear helps to expose the portlets from WAS as a webservice. (EAR file along with detailed PDF with instruction is available in backup email.)

Name of EAR (was.wsrp.producer.ear)

To access server1 admin console I used following url (https://localhost:9043/ibm/console/login.do?action=secure)

While deploying the EAR (In select deployment option page(i.e step1) you need to  check deploy as a webservice option in the checkbox)

After EAR is installed and started in WAS try to hit following url in browser you should be able see a wsdl

http://localhost:9080/producer/wsdl/wsrp_service.wsdl

Copy the above url and and log into the admin console of WebSphere portal where you want to consume the portlets from WAS

Go to webservice section in left panel of admin console
click new producer button

Fill the necessary details and  enter the wsdl url in the form and save it (if WAS server is remove localhost in the above url can be replaced with IP ).

Next step is you go to web modules section and click the consume button you should be able to see the newly created service

Lastly you can go to the portlets section search for the portlets with name installed in the WAS,you should be able to search the portlets and add them on the portal page.


Thus using above method we can consume the portlets deployed on WAS into the portal using WSRP

All the related material along with the PDF of instructions is available in backup email.


Accessing Portlets from WAS

Now here is a new thing I came to know,IBM has put in a portlet container into WAS 7 and maybe 6.1 as well. So I tried to run a portlet into WAS 7 and was successful. So without wasting time here are the steps to do it .

Note : - Portlets cannot run on WAS supplied with portal or on the WAS on which Portal server is running,so we need to deploy and run the portlets on server1 instance i.e separate standalone WAS.

If you try to run the portlet on the WAS on which portal server is running you might get an error such as "Direct portlet access prevented by WebSphere Portal ".

To access server1 admin console I used following url (https://localhost:9043/ibm/console/login.do?action=secure)

Step1 : Take a war containing portlets.

Setp 2 : Install the war in into the WAS

Step 3 : Provide the context root (eg /test)

Step 4 : Select server as server1

Step 5 : With all default settings complete the setup

Step 6 : Make sure war file is started

Now hit the following url in the browser to see the portlet

http://localhost:9080/mohit/SamplePortlet

format (http://localhost:9080/contextroot/portlet name as per portlet.xml)

By hitting the above url one should be able to see the portlet from WAS though basic features of portal will be missing from portlets as its running from WAS.

Saturday, May 5, 2012

Websphere Portal theme Intro

Websphere Portal has seen many changes in terms of portal theme in recent times,following is are few points which describe different generations of portal theme.Article include details of theme starting for portal 6.1.

Basic portal theme which was present in portal 6.x is known as simple portal theme,Default.jsp is the main file of this theme which creates the whole structure of theme.Each section of theme like head,side nav,top nav are constituted using different jspf files like head.jspf,ext_js.jspf  etc. All these jspf files are included in default.jsp which is responsible to aggregate all the components of theme .

Following libraries and there tags can be used for reference

Url : http://publib.boulder.ibm.com/infocenter/wpdoc/v6r0/index.jsp?topic=/com.ibm.wp.ent.doc/wps/dgn_ptltld.html

Basic Portal theme was followed by web2 theme,web 2 theme followed the concept of CSA (clien side aggregation) i.e when the page renders at all the dynamic spots on the page only the placeholder is placed and when the page is completely loaded these placeholders are filled with data.It means for example we need to render a imagein the banner of theme at first a place holder for the img like a div will be placed which will be filled with an image after page load.

Web2 theme also make sure that when there are multiple portlets on a single page and only one of the portlet needs to be refreshed then whole portal page is not refreshed but only the portion of the portlet is refreshed.Earlier to web 2 theme if we had to achieve this only was to send ajax call from the portlet which needs to be refreshed but in case of web 2 theme even if there is no ajax calls only one portlet is refresh on a page is possible without reloading other portlets and theme.

Portal 7 introduced the concept of page builder theme,this theme provides the logical separation of static content and dynamic content within theme.All the static content of theme like js,css etc are kept in a different logical place than the jsp and jspf's which represent dynamic content.Benefit of this logical separation is that if you just need to add a new js to theme or change a css you now dont need to change it into your theme project of RAD and redeploy theme on WAS.
       Static content of theme can be directly accessed by a tool like webdev where you just need to provide the url of logical separation where static content is located and access the folders of static content directly.Also the role of Default.jsp has been degraded in this type of theme,because now all the structure where all things aggregate happens in theme.html file which is located in Static content.
Now for example if you just need to add a new js file to the theme you can just add the new js file using webdev to static content and then refer this new js file in theme.html as its already present in static content folder which can be directly accessed through web dev,thus it saves developer to add the js in theme project,refer js in head.jspf and redeploy the whole war again.

Note : While development its recommended that the js files should be added to js folder and referenced in respective jspf files,above technique is best suited when project is ready and you want to do simple quick change.It must be also noted that in page builder theme default.jsp points to theme.html.

Theme Policy: theme policy is an xml file which have attributes in the form of name value pair,you can copy the default theme policy of portal and change the value of attributes as per you need and apply the theme policy on to the portal page page.We can create multiple theme policy for a portal theme,theme policy tells the theme what needs to be rendered on to the page.For example if in a portal theme we have created a top nav,side nav and a banner,using theme policy we can control what all things from theme are loaded on a particular portal page,i.e on page "xx"if I just want a top nav of theme I will first create a theme policy and set value to top nav as true while values to side nav and banner will be set to false,then I will apply the theme policy on to the portal page "xx" and portal will ensure that only top nav is rendered from theme in page "xx".

We must ensure that all the theme policies for a particular theme must have same set of attributes while the value of each attribute can be different in each of the theme policy.If you need to add a new attribute in theme policy which not present by default in portal theme policy them you will have to also create a bean in theme project and getter and setters of that attribute within the bean apart from adding the attribute to the theme policy.If you are adding your own custom attribute then you will also have to register the theme policy using xml access (only is you have added a custom attribute to theme policy).

Note: Page builder theme  of portal 7 do not support theme policy


Color Palette: As mentioned above theme policy allows us to select what all sections of theme are to be loaded on which portal page,likewise color palette allows developers to change the rendering of each section of theme.For example if I have a banner in theme and I want to show this banner in 2 different colors on 2 different portal pages.I will set the different value of color palette in both the portal pages by going into the page properties.

Thus if for page x if I will set in page property value of color palette as red on this page the banner of theme will appear red while on other page property if I will set the value of color palette as blue on this page the banner will apper as blue.

Important thing to note over there is that theme reads these values set in page properties using metadata and use it accordingly.

Code is as follows

<portal-logic:pageMetaData varname="pageMetaData">
    <c:set var="headerHostDefault"><c:out value='${pageMetaData["header.host.default"]}'/></c:set>
    <c:set var="headerHostSecure"><c:out value='${pageMetaData["header.host.secure"]}'/></c:set>
    <c:set var="headerConnectionsUrl"><c:out value='${pageMetaData["header.connections.url"]}'/></c:set>
    <c:set var="headerStyle"><c:out value='${pageMetaData["header.style"]}'/></c:set>
</portal-logic:pageMetaData>

In case of page builder theme since theme policy do not work even to rendering of different sections of theme is done by providing the values through  page parameters and theme reads them from page metadata and renders the sections like top nav,side nav accordingly.Color palette is default attribute of portal.If you need to provide your own custom as well as page parameters you need to also define these values in properties file within theme apart from adding them to the page,so in the above code the values like "header.host.default" are set as page properties and defined in theme's property file as well.


Following are few important tags with respect to theme



Thursday, April 26, 2012

Portal 7 theme

IBM Portal 7 theme development guide

http://www-10.lotus.com/ldd/portalwiki.nsf/xpViewCategories.xsp?lookupName=Exceptional%20Web%20Experience%20for%20WebSphere%20Portal%207.0

Monday, February 20, 2012

Portlet Preference

Portlet Preference is a feature provided by portal in order to provide persistent data storage.Persistent data storage means that data once set in portlet preference will remain available even after server re-starts.

Details about the interface can be found at
http://www.bluesunrise.com/portlet-api/javax/portlet/PortletPreferences.html#getMap%28%29

Preference can be of 2 types

1) Read-only : they cannot be changed at runtime  are are defined in deployment descriptor or portlet.xml

2) Dynamic Preference : they can be set in process Action phase of life cycle of portlet and can be read in Render phase.

Following is the example to set and retrieve preference dynamically

public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
        if( request.getParameter(FORM_SUBMIT) != null ) {
            // Set form text in the session bean
            PreferencePortletSessionBean sessionBean = getSessionBean(request);
            if( sessionBean != null )
                sessionBean.setFormText(request.getParameter(FORM_TEXT));
        }
       
        PortletPreferences preferences = request.getPreferences();
        preferences.setValue("myVal","mohit");
        preferences.store();
    }


public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {
        // Set the MIME type for the render response
        response.setContentType(request.getResponseContentType());

        // Check if portlet session exists
        PreferencePortletSessionBean sessionBean = getSessionBean(request);
        if( sessionBean==null ) {
            response.getWriter().println("<b>NO PORTLET SESSION YET</b>");
            return;
        }
       
        PortletPreferences pref = request.getPreferences();
        pref.getValue("myVal", "no data found");

        // Invoke the JSP to render
        PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(getJspFilePath(request, VIEW_JSP));
        rd.include(request,response);
    }



Saturday, February 18, 2012

Websphere Portal personalization

Portal personalization can be achieved on a particular portal page or even on a particular portlet with a portal page.Following are the 2 links of different blogs to achieve personalization on portlets

Link 1
http://absolutebrain.blogspot.in/2011/06/personalizing-page-portlet-using.html
Link2
http://wpcertification.blogspot.in/2011/01/how-to-show-or-hide-portal-or-portlet.html 

Following link is an excellent tutorial from IBM developer works to create personalization

Link3 (Pdf is also available in backup email Id)
http://www.ibm.com/developerworks/websphere/tutorials/0702_brunn2/0702_brunn2-pdf.pdf

Above 3 links are enough to help you create the personalization rules and apply them to a portlet

I have used the code from link 3 and have modified it to fetch the data from DB (My Sql) and based on the data fetched from DB,I have returned the value "Pass" or "Fail" which can be used in the personalization rules to show/hide portlet or Portal page.

Sample application which will be put in portal server as a jar is available in backup email.Following is the code for reference from application

package com.ibm.websphere.personalization.examples;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import com.ibm.websphere.personalization.RequestContext;
import com.ibm.websphere.personalization.applicationObjects.
SelfInitializingApplicationObject;
import java.io.Serializable;
public class MySampleObject implements
SelfInitializingApplicationObject,
Serializable {
private String userName;
public void init(RequestContext context) {
userName = context.getRequestUsername();
context.setSessionAttribute("mysampleobject", this);
}
public String getMySampleString() {
return "Hello " + userName;
}
public int getMySampleInt() {return 1;
}
public Date getMySampleDate() {
return new Date();
}

public String getMohitSampleString() {
    return "Hello " + userName;
    }
// Method to fetch the data from DB and return corresponding value to be used in personalization rules.

public String getMyVal()
{
String output="fail";
String nm=null;
int ag;
    try {
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        System.out.println("Please include Classpath  Where your DB2 Driver is located");
        e.printStackTrace();
       
    }
    System.out.println("DB2 driver is loaded successfully");
    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rset = null;
    boolean found = false;
    try {
        conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/personalization", "root", "root");
        if (conn != null) {
            System.out.println("DB2 Database Connected");
        } else {
            System.out.println("Db2 connection Failed ");
        }
        pstmt = conn.prepareStatement("Select * from person");
        rset = pstmt.executeQuery();
       
       
        if (rset != null) {
            while (rset.next()) {
                found = true;
               
               
                ag=rset.getInt("Age");
                nm=rset.getString("Name");
                if(nm.equalsIgnoreCase("mohit") || ag>25)
                    {output="pass"; }
                System.out.println("Name: " + rset.getString("Name")+output);
            }
        }
        if (found == false) {
            System.out.println("No Information Found");
        }
    } catch (SQLException e) {
        System.out.println("DB2 Database connection Failed");
        e.printStackTrace();
       
    }

    return output;
}
}


Note : Apart from putting this java project as jar in portal server,we need to put mysql connector jar as well into portal server at following locations

D:\IBM\WebSphere\PortalServer\pzn\prereq.pzn\lib
D:\IBM\WebSphere\PortalServer\pzn\prereq.pzn\collections

Note: While creating personalization rule based on parameters of portal,like (if userid of portal user is wpsadmin show the portlet) we need to select attribute (Portal Users-->uid).Value has to be hard coded in value textbox. 

Thursday, February 16, 2012

Customization vs Personalization

When developing a portal application, there is lot of confusion wrt Customization vs Personalization. What the client might be calling Personalization might in fact be Customization or vice versa. So, it is very important to understand the difference between the two.

The term "customization" is used to mean the rendering of portlet content based on users preferences or manipulating the portal layout based on the users security attributes.

The term "personalization" is used to mean delivering portlet content based on a business rule or collaborative filtering.

Customization centers around what resources (portlets and pages) you show the users based on their role. This is a core capability of Portal. There are tools provided that help administrators provision these resources. Typically, portlets allow users to specify what kind of information should display. For example, a weather portlet might be customized to show
weather in the users home town.

Personalization can deliver content to a user based on a profile and/or business rule, or determine characteristics of a user based on previous purchases, or pages viewed. Personalization then selects content that is appropriate for that profile. For example, if a person has a high salary range, personalization can be configured to retrieve information about premium products, the page is assembled with the proper information and the user sees his personalized page.

Personalization includes a rules engine, a recommendation engine and a resource engine. Although a full install of Portal installs and configures personalization functions by default, there are additional databases to consider. For example, personalization uses the DB2 Content Manager Runtime Edition for storage of rules, campaigns and other objects. There is a logging framework used to record information about web site usage to a feedback database. The LikeMinds recommendation engine also requires a database to store information gathered through the logging APIs.

To use personalization, you need content to display to your users. Therefore, personalization and content management go hand in hand. You will also need to understand where content is stored and how it is managed to optimize performance.

Monday, February 13, 2012

Check Portlet Form submit

The first way to determine the submit of a portlet is by using the default technique,i.e the code provided by the basic portlet on creation.We just need to perform following tasks.
1) Change the button name to some custom value like "btn1"
2) Change the following line in portlet.java as

public static final String FORM_SUBMIT   = "btn1";

Above mentioned changes will allow,process action method to determine the submit of form.Following is the check put in processAction method.

public void processAction(ActionRequest request, ActionResponse response) throws PortletException, java.io.IOException {
        if( request.getParameter(FORM_SUBMIT) != null ) {

Custom code goes here................

}
}