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.

    Wednesday, December 10, 2008

    Validating XML document using XML schema

    The simplest way to validate an XML document is to use a Validator object. This object will perform a validation against the Schema object from which the Validator was created. Schema objects are typically created from SchemaFactory objects. The static newInstance() object allows you to create a SchemaFactory using a preset XML schema. The following code demonstrates this:

    SchemaFactory factory =
    SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = factory.newSchema(new File("mySchema.xsd"));
    Validator validator = schema.newValidator();


    Calling the validate() method on the Validator object performs the actual validation. This method takes at least a javax.xml.transform.Source object, of which you can use a SAXSource or a DOMSource, depending on your preference.

    DocumentBuilder parser =
    DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document document = parser.parse(new File("myXMLDocument.xml"));
    validator.validate(new DOMSource(document));


    Here is a simple source example that shows how to validate an XML document using a World Wide Web Consortium (W3C) XML Schema, sometimes referred to as WXS.

    try {
    // Parse an XML document into a DOM tree.
    DocumentBuilder parser =
    DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document document = parser.parse(new File("myXMLDocument.xml"));
    // Create a SchemaFactory capable of understanding WXS schemas.
    SchemaFactory factory =
    SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    // Load a WXS schema, represented by a Schema instance.
    Source schemaFile = new StreamSource(new File("mySchema.xsd"));
    Schema schema = factory.newSchema(schemaFile);
    // Create a Validator object, which can be used to validate
    // an instance document.
    Validator validator = schema.newValidator();
    // Validate the DOM tree.
    validator.validate(new DOMSource(document));
    } catch (ParserConfigurationException e) {
    // exception handling
    } catch (SAXException e) {
    // exception handling - document not valid!
    } catch (IOException e) {
    // exception handling
    }




    following code shows how one can validate xml document programtically against the schema


    import javax.xml.transform.Source;
    import javax.xml.transform.stream.StreamSource;
    import javax.xml.validation.Schema;
    import javax.xml.validation.SchemaFactory;
    import javax.xml.validation.Validator;


    public void validateXML() {

    // parse an XML document into a DOM tree
    DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document document = parser.parse(new File("instance.xml"));

    // create a SchemaFactory capable of understanding WXS schemas
    SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

    // load a WXS schema, represented by a Schema instance
    Source schemaFile = new StreamSource(new File("mySchema.xsd"));
    Schema schema = factory.newSchema(schemaFile);

    // create a Validator instance, which can be used to validate an instance document
    Validator validator = schema.newValidator();

    // validate the DOM tree
    try {
    validator.validate(new DOMSource(document));
    } catch (SAXException e) {
    // instance document is invalid!
    }


    }

    Tuesday, September 30, 2008

    Web-Services best practices

    Following are different types of the WSDL

    1. RPC

    2. Document

    RPC can be of two types

    1. RPC encoded
    2. RPC literal

    Document style can be of two types

    1. Document Literal
    2. Document Literal Wrapped





    The "wrapped" convention produces document/literal services, and yet it supports an RPC-style programming interface (i.e., it performs automatic marshalling of input parameters and return values).The rules for the "wrapped" convention are fairly simple:

    1. "Wrapped" is a form of document/literal, therefore it must follow all the rules defined for document/literal. When defining a document/literal service, there can be at most one body part in your input message and at most one body part in your output message. You do *not* define each method parameter as a separate part in the message definition. (The parameters are defined in the types section, instead.)

    2. Each part definition must reference an element (not a type) defined, imported, or included in the types section of the WSDL document. These element definitions are "wrapper" elements (hence the name of this convention). You define your input and output parameters as element structures within these wrapper elements.
    3. A wrapper element must be defined as a complex type that is a sequence of elements. Each child element in that sequence will be generated as a parameter in the service interface.
      The name of the input wrapper element must be the same as the operation name.
      The name of the output wrapper element should be (but doesn't have to be) the operation name appended with "Response" (e.g., if the operation name is "add", the output wrapper element should be called "addResponse").
    4. In the binding definition, the soap:binding should specify style="document" (although this is the default value, so the attribute may be omitted), and the soap:body definitions must specify use="literal" and nothing else. You must not specify the namespace or encodingStyle attributes in the soap:body definition.

    Thursday, September 25, 2008

    IBM SOA : 667 Practice Questions and Answers


    Question: 1

    The SOA reference architecture identifies core services including Interaction, Process,
    Information, Partner, Access, and Infrastructure. What is one valid reason for excluding one or
    more of these services in an SOA?
    A. The application is predominantly middleware in nature, eliminating the need for presentation
    services.
    B. The consumer and the provider belong to different companies.
    C. The business sponsor has set budget constraints on solution architecture and the architectural
    components to be included have to be prioritized.
    D. The customer's internal politics make the specification too difficult.

    Answer: A

    Explaination : If the application is middleware only application then there is no need of having presentation service. Interaction service in IBM SOA reference architecture has Interaction services which provides interaction capability t user to interact to the system may not required hence answer is A
    Option B,C, D are irrelevant


    Question: 2

    The IBM SOA Foundation includes services that support business innovation and optimization.
    What should be found in an SOA deployment compliant with the SOA Foundation?
    A. Automatic recognition of marketplace trends and dynamic reconfiguration of services in
    support
    B. Tools to help simulate business design and to predict the effect that design changes might
    have on the business
    C. Alerts generated whenever business efficiency drops below a predefined threshold
    D. An SOA dashboard for executives showing new business opportunities categorized by Return
    on Investment (ROI)

    Answer: B

    The word business innovation and optimization. are important. With tools to simulate business desing ( Busienss Simulator option in IBM Business Modeler) allows to improve Business process design without actually putting the process in production and identify any bottleneck in the system . Hence Answer is B


    Question: 3
    What is the next step while architecting an SOA solution after having just completed documenting
    the business processes?
    A. Determine the operations required to realize each process
    B. Select a business steward for each process and instruct the steward to identify re-usable
    services
    C. Identify the services needed to realize each business process and group them into logical
    components
    D. Identify core and non-core business components

    Answer: C

    Web service Gateway continued


    What is the Web services gateway?

    The gateway provides you with a single point of control, access and validation of Web service requests, and allows you to control which services are available to different groups of Web service users.

    You use the gateway to make available controlled sets of Web services for use within your organization and by external users. The services that each gateway instance makes available as Web services can be a mixture of internal services that are directly available at service integration bus destinations and external Web services.

    This approach provides the following benefits:

    1. The gateway service is made available at a different Web address to the target service, so you can replace or relocate the target service without changing the details for the associated gateway service.

    2. You can have more than one target service (that is, more than one implementation of the same logical service) for each gateway service.
      The gateway service can be made available on a different service integration bus to the target service.

    3. The gateway provides a common interface to the services in each set. Your gateway service users need not know where each underlying service is located, or whether the underlying service is being provided internally or sourced externally, or whether there are multiple target services available for a single gateway service.

      How does the Web services gateway work?
    • When you create a gateway service, you map an existing destination that hosts a target service (either an internal service or an external Web service) to a new Web service that seems to be provided by the gateway.

      Who should use the Web services gateway?


    An enterprise that chooses to share its resources selectively with its business partners and customers, or an enterprise that uses external Web services and wants to make them available internally. IT managers and developers, who deploy resources, can also benefit from this technology.

    What business problems are solved by the Web services gateway?


    The gateway solves the following business problems:

    • Securely "externalizing" Web services: Business applications that are exposed as Web services can be used by any Web service-enabled tool, regardless of the implementation details. To better integrate your business processes, you might want to expose these assets to business partners, customers and suppliers who are outside the firewall. The gateway lets clients from outside the firewall use Web services that are hosted within your enterprise. Using the gateway, you can control access to each of these services.
      Better return on investment: Any number of partners can reuse a process that you develop as a Web service.

    • Use of existing infrastructure: With the gateway, you can make readily available as Web services any combination of your existing internal services and external Web services, no matter how each of those existing services are currently accessed (for example through a service integration bus destination, a Web address or a UDDI registry).
      Protocol transformation: You might use one particular messaging protocol to invoke Web services, while your partners use some other protocol. Using the Web services gateway, you can trap the request from the client and transform it to another messaging protocol.

    Monday, September 15, 2008

    Webservice Gateway

    Webservice gateway is infrastructure component for webservices architecture. It provides single point of control for the webservice invocation.

    It is nothing but soap processing engine that focuses on operation for intermidiatery for soap processing chain. It provides location transparency for service providers from webservice consumers

    Alternately it provides following functionalities

    1. Alter the destination of a message (routing)
    2. Handle custom header tag processing
    3. Apply and remove message level security (WS-Security)
    4. Perform protocol transformation, for example, submit incoming SOAP/HTTP messages to SOAP/JMS

    IBM websphere Security gateway is a Web services infrastructure component that is packaged with the WebSphere Deployment Manager

    Please see following link for more details

    http://www.ibm.com/developerworks/webservices/library/ws-routing/