migrating WebLogic EJB programs to JBoss _jsp programming

Source: Internet
Author: User
Tags reserved xslt java web jboss jboss application server jboss server

The WebLogic server is a top-level commercial application server. But for a small developer, JBoss, a standards-based application server that develops the source code, can be used to replace a commercial application server like WebLogic or WebSphere. Unfortunately, applications developed in WebLogic cannot be deployed in JBoss. The JBoss Migration Service provides us with the support to migrate applications to JBoss. Instead, it is possible to migrate applications to JBoss by migrating vendor-specific deployment file information to JBoss. To demonstrate the process of migrating an application to JBoss, we will migrate an EJB application with an Oracle database developed in WebLogic to an JBoss application server with a MySQL database.

   Pre-installation software

To configure the JDBC connection for the MySQL database, you need to download the MySQL database driver class.

1. Download the MySQL JDBC driver. jar file

2. Download and install the MySQL database server

3. Download and install the JBoss 4.0 application Server

To develop a Java application, we will use it and XSLT to convert the WebLogic deployment file into an JBoss deployment file. The deployment file can also be converted using the XSLT tool.

   Overview

Applications developed in WebLogic cannot be deployed in JBoss without modification. The deployment file for the JBoss application is different from the WebLogic deployment file. In this article, we will migrate an entity (entity) EJB Application sample developed in WebLogic into JBoss by converting the WebLogic deployment file into an JBoss deployment file.

The sample application contains a catalog entity EJB. The EJB's Bean Class (Catalogbean.java), the Remote Interface (Catalog.java), and the Home Interface (Cataloghome.java) are in the Weblogic-jboss-resources.zip sample file for the download link in this article. We will use the MySQL open source database to configure the JBoss application. Deploying an WebLogic EJB application into JBoss does not require modifying the entity EJB class, only the deployment files for that EJB.

  Configuring JBoss and MySQL

MySQL is an open source database that is suitable for open source projects and small organizations. Some of the following modifications are required to configure the JBoss and MySQL databases.

  Configuring the JBoss classpath

To use JBoss 4.0 and MySQL, we first copy the driver class. jar file (Mysql-connector-java-3.0.9-stable-bin.jar) to the <JBoss>/server/default/ Lib directory. The <JBoss> is the directory where the JBoss application server is installed. The. jar and. zip files for the Lib directory are contained in the CLASSPATH (classpath) of the JBoss server.

   Configuring a MySQL data source

In order to use the MySQL data source, you need to copy the <JBoss>/docs/examples/jca/mysql-ds.xml to the <JBoss>/server/default/deploy directory. When the JBoss server is started, the data source configuration files in the Deploy directory are deployed. Follow these steps to modify the Mysql-ds.xml configuration file:

· Set <driver-class/> to Com.mysql.jdbc.Driver, <connection-url/> set to jdbc:mysql://localhost/<database>, Where <database> is the MySQL database. The value of the <database> can be set to test, which is the sample database in MySQL.

· Specifies the Jndi name of the data source in the Jndi-name element.

· Specifies the username and password to connect to the MySQL database. By default, the root username does not require a password.

· Specify the type-mapping element as MySQL. The type-mapping element specifies the predefined database type mapping relationships in the Standardjbosscmp-jdbc.xml deployment file. For MySQL databases, type mappings are MySQL.

The modified Mysql-ds.xml is shown below:

<?xml version= "1.0" encoding= "UTF-8"?
<datasources>
<local-tx-datasource>
<jndi-name> Mysqlds </jndi-name>
<connection-url> jdbc:mysql://localhost/test </connection-url>
<driver-class> Com.mysql.jdbc.Driver </driver-class>
<user-name> Root </user-name>
<password> </password>
<metadata>
<type-mapping> MySQL </type-mapping>
</metadata>
</local-tx-datasource>
</datasources>

We can obtain a JDBC connection from the data source by providing the data source Jndi name:

InitialContext InitialContext = new InitialContext ();
Javax.sql.DataSource ds = (javax.sql.DataSource)
Initialcontext.lookup ("Java:/mysqlds");
Java.sql.Connection conn = Ds.getconnection ();

   Configure logon Information

Now we modify the Login-config.xml configuration file according to the MySQL database settings. Application policy Mysqldbrealm is necessary in order to log on to the MySQL database. Add the following <application-policy/> element to Login-config.xml:

