Commit Priority for transaction Resources in Websphere!


Recently we faced a situation where in DB commits which were issued before the JMS puts, were not actually reflecting in the database.

To elaborate further, consider this…

  1. A MQ message arrives on a Queue say Q1.
  2. Corresponding MDB(for Q1) gets the message and starts processing.
    1. Creates some DB records.
    2. Puts a MQ message with DB information, say primary key, on another queue Q2.
  3. MDB, for Q2, gets the message and starts processing.
    1. Fetches DB information as created in Step 2.a and FAILS with “ENTITY WITH KEY NOT FOUND IN THE DATABASE” ???????????

Where the hell did it go?

After some digging/retesting with enhanced logging we concluded that even though the commit to DB was issue before MQ put, because there was a DB failover which happened at the same time and since the DB was not available momentarily WAS proceeded with the next resource commit, which in this case happen to be the MQ PUT.

What was supposed to happen?

  1. A global transaction is started
  2. MQ resource branch …0000000000000000000000000001 (to GET a message from the Q1)
  3. Oracle resource branch …0000000000000000000000000002 (is added for the database work)
  4. MQ resource branch …0000000000000000000000000003 (is added to PUT a message to Q2)


  1. WebSphere TM prepares …0000000000000000000000000003(MQ.PUT)
  2. WebSphere TM prepares …0000000000000000000000000002(DB.COMMIT)
  3. WebSphere TM prepares …0000000000000000000000000001(MQ.GET)


  1. WebSphere Tm commits …0000000000000000000000000001(MQ.GET)
  2. WebSphere Tm commits …0000000000000000000000000002(DB.COMMIT)
  3. WebSphere Tm commits …0000000000000000000000000003(MQ.PUT)

What ACTUALLY happened?

  1. WebSphere Tm commits …0000000000000000000000000001 (MQ.GET)
  2. WebSphere Tm commits …0000000000000000000000000002 (DB) —-> Oracle commit delay, so ignored for now and move to the next resource.
  3. WebSphere Tm commits …0000000000000000000000000003 (MQ.PUT)
  4. WebSphere Tm commits …0000000000000000000000000002 (DB) -> retried/wait longer and success

The order would have been accurate when and only when there is no oracle commit delay caused by the DB data source. However if there is a commit delay/failover probably, the logic of the IBM TRANSACTION MANAGER is to temporarily skip it (it will retry/wait later) and move on to the next resource with the same commit order. ALTHOUGH WE ARE NOT ALLOWED TO DO SO, and to avoid even further delays with IBM support, we know for sure this logic because we’ve reverse engineered the IBM TRANSACTION MANAGER code. Because of this logic, if all the resources have the same commit order or no commit order specified, the commit steps that you will see in case of oracle commit delay is the following.


Specify a commit order on your resources. More on commit priority…


If you have specified a commit order as indicated earlier, the IBM TRANSACTION MANAGER will not skip the commit and not move on to the next resource commit, it will wait/retry until the DB is effectively committed.

  1. WebSphere Tm commits …0000000000000000000000000001 (MQ.GET)
  2. WebSphere Tm commits …0000000000000000000000000002 (DB) —-> Oracle commit delay, but wait and retry before attempting the commit on MQ.PUT data source

10. WebSphere Tm commits …0000000000000000000000000003 (MQ.PUT)

Method Local Inner Class ! REWORKED!

Today I got a comment on my blog entry HERE.

When I went through my blog again, I was surprised to see that the thing I explained there was not right, probably at that time my understanding was not good enough. So I apologize for providing the wrong information. I will explain it again here :
Considering the same example :

