Labels

Tuesday, June 19, 2012

How to Migrate a JBoss EJB Application to WebLogic?

The JBoss open source application server is commonly used in the development phase of a J2EE project. In the production phase the commercial BEA WebLogic server is preferred because of its enhanced set of features. Without modifications, an application developed in JBoss does not deploy in WebLogic server.
The deployment descriptors for the WebLogic server are different from the JBoss deployment descriptors. An application may be migrated to WebLogic by converting the vendor-specific deployment descriptors to WebLogic. In this tutorial an EJB application developed in JBoss will be migrated to WebLogic with MySQL as the database.
Preliminary Setup
Download and install the BEA WebLogic server (www.bea.com/framework.jsp?CNT=overview.htm &FP=/content/products/weblogic/server). Create a server domain. Download the MySQL JDBC driver JAR file (www.mysql.com/products/connector/j/) and the MySQL database server (www.mysql.com/products/mysql/). Develop a Java application or obtain an XSLT utility to transform the JBoss deployment descriptors to WebLogic deployment descriptors with an XSLT.
Without deployment descriptor conversions, an application developed for JBoss does not deploy in WebLogic. In this tutorial, we will migrate an example entity EJB application developed in JBoss to WebLogic by converting the JBoss deployment descriptors to WebLogic deployment descriptors.
The example application consists of a Catalog entity EJB. The EJB's bean class (CatalogBean.java) is shown in Listing 1. The remote interface (Catalog.java) and home interface (CatalogHome.java) are shown in Listing 2 and Listing 3. The entity EJB classes do not need to be modified for deploying a JBoss EJB application to WebLogic. Only the deployment descriptors for an EJB are required to be modified.
Configuring WebLogic JDBC
In this section a JDBC connection will be configured with the MySQL database from the WebLogic server. First a JDBC Connection Pool is configured and subsequently a JNDI data source to access the JDBC connection pool is configured. Add the MySQL database driver JAR file, mysql-connector-java-3.0.16-ga-bin.jar, to the CLASSPATH variable of the examples server. The CLASSPATH variable for the WebLogic server is set in the <BEA>\user_projects\domains\mydomain\startWebLogic script. Double-click on the startWebLogic script file to start the WebLogic examples server. The server gets started on port 7001. Login to the WebLogic Administration Console with the URL http://localhost:7001/console. The login page for the Administration Console gets displayed. In the login page specify user name and password and log in to the administration console.
In the administration console select the Services>JDBC node. To configure a JDBC connection pool, right-click on the Connection Pools node and select Configure a new JDBCConnectionPool. In the Choose database frame displayed select MySQL as the Database Type. Select MySQL's Driver (Type 4) as the Database Driver. Click on the Continue button. Specify the connection properties for the JDBC connection. In the Database Name field specify test, the example MySQL database. In the Host Name field specify localhost. In the Database User Name field specify root. A password is not required to login to MySQL database with the root username, but the WebLogic server requires a password to be specified. Specify the password for the user name. Click on the Continue button.
In the Test database connection frame, the MySQL driver com.mysql.jdbc.Driver is specified in the Driver Classname field. The MySQL driver is used to establish a connection with the MySQL database. In the URL field specify jdbc:mysql://localhost/test as the connection URL for the database. To test the JDBC connection to the database click on the Test Driver Configuration button. If a connection gets established with the database, a "connection successful" message gets displayed. In the Create and deploy frame, select the server on which the connection pool is to be deployed. Click on the Create and deploy button to deploy the JDBC connection pool on the server. The configured connection gets deployed on the examples server and a node for the connection pool gets added to the JDBC>Connection Pools node. To modify the configuration of the connection pool, select the connection pool node and modify the settings in the different tabs: General, Target and Deploy, Monitoring, Control, Testing, Connections.
Next, configure a data source in the WebLogic server. Right-click on the Services>JDBC node and select Configure a new JDBCTxDataSource. Specify a data source name. In the JNDI Name field specify a JNDI name for the data source - MySQLDS for example. Click on the Continue button. In the Connect to connection pool frame, select a connection pool from the list of connection pools. Select the connection pool that was configured in the previous section and click on the Continue button. In the Target the data source frame select a server as the target server for the data source. Click on the Create button. The configured data source gets deployed on the examples server and a node for the data source gets added to the Data Sources node. To modify the data source select the data source node and modify the settings in the different tabs: Configuration, Target, and Deploy. The data source is available with the JNDI name MySQLDS, which was specified in the data source configuration.
Converting the JBoss EJB Application
In the previous section the WebLogic server was configured with the MySQL database. In this section we'll convert the JBoss EJB application to a WebLogic EJB application, which involves converting the deployment descriptors. A JBoss entity EJB application consists of the EJB deployment descriptors (ejb-jar.xml, jboss.xml, and jbosscmp-jdbc.xml), the bean class (CatalogBean.java), the remote interface (Catalog.java), and the home interface (CatalogHome.java). To deploy the entity EJB in the JBoss server, an EJB JAR file is created; this EJB JAR file has the structure:
META-INF/
  ejb-jar.xml
  jboss.xml
  jbosscmp-jdbc.xml