<application-policy name = "Mysqldbrealm" >
<authentication>
<login-module Code =
"Org.jboss.resource.security.ConfiguredIdentityLoginModule"
Flag = "Required" >
<module-option name = "Principal" > </module-option>
<module-option name = "UserName" >root </module-option>
<module-option name = "Password" > </module-option>
<module-option name = "Managedconnectionfactoryname" >
Jboss.jca:service=localtxcm,name=mysqlds
</module-option>
</login-module>
</authentication>
</application-policy>


By modifying the Mysql-ds.xml and Login-config.xml files, the JBoss 4.0 Server has been configured to use the MySQL database. In addition to some of the previous specific settings, you might need to make some modifications to the JBoss deployment file and the JBoss JDBC configuration file.

If you set up the table The option is selected (by setting the create-table element in Jbosscmp-jdbc.xml to true) to deploy the CMP entity EJB, and the primary key (or unique key) of the MySQL table is longer than 500 bytes, and the application's deployment process generates an SQL syntax in the MySQL database Error. For java.lang.String-type CMP fields, we can subtract the SQL type for Java type java.lang.String by setting it to a lower varchar value in the MySQL type mapping of the Standardjbosscmp-jdbc.xml deployment file The length of a small primary key (or unique key). Another possible problem is the column-name element in the Jbosscmp-jdbc.xml deployment file. If a MySQL table has the same column name as the MySQL reserved word, an error occurs when deploying the Java application in JBoss. The way to solve this problem is to make the column name different from the MySQL reserved word.

   Converting WebLogic EJB applications

After you have established the JBoss server that uses MySQL, you must now convert the WebLogic EJB application to the JBoss EJB application, which involves the modification of the deployment file. WebLogic Entity EJB application consists of EJB deployment files (Ejb-jar.xml, Weblogic-ejb-jar.xml, and Weblogic-cmp-rdbms-jar.xml), Bean Class (Catalogbean.java) , a remote interface (Catalog.java), and a Home interface (Cataloghome.java). In order to deploy the entity EJB on the WebLogic server, you need to build an EJB. jar file, the structure of this EJB. jar file is as follows:

meta-inf/
Ejb-jar.xml
Weblogic-ejb-jar.xml
Weblogic-cmp-rdbms-jar.xml
Catalogbean.class
Catalog.class
Cataloghome.class

The structure information and application assembly information for the EJB are specified in the deployment file. The structure information includes a description of whether the EJB is a dialog EJB or an entity EJB. The application assembler information in the Ejb-jar.xml deployment file is specified in the Assembly-descriptor element. The Entity EJB deployment files in WebLogic include Ejb-jar.xml, Weblogic-ejb-jar.xml, and Weblogic-cmp-rdbms-jar.xml. The corresponding JBoss deployment files are Ejb-jar.xml, Jboss.xml, and Jbosscmp-jdbc.xml. The conversions between these files are shown below.

Ejb-jar.xml deployment files are the same for both WebLogic and JBoss, except for multiplicity elements. The multiplicity element in the ejb-jar.xml of the JBoss server needs to be capitalized, such as one or many, not one or many.

The Ejb-jar.xml deployment file for the sample entity EJB is included in the sample code. The example ejb-jar.xml defines an entity EJB called "Catalog". This example EJB has CMP Fields Catalogid, Journal, and Publisher. Its primary key field is Catalogid.

Convert Weblogic-ejb-jar.xml to Jboss.xml

The Weblogic-ejb-jar.xml and Jboss.xml deployment files are specific deployment files for the EJB vendor. In order to deploy the WebLogic EJB application to the JBoss application server, the Weblogic-ejb-jar.xml deployment file must be converted to Jboss.xml.

The root element in the Weblogic-ejb-jar.xml is Weblogic-ejb-jar. The root element in the Jboss.xml is JBoss. The element that specifies the Jndi name of an EJB in the Jboss.xml and Weblogic-ejb-jar.xml deployment files is Jndi-name or local-jndi-name. The Weblogic-ejb-jar.xml deployment file for the sample entity EJB in this article is also included in the sample code. The DOCTYPE elements of the Weblogic-ejb-jar.xml deployment file are:

! 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 of the Jboss.xml deployment file is:
! DOCTYPE JBoss Public "-//jboss//dtd JBoss 4.0//en"
"Http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd" >

