Monday, July 20, 2009

Migrating J2EE application from from Weblogic to JBOSS application server

1 Objective

Objective of this document provide insights, consideration and configuration changes that needs to be done for migrating the j2ee application from BEA Weblogic application server to JBOSS application server.


2 Assumptions

· Third party libraries used with Weblogic application servers are compatible with the JBoss application server
· If migration requires any JDK version upgrades, those changes are not covered in the scope of the requirement
· Migrations of third party adapters needed to communicate to third party component are not covered.
· Target Jboss version considered is 4.2


3 Migration Process

3.1 Potential issues with migrations

Java enterprise application servers are standard driven and adheres to JEE specifications. Even in that case when we want to migrate j2ee enterprise application from one application server to another application server, there are potential issues like

1. Completeness of Specifications:

Though JEE specification is very comprehensive some of the behaviors are not defined in specification like Class loading , clustering etc. which are critical for application migration

2. JDK compatibility :

Every vendor has implemented JDK like sun Microsystems , Bea Jrocket JDK. There could be subtle different behavior and bugs can be found between different java virtual machine

Following link provides the OS and JDK compatibility for JBOSS Application server 4.2 and 4.3







http://www.jboss.com/products/platforms/application/testedconfigurations/

1. Class loading mechanism


Web-logic class loader policy :

Following diagram depicts the class loader hierarchy for

Weblogic application server







JBOSS Server class loader






For the details about JBOSS class loader hierarchy you can find at
JBOSS Classloader hierarchy



As shown in the above figure the class loading mechanism is different between two application server. While migrating the application, review of class lading hierarchy requirements and isolation level of class loader across various modules ( wars, jars, rars) in the applications are necessary.


4. Different Specification versions

Weblogic (current version) and JBOSS (target version) may be supporting different JEE specification and underling JDK version . IT management needs to take decision about which specification needs to be targeted


5. Use of application server specifics

There could be some weblogic specific components that the applications is using , Typical candidates are
· Security Realms , context lookup, datasource , JMS configuration
· WEbservices developed using weblogic framework
· Proprietary components
· Clustering and caching mechanism , session replications
· Connection to third party systems for e.g integration adapters to systems like SAP, Siebel , People soft


3.2 Migration process Steps

Following diagram represent migration processes

Tuesday, July 14, 2009

Setting Up Default Isolation level on WAS 6.1

Setting a right Isolation level for database operation is critical for performance of the database operation performed in online or batch application.

Following are different isolation levels

1. READ Uncommited
2. READ_COMMITED
3. REPEATABLE_READ
4. Serializable

Read Uncommited provides highest level of concurrancy and best performance, while Serialization provides lowest level of concurrecy , highest level of transaction isolation and lowest performance.

The need of iolstaion level is an application specific requirement and can differ from transaction to transaction.

In J2EE application, isolation level can be set at application server (data source setting level ) as well as application level using declarative configuration. ( In EJB application, it can be defiend in server specific deployment discriptor or in Spring based applciation , it can be defined in the transaction manager configuration using element )

If this is not defined application server defaults it to default transaction level depending upon driver and application server setting

For most drivers, WebSphere Application Server uses an isolation level default of TRANSACTION_REPEATABLE_READ. For Oracle drivers, however, WebSphere Application Server uses an isolation level of TRANSACTION_READ_COMMITTED.

Use the following table for quick reference:
1. Sybase : RR
2. Oracle : RC
3. DB2: RR
4. Informix : RR
5. Cloudscape : RR
6. DB2 : RR
7. SQL Server : RR


• Note: These same default isolation levels are used in cases of direct JNDI lookups of a data source.
• RR = JDBC Repeatable read (TRANSACTION_REPEATABLE_READ)
• RC = JDBC Read committed (TRANSACTION_READ_COMMITTED)

WebSphere 6.1 allows us to specify the default Isolation level as a customproperty on the data source definition.

To Set this Data Source custom property webSphereDefaultIsolationLevel can be used

Data Source custom property : webSphereDefaultIsolationLevel

Possible values : 1, 2, 4, 8

Value JDBC ISOLATION Level DB2 Isolation Level

8 TRANSACTION_SERIALIZABLE Repeatable Read (RR)

4 TRANSACTION_REPEATABLE_READ Read Stability (RS)

2 TRANSACTION_READ_COMMITTED Cursor Stability (CS)

1 TRANSACTION_READ_UNCOMMITTED Uncommitted Read (UR)