CatalogBean.class
Catalog.class
CatalogHome.class 





The structural and application assembly information for an EJB is specified in the deployment descriptors. Structural information includes specifying the EJB as a session EJB or an entity EJB. The application assembly information in the ejb-jar.xml deployment descriptor is specified in the assembly-descriptor element. The entity EJB deployment descriptors for JBoss are ejb-jar.xml, jboss.xml, and jbosscmp-jdbc.xml. The corresponding deployment descriptors for WebLogic are ejb-jar.xml, weblogic-ejb-jar.xml, and weblogic-cmp-rdbms-jar.xml. In the following sections the conversion between these files will be described.
The ejb-jar.xml deployment descriptor is the same for WebLogic and JBoss. The ejb-jar.xml deployment descriptor for the example entity EJB is shown in Listing 4. The example ejb-jar.xml defines an entity EJB with the EJB name "Catalog." The example EJB has the CMP fields: catalogId, journal, and publisher. The primary key field is catalogId.
Converting jboss.xml to weblogic-ejb-jar.xml
The weblogic-ejb-jar.xml and jboss.xml deployment descriptors are vendor-specific deployment descriptors for EJBs. To deploy a JBoss EJB application to the WebLogic application server, convert the jboss.xml deployment descriptor to weblogic-ejb-jar.xml. The root element in weblogic-ejb-jar.xml is weblogic-ejb-jar. The root element in jboss.xml is jboss. The JNDI name for an EJB is specified in the jboss.xml and weblogic-ejb-jar.xml deployment descriptors with the jndi-name element or the local-jndi-name element. The jboss.xml deployment descriptor for the example entity EJB is shown in Listing 5. The DOCTYPE element for the weblogic-ejb-jar.xml deployment descriptor is:
<!DOCTYPE weblogic-ejb-jar PUBLIC
"-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN"
"http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd" >

The DOCTYPE for the jboss.xml deployment descriptor is:
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">

Convert the deployment descriptor ejb-jar.xml to the deployment descriptor weblogic-ejb-jar.xml with a custom XSLT stylesheet, weblogic-ejb-jar.xslt, shown in Listing 6. The stylesheet creates weblogic-ejb-jar.xml, the WebLogic equivalent of JBoss's jboss.xml deployment descriptor. The weblogic-ejb-jar.xml file generated with the weblogic-ejb-jar.xslt stylesheet is shown in Listing 7.
Converting jbosscmp-jdbc.xml to weblogic-cmp-rdbms-jar.xml
The weblogic-cmp-rdbms-jar.xml deployment specifies the database persistence information for a CMP entity EJB. The weblogic-cmp-rdbms-jar.xml file includes the table name for an entity EJB, the data source to connect to the database, and the columns corresponding to the entity EJB CMP fields. The JBoss deployment descriptor that specifies the CMP entity EJB persistence information is jbosscmp-jdbc.xml. The jbosscmp-jdbc.xml for the example EJB is shown in Listing 8.
The root element of weblogic-cmp-rdbms-jar.xml is weblogic-rdbms-jar. The root element in jbosscmp-jdbc.xml is jbosscmp-jdbc. The data-source-name element, which specifies the data source to connect to the database in the weblogic-cmp-rdbms-jar.xml file, is equivalent to the datasource element in the jbosscmp-jdbc.xml deployment descriptor. The field-map element, which specifies the mapping of the entity EJB CMP fields to database table columns in weblogic-cmp-rdbms-jar.xml, is the equivalent of the cmp-field element in jbosscmp-jdbc.xml. The dbms-column element, which specifies a column name in weblogic-cmp-rdbms-jar.xml, is the equivalent of the column-name element in jbosscmp-jdbc.xml. The DOCTYPE for the weblogic-cmp-rdbms-jar.xml deployment descriptor is:
<!DOCTYPE weblogic-rdbms-jar PUBLIC
'-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB RDBMS Persistence//EN'
'http://www.bea.com/servers/wls810/dtd/weblogic-rdbms20-persistence-810.dtd'>