We convert the deployment file Weblogic-ejb-jar.xml to Jboss.xml through a custom XSLT stylesheet Jboss.xslt (included in the sample code). The stylesheet establishes the Jboss.xml, which is the JBoss file that is equivalent to the WebLogic weblogic-ejb-jar.xml deployment file. The Jboss.xml file generated using the JBOSS.XSLT style sheet is also included in the sample code.

Convert Weblogic-cmp-rdbms-jar.xml to Jbosscmp-jdbc.xml

The Weblogic-cmp-rdbms-jar.xml deployment file specifies the database persistence information for the CMP entity EJB. The Weblogic-cmp-rdbms-jar.xml file contains the table name of the entity EJB, the data source that connects to the database, and the columns that correspond to the Entity EJB CMP field. The Weblogic-cmp-rdbms-jar.xml deployment file for the sample entity EJB is contained in a. zip file that can be downloaded. The JBoss deployment file that specifies the CMP view EJB persistence information is jbosscmp-jdbc.xml.

The root element of the weblogic-cmp-rdbms-jar.xml is the weblogic-rdbms-jar;jbosscmp-jdbc.xml root element is JBOSSCMP-JDBC. The Data-source-name element in the Weblogic-cmp-rdbms-jar.xml file that specifies the data source to connect to the database is equivalent to the DataSource element in the Jbosscmp-jdbc.xml deployment file. Weblogic-cmp-rdbms-jar.xml the Field-map element that specifies the mapping between the entity EJB CMP field and the database table's columns is equivalent to the Cmp-field element in Jbosscmp-jdbc.xml. The dbms-column element of the specified column name in Weblogic-cmp-rdbms-jar.xml is equivalent to the column-name element in Jbosscmp-jdbc.xml. The DOCTYPE of the Weblogic-cmp-rdbms-jar.xml deployment file 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 ' >
Jbosscmp-jdbc.xml's doctype are:
! DOCTYPE jbosscmp-jdbc Public "-//jboss//dtd jbosscmp-jdbc 4.0//en"
"Http://www.jboss.org/j2ee/dtd/jbosscmp-jdbc_4_0.dtd" >


We use the custom XSLT stylesheet Jbosscmp-jdbc.xslt (included in the sample code) to convert the deployment file Weblogic-cmp-rdbms-jar.xml to Jbosscmp-jdbc.xml. The stylesheet establishes Jbosscmp-jdbc.xml, which is an JBoss file that is equivalent to the WebLogic weblogic-cmp-rdbms-jar.xml deployment file. Jbosscmp-jdbc.xml also contains downloads in the. zip file.

The DTD for the WebLogic deployment file differs from the JBoss deployment file. When using a custom XSLT, if additional elements appear in the deployment file, further modifications may be required to convert the WebLogic deployment file to the JBoss deployment file. In the following section, we will deploy this EJB application on the JBoss server.

  Deploying the EJB application in JBoss

After converting the WebLogic EJB deployment file to the JBoss deployment file, you must build a heart EJB. jar file to deploy to the JBoss server. The structure of the JBoss. jar file is as follows:

meta-inf/
Ejb-jar.xml
Jboss.xml
Jbosscmp-jdbc.xml
Catalogbean.class
Catalog.class
Cataloghome.class

To compile the sample EJB classes and interfaces:

Java Catalog.java Catalogbean.java Cataloghome.java

Copy the JBoss deployment files Ejb-jar.xml, Jboss.xml, and Jbosscmp-jdbc.xml to the Meta-inf directory. Use the jar tool to build a. jar file from the JBoss deployment files, classes, and interfaces.

Jar CF Catalogejb.jar Catalogbean.class
Catalog.class Cataloghome.class Meta-inf/*.xml

The process of deploying the JBoss entity EJB application is to copy the. jar file (Entityejb.jar) to the <JBoss> \server\default\deploy directory where <JBoss> is the JBoss-installed directory. When the server is started, the EJB application is deployed on the JBoss server. The deployment (deploy) directory in the JBoss application server corresponds to the application (applications) directory in the WebLogic application server.

   Conclusions

You can migrate the entity EJB applications deployed in WebLogic to the JBoss application server by converting the deployment files. Using similar steps, you can migrate the WebLogic Java Web application to JBoss by converting the Weblogic.xml deployment file to Jboss-web.xml.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.