JMS message does not roll back when an exception occurs in an EJB exposed as a Web Service
 Technote (troubleshooting)
 
Problem(Abstract)
When a stateless session Enterprise Java™ Bean (EJB) is exposed as a web service using SOAP/JMS as the transport, the message-driven bean that is used by the web services engine and the EJB are not in the same transaction. This has a strong effect on one-way SOAP/JMS functionality. Messages can become permanently lost if there is a transaction rollback in the EJB.
 
Cause
For a SOAP/JMS web service, the web service client sends a request to invoke the web service by using JMS to send a SOAP message to a message queue. A message-driven bean is provided by WebSphere™ Application Server to get messages from the queue. When the message-driven bean gets a SOAP message, it routes the message to the appropriate stateless session EJB that is acting as the web service.

There are two possible transactional behaviors that could occur between the message-driven bean and the target EJB:

  1. The message-driven bean and the EJB are not in the same transaction. The transaction in the message-driven bean is suspended before the message is sent to the EJB. Therefore, if a transaction rollback occurs in the EJB, the message-driven bean's transaction does not rollback.

    This presents some limitations. As long as the message-driven successfully gets the message from the queue, the message will be permanently removed from the queue, even if a rollback occurs in the EJB.

    This is the behavior in WebSphere Application Server V5.0.2.4 and above and WebSphere Application Server V5.1.0.3 and above due to APAR PQ84107. This is also the default behavior in WebSphere Application Server V6, although it can be changed (details in the Solution section).

  2. The message-driven bean and the EJB are in the same transaction. Therefore, if a transaction rollback occurs in the EJB, the message-driven bean's transaction does rollback, and the message is returned to the queue.

    This is the behavior in WebSphere Application Server V5.0.2.3 and below and WebSphere Application Server V5.1.0.2 and below. It is possible to get this behavior to occur in WebSphere Application Server V6 with the fixes for APARs PK08430 and PK17001. Both of these APARs are included in Fix Pack 9 (V6.0.2.9) and above.
 
Resolving the problem
For V5.0 and V5.1:

You must create your own mechanism to ensure that messages are not lost completely if a transaction rollback occurs in the EJB. One possible solution is to use a JAX-RPC handler to backup messages that are being processed.

If one-way messaging is used, the application developer must devise methods to recover and keep track of messages that cause the rollback. There is no possibility of using a backout queue.

For 6.0:

Install Fix Pack 9 (V6.0.2.9) or above to allow the message-driven bean and the EJB to be in the same transaction. If you are running the web service client in WebSphere Application Server, you can set the property Constants.ENABLE_TRAN_ONEWAY on the Call or Stub objects.


// Example begins
import com.ibm.websphere.webservices.Constants;
import javax.xml.rpc.Call;
import javax.xml.rpc.Stub;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import java.util.Properties;


// Example 1
// DII programming model using Call object
//
ServiceFactory factory = ServiceFactory.newInstance();
QName svcQname = new QName(YOUR_TEST_NS, "yourService");
Service svc = factory.createService(svcQname);

QName portQname = new QName(YOUR_TEST_NS, "yourPort");
Call call = svc.createCall(portQname);
...
call.setProperty(Constants.ENABLE_TRAN_ONEWAY, new Boolean(true));
...

// Example 2
// Using static stub programming model
//
Properties prop = new Properties();
InitialContext ctx = new InitialContext(prop);
Service service =
(Service)ctx.lookup("java:comp/env/service/yourService");

Bean yourBean = (Bean)service.getPort(portQname, Bean.class);
((Stub)Bean)._setProperty(Constants.ENABLE_TRAN_ONEWAY,new
Boolean(true));

// Example ends



 
 
Cross Reference information
Segment Product Component Platform Version Edition
Application Servers Runtimes for Java Technology Java SDK
 
 


Document Information


Product categories: Software > Application Servers > Distributed Application & Web Servers > WebSphere Application Server > Web Services (for example: SOAP or UDDI or WSGW or WSIF)
Operating system(s): Windows
Software version: 6.0.2
Software edition:
Reference #: 1213290
IBM Group: Software Group
Modified date: Sep 28, 2006