Following are the instructions to add custom property for a data source using Administrative console:
1. Configure the JDBC provider using Creating and configuring a JDBC provider using the administrative console and the Data Source using Creating and configuring a data source using the administrative console
2. Expand Resources > JDBC provider >
3. Select the Configured_JDBC_Provider
4. Select DataSource
5. Click on the name of the Data Source for which you want to customize the default Isolation level
6. Under additional properties, click Custom properties
7. Click New to add a new custom property, specifying the name webSphereDefaultIsolationLevel and type the desired value (possible values: 1, 2, 4, 8)
8. Click OK, and save the configuration; resync the node if you are using the Network Deployment Environment.
9. Restart the Application Server to make the custom property active
You can find the details about isolation level to specific to DB2 at following link
http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=/db2/rbafzmstisol.htm



Monday, July 13, 2009

Useful Shortcut for eclipse IDE

Following are useful shortcuts that a developer can leverage on eclipse IDE.

Ctrl + Shift + O : Organize imports
  • Ctrl + Shift + R : Search resources
  • Ctrl + T : Type hierarchy
  • Ctrl + / : Line Comment
  • Ctrl + Shift + T : Open Type
  • Ctrl + O : Open declarations
  • Ctrl + E : Open Editor
  • Ctrl + Shift + F4 : Close all Opened Editors
  • Alt + Shift + R : Rename
  • Alt + Shift + L : Extract to Local Variable
  • Alt + Shift + M : Extract to Method
  • F3 : Open Declaration
  • Alt + Shift + X : Run As…
  • Alt + Shift + D : Debug As…
  • Alt + Shift + W : show the class in the package view.
  • Ctrl+Q : Last edit
  • Alt + Left or Alt + Right : Navigate Left and Right
  • Ctrl + 1 : Quick Fix
  • Ctrl + Space : Content Assist
  • Ctrl + Shift + F : Format code
  • Alt + Shift + S + R : Generate getter and setter methods
  • Monday, June 22, 2009

    Thursday, April 9, 2009

    JBI and Apache Service Mix

    Excellent Video at

    http://parleys.com/display/PARLEYS/Home#slide=1;title=ServiceMix;talk=14123079

    WAS 6.1 issue with log4J

    Apache Commons Logging has a problem with WAS 6.1. Its Log4JLogger either can't be loaded or be reported not compatible with LogFactory.The root cause is WebSphere uses commons-logging and so it's in the root classloader. In addition, WebSphere ships a commons-logging.properties with the following properties set:

    org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImplorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger

    Therefore by default the application will use JDK logging and not log4j.

    The solution is to ensure that the right classloader mode is set and the application has an appropriate commons-logging.properties:

    1. Set application classloader mode as PARENT_LAST.
    2. Also, add a commons-logging.properties to the application classpath with the following entries:

    priority=1
    org.apache.commons.logging.LogFactory=org.apache.commons.logging.impl.LogFactoryImpl

    The priority flag was introduced in Commons Logging 1.1 to allow an ordering based on priority.

    To ensure that an application's commons-logging.properties will take precedence over WebSphere's file, a priority of greater that 0.0 must be set.

    Monday, March 9, 2009

    Creating WS-Security element using ws4j api

    You can create WS Security element <wss:security> using wss4j api
    Following code snippet describe how to attach Security header to SOAP message


    import java.io.File;
    import java.io.IOException;
    import java.io.StringWriter;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.transform.OutputKeys;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerConfigurationException;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.TransformerFactoryConfigurationError;
    import javax.xml.transform.dom.DOMSource;
    import javax.xml.transform.stream.StreamResult;
    import org.apache.ws.security.WSConstants;
    import org.apache.ws.security.message.WSSecHeader;
    import org.apache.ws.security.message.WSSecUsernameToken;
    import org.w3c.dom.Document;
    import org.xml.sax.SAXException;


    public class WSS4JSecurityUtil {

    public static void main(String[] args) {

    WSS4JSecurityUtil util = new WSS4JSecurityUtil();
    // Create UsernameToken
    object
    WSSecUsernameToken wsSecUserNameToken = new
    WSSecUsernameToken();
    // Set user info to UsernameToken
    wsSecUserNameToken.setUserInfo("wsuser", "wspwd");
    // Set password Type
    WSConstants.PASSWORD_DIGEST for digest password or
    //
    WSConstants.PASSWORD_TEST for plain text
    password
    //wsSecUserNameToken.setPasswordType(WSConstants.PASSWORD_TEXT);
    wsSecUserNameToken.setPasswordType(
    WSConstants.PASSWORD_DIGEST);
    org.w3c.dom.Document doc = util.getSoapEnvelopeAsDocument();

    // Create Header element
    WSSecHeader secHeader = new WSSecHeader();
    // Insert Security header to soap envelop document
    secHeader.insertSecurityHeader(doc);
    // build the soap envelope with
    Security header with user token
    Document elementWithDigest = wsSecUserNameToken.build(doc, secHeader);
    printXMLDocument(elementWithDigest);

    }
    private org.w3c.dom.Document getSoapEnvelopeAsDocument() {
    String
    soapenvelopeString = "";
    Document soapEnv = null;
    try
    {
    DocumentBuilderFactory docBuilderFactory =
    DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder =
    docBuilderFactory.newDocumentBuilder();
    soapEnv = docBuilder.parse (new
    File("soapmessage.xml"));
    //
    // normalize text representation
    // soapEnv.getDocumentElement ().normalize
    ();
    // System.out.println ("Root element of the doc is " +
    //
    soapEnv.getDocumentElement().getNodeName());
    //
    // Transformer
    transformer = TransformerFactory.newInstance().newTransformer();
    //
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    //
    ////
    initialize StreamResult with File object to save to file
    // StreamResult
    result = new StreamResult(new StringWriter());
    // DOMSource source = new
    DOMSource(soapEnv);
    // transformer.transform(source, result);
    //
    //
    String xmlString = result.getWriter().toString();
    //
    System.out.println(xmlString);
    } catch (ParserConfigurationException e)
    {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch
    (SAXException e) {
    // TODO Auto-generated catch
    block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO
    Auto-generated catch block
    e.printStackTrace();
    }
    return
    soapEnv;
    }
    public static void printXMLDocument(org.w3c.dom.Document
    document){
    Transformer transformer;
    try {
    transformer =
    TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT,
    "yes");
    // initialize StreamResult with File object to save to
    file
    StreamResult result = new StreamResult(new StringWriter());
    DOMSource
    source = new DOMSource(document);
    transformer.transform(source,
    result);
    String xmlString =
    result.getWriter().toString();
    System.out.println(xmlString);
    } catch
    (TransformerConfigurationException e) {
    // TODO Auto-generated catch
    block
    e.printStackTrace();
    } catch (TransformerFactoryConfigurationError
    e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch
    (TransformerException e) {
    // TODO Auto-generated catch
    block
    e.printStackTrace();
    }
    }
    }

    Blank Space or null String validation using XSD schema

    Regarding null values:

    The W3C Schema "nillable" and "nill" attributes can be used to indicate that an element has a null (nill) value in an XML instance document.
    The "nillable" attribute is used in a schema, and the "nill" attribute is used in an XML instance document.

    For example, the following schema declaration indicates that the element "SomeElement" is nillable (i.e. can be marked as null in an XML instance document):

    <xsd:element name="SomeElement" type="xsd:string" nillable="true"/>



    This declaration allows the following to appear in an XML instance document:

    <SomeElement xsi:nill="true"></SomeElement>



    For a "not null" specification (as you indicate below), simply set the "nillable" attribute in the schema to "false":

    <xsd:element name="SomeElement" type="xsd:string" nillable="false"/>



    Regarding whitespace:

    The W3C Schema "whiteSpace" facet can be used to indicate to an XML processor how whitespace should be handled for an element of datatype string.

    There are 3 possible values:
    (1) preserve - do not normalize (i.e. preserve all whitespace)
    (2) replace - all occurences of tab (#x9), linefeed (#xA), and carriage return (#xD) are replaced with space (#x20)
    (3) collapse - performs the same processing as "replace", plus: collapses contiguous spaces (#x20) to a single space, and removes leading and trailing spaces.

    An example is as follows:


    <xsd:simpleType name="SomeType">

    <xsd:restriction base="string">

    <xsd:whiteSpace value="replace"/>

    </xsd:restriction>

    </xsd:simpleType>

    To define type which allows only not null value you can define simple type as follows

    <xsd:simpleType name="nonEmptyString">

    <xsd:restriction base="xsd:string">

    <xsd:minLength value="1"/>

    <xsd:whiteSpace value="collapse"/>

    </xsd:restriction>

    </xsd:simpleType>


    Sunday, February 15, 2009

    Relevant

    If anything is relevant, that means it has capacity to make difference.

    Information

    Any information is a tool and like most tools can not be of direct help to those who are unable or unwilling to use it or who misuse it

    Defination Of Theory

    Defination of Theory :

    Theory is a coherent set of hypothetical, conceptual and pragmatic principles, forming a general frame of reference for a field of inquiry.