ShowTable of Contents
Mobile Portal Accelerator (MPA), based on device-independency, enables providers to create Web-based applications to a limitless range of mobile devices. It helps extend the capabilities of WebSphere Portal to mobile devices through device-independent Web authoring for virtually any mobile device. It uses a device independent markup language called XML-based Device Independent Markup Extensions (XDIME) .The latest version, XDIME 2, is based on the W3C Device Independent Authoring Language (DIAL) specification .
The recent months have seen an explosion in the market for smartphones. Smartphone sales have risen dramatically, with consumers snapping up the latest models as the smartphone vendors compete to provide the best & UI rich products with the newest technology. In this market, those consumers - your customers and employees - increasingly expect to be able to do many of the same things (including rich UI) on their mobile devices that they've traditionally done on their laptop or desktop devices.
This Article/Sample shows a simple example of how to use MPA with EJB (this is developed on MPA 7.0 on Portal 7.0)
This article requires the following development environment:
Mobile Portal Accelerator 7.0
Mobile Portal Toolkit 7.0
Rational Application Developer (RAD) 8.0
To test the sample portlets , mobile simulators can be used. This article used User-Agent-Switcher to test this functionalities.
Implementing the EJB code
The following code is in the EJB Home interface
Listing 1. Home interface
Listing 2. Enterprise Bean
public ejbs.Calculator create() throws javax.ejb.CreateException, java.rmi.RemoteException;
public int add(int i, int j) throws java.rmi.RemoteException;
public float add(float i, float j) throws java.rmi.RemoteException;
public int multiply(int i, int j) throws java.rmi.RemoteException;
public float multiply(float i, float j) throws java.rmi.RemoteException;
Code in the portlet processAction code to invoke the EJB
Hashtable env = new Hashtable();
ic = new InitialContext(env);
Object oRef = ic.lookup("ejb/ejbs/CalculatorHome" );
CalculatorHome home = (CalculatorHome)PortableRemoteObject.narrow(oRef,CalculatorHome.class );
Calculator calcy = (Calculator)home.create();
calValue = calcy.add(firstno, secondno);
String message = "The sum of " + firstno + " and " + secondno + " is : " + calValue;
Here are the steps to deploy the same :
Steps to deploy the same
a) Install the CalculatorEAR.ear (this is the EJB code) on the WAS server existing on the same location where the Portal Server is installed.You can use the Admin console of WAS to deploy the ear file. This contains the CalculatorBean.java which contains the EJB methods.
b) Install the Portlet(myejbportlet.war ) on the Portal Server (same machine as where the EAR file is deployed).
The EJB narrowing/create code is within the processAction method of the portlet (the java file is : Myejbportlet).
The only place where you may need to modify the code is the port number specific to your machine(in the Myejbportlet.java) :
You can get the port no from the following location : \properties\portdef.props (For eg : in this case is : C:\wps70\wp_profile location)
For the port number in the color , you can take either of the ORB_LISTENER_ADDRESS or BOOTSTRAP_ADDRESS (taken from the portdef.props file location) :
The portdef.props (from the source machine) has been attached as a reference as well.