Identify correct and incorrect statements or examples about the client's view of exceptions received from an enterprise bean invocation.

[Note]

Client's View of Exceptions

A client accesses an enterprise bean either through the enterprise bean's business interface (whether local or remote), through the enterprise bean's remote home and remote interfaces, through the enterprise bean's local home and local interfaces, or through the enterprise bean's web service client view depending on whether the client is written to the EJB 3.0 API or earlier API and whether the client is a remote client, a local client, or a web service client.

The methods of the BUSINESS interface typically DO NOT throw the java.rmi.RemoteException, regardless of whether the interface is a remote or local interface.

/**
 * Local Business Interface
 */

@Local
public interface Calculator {
	public double add(double a, double b);
}
					
/**
 * Remote Business Interface
 */

@Remote
public interface RemoteCalculator {
	public double add(double a, double b);
	public String getServerInfo();
}
					
@Stateless
public class StatelessCalculator implements Calculator, RemoteCalculator {

	public double add(double a, double b) {
		return a + b;
	}
	
	public String getServerInfo () {
		return "This is SCBCD 5.0 Study Guide !";
	}
}
					

The REMOTE HOME interface, the REMOTE interface, and the WEB SERVICE ENDPOINT interface are Java RMI interfaces, and therefore the throws clauses of all their methods (including those inherited from superinterfaces) include the MANDATORY java.rmi.RemoteException. The throws clauses MAY include an arbitrary number of application exceptions.

/**
 * JAX-RPC Service Endpoint Interface
 */
public interface Calculator extends java.rmi.Remote {
	public double add(double a, double b) throws java.rmi.RemoteException;
	public String getServerInfo() throws java.rmi.RemoteException;
}
					

The LOCAL HOME and LOCAL interfaces are both Java local interfaces, and the throws clauses of all their methods (including those inherited from superinterfaces) MUST NOT include the java.rmi.RemoteException. The throws clauses MAY include an arbitrary number of application exceptions.

Application Exception to Local and Remote Clients

If a client program receives an APPLICATION exception from an enterprise bean invocation, the client CAN CONTINUE calling the enterprise bean. An application exception DOES NOT result in the removal of the EJB object.

Although the container does not automatically mark for rollback a transaction because of a thrown application exception, the transaction MIGHT have been marked for rollback by the enterprise bean instance before it threw the application exception OR the application exception MAY have been specified to require the container to rollback the transaction. There are two ways to learn if a particular application exception results in transaction rollback or not:

Application Exception to Web Service Clients

If a stateless session bean throws an application exception from one of its web service methods, it is the responsibility of the container to map the exception to the SOAP fault specified in the WSDL that describes the port type that the stateless session bean implements.

System Exception (java.rmi.RemoteException and javax.ejb.EJBException)

A client receives the javax.ejb.EJBException or the java.rmi.RemoteException as an indication of a failure to invoke an enterprise bean method or to properly complete its invocation. The exception can be thrown by the CONTAINER or by the COMMUNICATION SUBSYSTEM between the client and the container.

If the client receives the javax.ejb.EJBException or the java.rmi.RemoteException exception from a method invocation, the client, in general, DOES NOT KNOW if the enterprise bean's method has been completed or not.

If the client executes in the context of a transaction, the client's transaction may, OR may not, have been marked for rollback by the communication subsystem or target bean's container.

For example, the transaction would be marked for rollback if the underlying transaction service or the target bean's container doubted the integrity of the data because the business method may have been partially completed. Partial completion could happen, for example, when the target bean's method returned with a RuntimeException exception, or if the remote server crashed in the middle of executing the business method.

The transaction may not necessarily be marked for rollback. This might occur, for example, when the communication subsystem on the client-side has not been able to send the request to the server.

When a client executing in a transaction context receives an EJBException or a RemoteException from an enterprise bean invocation, the client may use either of the following strategies to deal with the exception:

If the client chooses to continue the transaction, the client can first inquire about the transaction status to avoid fruitless computation on a transaction that has been marked for rollback. A client that is an enterprise bean with container-managed transaction (CMT) demarcation can use the EJBContext.getRollbackOnly method to test if the transaction has been marked for rollback; a client that is an enterprise bean with bean-managed transaction (BMT) demarcation, and other client types, can use the UserTransaction.getStatus method to obtain the status of the transaction.

Some implementations of EJB servers and containers may provide more detailed exception reporting by throwing an appropriate subclass of the javax.ejb.EJBException or java.rmi.RemoteException to the client.

Professional hosting     Belorussian informational portal         Free SCWCD 1.4 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     IBM Test 000-287. Enterprise Application Development with IBM WebSphere Studio, V5.0 Study Guide     Free Mock Exam Engine