Thursday, December 24, 2009

Porting Enterprise Application to any App Server

Few months back I had to Port MDM Application from Glassfish to JBOSS. I found few issues while porting. This blog helps developing/porting any Enterprise Application to any Application Server.

Here are the few things we need to consider.

Registering MBean Server: Generally we will find Default domain of Appserver and setMbeanServer.That doesn't work with all the Appserver especially with JBOSS Server.
Genral Method of Setting MbeanServer.
synchronized void setMBeanServer() {
List srvrList = MBeanServerFactory.findMBeanServer(null);
Iterator slist = srvrList.iterator();
while (slist.hasNext()) {
MBeanServer mBeanServer = (MBeanServer) slist.next();
if (mBeanServer.getDefaultDomain().equals("DefaultDomain")) {
mMBeanServer = mBeanServer; break;
}
} if (mMBeanServer == null) {
//Logmessage
}
}

for Jboss Server advisable approach is .
private synchronized void setMBeanServer() {
List srvrList = MBeanServerFactory.findMBeanServer(null);
Iterator slist = srvrList.iterator();
while (slist.hasNext()) {
MBeanServer mBeanServer = (MBeanServer) slist.next();
if (mBeanServer.getDefaultDomain() != null) {
if (mBeanServer.getDefaultDomain().equals("DefaultDomain")){
mMBeanServer = mBeanServer;
break;
}
} else {
MBeanServer server = MBeanServerLocator.locateJBoss();
mMBeanServer = server;
mLogger.info("ABC001: Pointed to JBOSS srver.");
}
} if (mMBeanServer == null) {
mLogger.severe("ABC002: Could not find the BeanServer.");
}
}

Handling JDBC Connections & Transaction:
do not set Autocommit to false when its Oracle XA trasaction, because by default the Autocommit already set and when you try to set it will throw Exception.
User like this.
boolean flag = false;
flag =con.getAutoCommit();
if (flag){
con.setAutoCommit(false);
}

JNDI Lookup:
JNDI Lookup will be different respective to App server.
Example if your JNDI name is jdbc/TestDataSource, In JBOSS it will creates a folder with jdbc and generates and XML file with TestDataSource.xml under deploy folder. It many not happen with other Appserver.

Libraries: do not add any Servlet API libraries,Logger,JSF libraries to your Application.That some times even cause PermSize memory Issue.every Appserver ships with required libraries except in few cases like websphere doesn't ship appserver with JSF libraries.

Authentication: many webapplications uses form based authentication it inclueds confiuring users and roles depends on Appserver. In Glassfish,weblogic....users and roles configured from Admin console but in JBOSS we need to write .propertyfile and place in deploy folder.

JSF webApplication :
  1. Do not use ValueExpressions directly with Scriptlet use managed bean.
  2. DataTable behavior is different in different Appserver.
  3. In JSF its not adivsable to write any scritplet, use Myfaces from Sun Microsystems its very good. we can write application without any single line of Scriptlet code.

    Thank you !!!!!