The DOCTYPE for jbosscmp-jdbc.xml is:
<!DOCTYPE jbosscmp-jdbc PUBLIC "-//JBoss//DTD JBOSSCMP-JDBC 4.0//EN"
"http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd">

Convert the deployment descriptor jbosscmp-jdbc.xml to weblogic-cmp-rdbms-jar.xml with the custom XSLT stylesheet, weblogic-cmp-rdbms-jar.xslt, shown in Listing 9. The stylesheet creates weblogic-cmp-rdbms-jar.xml, the WebLogic equivalent of JBoss's jbosscmp-jdbc.xml deployment descriptor. weblogic-cmp-rdbms-jar.xml is shown in Listing 10.
The DTDs for the WebLogic deployment descriptors are different from the JBoss deployment descriptors. With custom XSLTs, which may be modified if additional elements are present in the deployment descriptors, the JBoss deployment descriptors get converted to WebLogic deployment descriptors. In the following section, the EJB application is deployed in the WebLogic server.
Deploying the EJB Application in WebLogic
After converting the JBoss EJB deployment descriptors to WebLogic deployment descriptors, create an EJB JAR file to deploy in the WebLogic server. The structure of the WebLogic JAR file is:
META-INF/
  ejb-jar.xml
  weblogic-ejb-jar.xml
  weblogic-cmp-rdbms-jar.xml
CatalogBean.class
Catalog.class
CatalogHome.class 



Compile the example EJB classes and interfaces.
java Catalog.java CatalogBean.java CatalogHome.java
Copy the WebLogic deployment descriptors, ejb-jar.xml, weblogic-ejb-jar.xml, and weblogic-cmp-rdbms-jar.xml, to the META-INF directory. Create a JAR file from the WebLogic deployment descriptors, classes, and interfaces with the JAR (http://java.sun.com/j2se/1.4.2/docs/ tooldocs/windows/jar.html) utility.
jar cf CatalogEJB.jar CatalogBean.class
Catalog.class CatalogHome.class META-INF/*.xml

To deploy the WebLogic entity EJB application, copy the JAR file, CatalogEJB.jar, to the <BEA>\user_proje

cts\domains\mydomain\applications directory, where <BEA> is the directory in which WebLogic server is installed. The EJB application gets deployed on the JBoss server when the server is started. The applications directory in the WebLogic application server is the directory that corresponds to the deploy directory in the JBoss application server.



Conclusion
An entity EJB application developed in JBoss may be migrated to the WebLogic application server by converting the deployment descriptors. Using a similar process, a JBoss J2EE Web application may be migrated to WebLogic by converting the jboss-web.xml deployment descriptor to weblogic.xml.



1 comment:

  1. I found several copies of this article on the net and I'm trying to find the XSLT stylesheet to transform jboss.xml to weblogic-ejb-jar.xml (it is refered as Listing 6 in this article). Can anybody post this file somewhere? A working stylesheet in the other direction (weblogic-ejb-jar.xml -> jboss.xml) would be nice as well. I found this one: http://www.opensource.apple.com/source/JBoss/JBoss-734/jboss-all/varia/src/resources/deployment/resources/5.1/weblogic-ejb-jar.xsl - but it doesn't work for me.

    ReplyDelete