class MyClass{
public void showValue(){
final int x = 0;
class MyInnerClass{
public void showOuterVar(){
System.out.println(“Hi I am method local Inner Class” + x);
Now as I explained earlier, the local variables of the method live on the stack, and exist only for the lifetime of the method. As we know that the scope of a local variable is limited to the method the variable is declared in so, When the method ends, the stack frame is blown away and the variable is history. But even after the method completes, the inner class object created within it might still be alive on the heap if, for example, a reference to it was passed into some other code and then stored in an some variable. Because the local variables are not guaranteed to be alive as long as the method-local inner class object, the inner class object can’t use them.
So we mark the local variables as final. When marked final now our class can use it.

Here is the correct reason :
As a part of optimizing the java code, what JAVA Programmers at SUN did, they made the JVM do some WORK, So in this case when this class is compiled there will be two class files (MyClass.class & MyClass$MyInnerClass.class) and the the value of the final variable is stuffed in the inner class i:e: we will have a variable “val$x” in the inner class. Compiler does this because it knows that the variable is final so there is no harm in inserting the value as it is, in the class. You probably won’t be able to see this in your compiler class but it does this way only. The fact can be verified in another way. When you open you class file of the inner class you will see a variable “this$0”, this is actually a reference to the outer class, this is the reason that you can access the outer class variables without any reference. So this is it works. I had a lot of discussion among my friend before writing this and we decided on this only. 🙂
So if anyone gets to know a better reason, Please do share with us. Thanx. enjoy.

Axis2-SOAP-Header problem

Hello everybody again.
Currently I am working with web-services, and my current implementation of the project uses Axis2. Few days back I was stuck with a very weird problem. Scenario was like this.
I have a Web-Application(WA) which is supposed to call a web-service (WS1) which in turn will forward the request to another web-service (WS2) which in turn will forward the request to final web-service(WS3). I have made a generic stub which is used to call any web-service(And I have disabled the header adding code inside this stub because of project requirement.) So the WA was preparing a document and sending it to the WS1 using the generic stub, Now WS1 does some processing and send it to WS2 using the same generic stub, and WS2 again sends it to WS3 using the same generic stub. Now my requirement was that there should not be any SOAP Header in my requests because if it exists then the document will fail the validation. So the problem was that when the document was reaching WS1 it was not having any header and it passed the validation test but when it reaches the WS2 it failed validation. When I traced the log I found that it was having a SOAP Header.
It was very weird since the same stub was being used so how cum there were two documents being generated one with header and the other without header.
After tracing all the logs I didn’t found anything. So finally I used the soap-monitoring tool to see what actually is being transmitted on wires from one WS to the other. Then I came to know, when one WS is sending the document to the other WS it is adding SOAP Header into the document and after a some brain storming I concluded that it does so because by default addressing is enabled at the global level and it is the addressing which was responsible for doing this.
So I disabled the addressing module and it worked. Now the document being passed from one WS to the other WS is not having the SOAP header. 😀
To disable the addressing module you simply go to axis2.xml file and find this line.

<module ref=”addressing”/>

Comment this line and the addressing module is disabled.

Axis2 Hibernate Problem

Hi all, So I am back with another problem->solution, Some days back a guy pinged me up and asked for help with a problem which I found that I also have faced a long time back while in one of my project. The problem is integration of Hibernate with Axis2. Though I myself didn’t solve the problem at that time because we have dropped the idea of using hibernate for some other reasons. But this time this guy himself solved the problem (cheers for him) and I am sharing the solution with you all as I also tried my hand on it and it worked.

I will explain with an example.

I have to create a web service which will receive 3 parameters from the client and persist them into the database using Hibernate. Not a big task :P. So I created a wsdl, generated the classes using axis2’s “wsdl2java“ command and put my own business logic, created the hibernate configuration and mapping files and simply deployed the aar file with the axis2 which further was deployed as a web application into the JBoss AS . The structure of my application is like this :


data (package)

o service (package

§ business ( package )

· (class)

· DataBeam.hbm.xml (class mapping file)

· ( business class)

§ Core (package with generated classes for web service)






§ Persistence


Lib ( libraries used in my application)


o DSService.wsdl

o Services.xml


And finally I successfully deployed my application. But when I tried to execute it using a client, it gave an error, it didn’t found the hibernate.cfg.xml file. Here was what I saw on the JBoss console

2009-02-26 09:41:08,609 INFO [data.service.core.DSServiceSkeleton] Document recieved : <wsdl:dataRequest xmlns:wsdl=”; xmlns:soapenv=””&gt;





2009-02-26 09:41:08,656 INFO [data.service.core.DSServiceSkeleton] Values recieved :

2009-02-26 09:41:08,656 INFO [data.service.core.DSServiceSkeleton] Name : bhupesh

2009-02-26 09:41:08,656 INFO [data.service.core.DSServiceSkeleton] Age : 25

2009-02-26 09:41:08,671 INFO [data.service.core.DSServiceSkeleton] Sex : male

2009-02-26 09:41:08,671 INFO [] insertData() method called…

2009-02-26 09:41:08,671 INFO [] execute() method called…

2009-02-26 09:41:08,687 INFO [data.service.persistence.HibernateUtil] static block of HibernateUtil class

2009-02-26 09:41:08,781 INFO [org.hibernate.cfg.Environment] Hibernate 3.2.4.sp1

2009-02-26 09:41:08,796 INFO [org.hibernate.cfg.Environment] not found

2009-02-26 09:41:08,812 INFO [org.hibernate.cfg.Environment] Bytecode provider name : javassist

2009-02-26 09:41:08,812 INFO [org.hibernate.cfg.Environment] using JDK 1.4 java.sql.Timestamp handling

2009-02-26 09:41:09,000 INFO [org.hibernate.cfg.Configuration] configuring from resource: /hibernate.cfg.xml

2009-02-26 09:41:09,000 INFO [org.hibernate.cfg.Configuration] Configuration resource: /hibernate.cfg.xml

2009-02-26 09:41:09,000 ERROR [org.apache.axis2.transport.http.AxisServlet] java.lang.ExceptionInInitializerError

2009-02-26 09:41:09,015 ERROR [org.apache.catalina.core.ContainerBase] Servlet.service() for servlet AxisServlet threw exception


So I found that it is not able to load the configuration from the hibernate.cfg.xml file.

Now this problem is resolved if you put your file configuration file inside the Axis2/WEB-INF folder as the axis2 class loader and also if you have to put the hibernate jars inside Axis2/WEB-INF/lib. But this is not a good solution.

Solution to this problem :

Axis2’s service class loader prime use case is service isolation, hot deployment and hot updates. So Axis2 creates a new class loader for every service and carefully manages which jars are available in that class loader. One common problem is that an external project uses a Thread Context class loader to load classes or resources from its environment. (TCCL-Thread Context Class Loader ) instead of trying to use the classloader that the class itself was loaded with. So to facilitate this mechanism you can specify a parameter in your services.xml file as under.( from the wso2 site )


<service name=“DSService”>

<!– added for loading libraries files from the lib folder inside aar file –>

<parameter name=“ServiceTCCL”>composite</parameter>

. . . .

. . . .

<!– More configurations as per your service à



By doing this libraries inside your aar file will be accessed.

Another Problem

Now class loading problem was solved but still axis2 was not able to find the mapping file.

Since I have explained before that Axis2 has the notion of service isolation where each service/modules gets its own class loader. Using this class loader you can access any resource that you put into your service archive.

You can do this as under within your HibernateUtil class.

AxisService axisService = MessageContext.getCurrentMessageContext().getAxisService();

ClassLoader serviceClassLoader = axisService.getClassLoader();

URL configURL = serviceClassLoader.getResource(“hibernate.cfg.xml”);

sessionFactory = new Configuration().configure(configURL).buildSessionFactory();

Work Done 😉

Now When you deploy your application and play with it.

My data was successfully persisting into the database.

Deploying Entity Bean on JBoss 5

Hello everyone, Now a days I am trying my hands on EJB 3.0. I have been experimenting
with EJB 3.0 on JBoss application Server. I went on many forums and found that some of
you people are facing problems deploying Entity Beans same as I did in the begining,
So i thought of writing on it n giving a working example.
I have gone through “Enterprise java beans 3.0” book by oreilly. its a very nice book.
My example is also from the same book.
I will start with the example as you people can go through the definition n all from
the book. Though you can get this code from book too m also writng it so that everything
should be in a rytdhm 😛

One more thing you can code entity bean either using annotations or by specifying the
mappings in a mapping file named “orm.xml”. I will give an example based on the mapping
file, I you guys want an example using annotations refer to the unlined link. He is my
colleague and a good friend, he has explained clearly about the example and much more
concepts of the entity beans.

we will start with code now
This is our customer class : ENTITY BEAN

package com.titan.domain;
* @author bhupesh
public class Customer implements Serializable {
private int id;
private String firstName;
private String lastName;
public int getId() {
return id;
public void setId(int id) { = id;
public String getFirstName() {
return firstName;
public void setFirstName(String firstName) {
this.firstName = firstName;
public String getLastName() {
return lastName;
public void setLastName(String lastName) {
this.lastName = lastName;

We Will need a session bean which will be responsible for persisting the object into
the database, though the actual work is done by an ENTITY MANAGER
package com.titan.travelagent;
import com.titan.domain.Customer;;
* @author bhupesh
public interface TravelAgentRemote {
public void createCustomer(Customer p);
public Customer findCustomer(int id);
package com.titan.travelagent;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import com.titan.domain.Customer;
* @author bhupesh
public class TravelAgentBean {
@PersistenceContext(unitName=”titan”)private EntityManager manager;
public void createCustomer(Customer cust){
public Customer findCustomer(int id){
return manager.find(Customer.class, id);

ORM Mapping file is :
<?xml version=”1.0″ encoding=”UTF-8″?>
<orm:entity-mappings version=”1.0″
xsi:schemaLocation=” orm_1_0.xsd “>
<orm:description>ORM file for mapping Customer entity!</orm:description>
<orm:entity access=”PROPERTY” class=”com.titan.domain.Customer” name=”customer”>
<orm:table name=”CUSTOMER_INFO” />
<orm:id name=”id”>
<orm:column name=”id” nullable=”false” column-definition=”integer”/>
<orm:basic name=”firstName” >
<orm:column length=”20″ name=”FIRST_NAME” nullable=”false” />
<orm:basic name=”lastName” >
<orm:column length=”20″ name=”LAST_NAME” nullable=”false” />

Now we also need a persistence.xml file which goes into the META-INF directory
here is it :

<persistence:persistence version=”1.0″
xsi:schemaLocation=” persistence_1_0.xsd “>
<persistence:persistence-unit name=”titan”>
Persistence unit name is titan
<persistence:property name=”” value=”create” />
<persistence:property name=”hibernate.dialect” value=”org.hibernate.dialect.Oracle9iDialect” />

Note one thing
you have to give like this. Firstly I tried by giving only “orm.xml” and when I packaged &
deployed the jar it gave an error stating that the mapping file could not be found.
Then i tried another bad thing, i put this file into the src directory which ultimately came into
the bin folder. When I deployed the jar to my surprise it worked. 😛 Anyway its not a good
programming practice. So i tried giving in the above way META-INF/orm.xml and it worked fine.

JAR Structure

Thats all about in how to deploy Entity Beans on JBoss 5. Wait for more to come in EJB 3.0
If you still have any queries then feel free to contact me.

Method Local inner Classes! Confusion.

Last month when I was preparing for SCJP exam, I came through many new things in Java Language, some things were pretty confusing too. While going through the Inner Classes chapter I came through a problem. As we know we can define a class within a method, likewise :

Class MyClass{

private int x;

public showValue(){

class MyInnerClass{

System.out.println(“Hi I am method local Inner Class”);



A method-local inner class can be instantiated only within the method where the inner class is defined i:e: no other code running in any other method—inside or outside the outer class—can ever instantiate the method-local inner class. But, the inner class object cannot use the local variables of the method the inner class is in. The local variables of the method live on the stack, and exist only for the lifetime of the method. As we know that the scope of a local variable is limited to the method the variable is declared in. When the method ends, the stack frame is blown away and the variable is history. But even after the method completes, the inner class object created within it might still be alive on the heap if, for example, a reference to it was passed into some other code and then stored in an instance variable. Because the local variables aren’t guaranteed to be alive as long as the method-local inner class object, the inner class object can’t use them.

So we mark the local variables as final. When marked final now our class can use it.

But How?

I didn’t knew where the local final variables are stored. Actually if you go through the specification of the JVM you will come to know that JVM defines various runtime data areas that are used during execution of a program. Some of these data areas are created on Java virtual machine start-up and are destroyed only when the Java virtual machine exits. Other data areas are per thread. Per-thread data areas are created when a thread is created and destroyed when the thread exits.

Different areas are :

1. The PC Register

2. Stack

3. Heap

4. Method Area

5. Runtime Constant Pool

6. Native Method Stack

I will not explain each of them here, for this you can refer to the Java virtual Machine Specifications.

The point of our discussion is where are final variables stored. They are stored in Runtime Constant Pool .

A runtime constant pool is a per-class or per-interface runtime representation of the constant_pool table in a class file. It contains several kinds of constants, ranging from numeric literals known at compile time to method and field references that must be resolved at run time. The runtime constant pool serves a function similar to that of a symbol table for a conventional programming language, although it contains a wider range of data than a typical symbol table.

Each runtime constant pool is allocated from the Java virtual machine’s method area. The runtime constant pool for a class or interface is constructed when the class or interface is created by the Java virtual machine. The following exceptional condition is associated with the construction of the runtime constant pool for a class or interface:

  • When creating a class or interface, if the construction of the runtime constant pool requires more memory than can be made available in the method area of the Java virtual machine, the Java virtual machine throws an OutOfMemoryError.

Accessing SSL enabled Web Services

<!– @page { size: 8.5in 11in; margin: 0.79in } P { margin-bottom: 0.08in } –>

This document will guide you in Consuming a Web Service over a HTTPS protocol.

I am using AXIS2 for deploying my Web Service and hence here I will present you with an example of making a client for a Web Service ( Version ) which comes deployed in AXIS2.

For security we usually deploy out Web Service over the HTTPS protocol. As you must be knowing HTTPS protocol uses Digital Certificate for the authentication and to ensure that no one else except the the authenticated parties may access/tamper the data.

Since in my previous post i:e: I described how to enable the JBOSS Application Server.

There we created a keystore ( which contains a certificate ).

Now we have to export the server certificate so that clients can use it. For exporting the certificate we will write

keytool – export -alias <keystore-alias-name> -keystore <keystore-name> -rfc -file <your-cert-name.cer>

then it will prompt for the password ( of the keystore ) : give it and your certificate will be generated by the name.

In my case I did :

keytool -export -alias nsdg_ssl -keystore nsdg.keystore -rfc -file nsdg_temp.cer

and a certificate by name nsdg_temp.cer was generated.

If you want to see the certificate you can write at the terminal :

cat you-cert-name.cer

If a client has to communicate to a server over SSL, it must have a truststore file. Below is given the command which will import the certificate to the client truststore :

keytool -import -alias <trust-store-name> -file <cert-file-name.cer> -keystore <client-trust-store>

FINALLY We will write a JAVA CLIENT which will call a web service.

To access a secure website from a web service client you need to set the following properties : and

The value of should be the path of your truststore file. You must have already imported the certificate to this truststore from th server to which you are going to communicate.

This is how i did :


System.setProperty(“”, “rmi+ssl”);

My Client looked like :

import javax.xml.namespace.QName;







import org.apache.axis2.AxisFault;

import org.apache.axis2.addressing.EndpointReference;

import org.apache.axis2.client.*;


* @author bhupesh


public class VersionJavaClient {

private EndpointReference targetEPR;

private QName operationName = new QName(“version”);

public static void main(String[] args) throws AxisFault {



System.setProperty(“”, “rmi+ssl”);

VersionJavaClient client = new VersionJavaClient();



private void getAxisVersion() throws AxisFault {

System.out.println(“getAxisVersion() STARTS”);

OMElement payload = createRequestMethod();

ServiceClient serviceClient = new ServiceClient();

Options options = new Options();

options.setTo(new EndpointReference(“;));



OMElement result = serviceClient.sendReceive(payload);

System.out.println(“getAxisVersion() ENDS”);

if (result != null) {

System.out.println(“RESULT WILL BE DISPLAYED NOW”);


} else {

System.out.println(“Got Null Result”);


private OMElement createRequestMethod() {

System.out.println(“createRequestMethod() :: creating envelope”);

OMFactory fac = OMAbstractFactory.getSOAP11Factory();

OMNamespace omNs = fac.createOMNamespace(“http://localhost/d2&#8221;, “d2”);

OMElement requestMethod = fac.createOMElement(“getVersion”, omNs);

OMElement firstElement = fac.createOMElement(“firstElement”, null);



System.out.println(“createRequestMethod() :: request method returned..”);

return requestMethod;


private void displayResult(OMElement result) {

System.out.println(“displayResult() :: STARTS”);

try {

XMLStreamWriter writer = XMLOutputFactory.newInstance()


//result.serialize(new OMOutputImpl(writer));


System.out.println(“trying to serialize the result. FLUSHING….”);

System.out.println(“displayResult() :: ENDS”);


} catch (Exception e) {

System.out.println(“got Exception while printing”);