Show TOC Start of Content Area

Procedure documentation Throwing the Exception QuickCarRentalException  Locate the document in its SAP Library structure

 

All three business methods, saveBooking, cancelBooking, and viewActiveBookings, can throw the application-specific exception QuickCarRentalException. For this reason, we must take account of this exception in the local and remote interfaces.

Prerequisites

This graphic is explained in the accompanying textThis graphic is explained in the accompanying text

You have created the exception class QuickCarRentalException.

This graphic is explained in the accompanying textThis graphic is explained in the accompanying text

The structure of your project QuickCarRentalEjb is currently displayed in the J2EE Explorer.

 

Procedure

Throwing QuickCarRentalException in the local interface

 

       1.      In the project structure, expand the QuickCarRentalEjb ejb-jar.xml node and double-click the name of the session bean QuickOrderProcessorBean, if you have not already done so.

       2.      In the overview that appears, choose Navigate to Local Interface.

The Java Editor opens and displays the source code of the local interface QuickOrderProcessorLocal.

       3.      Add throws QuickCarRentalException  to the end of each method (before the semi-colon).

       4.      To add the import statements, choose Source Organize Imports from the context menu.

The source code now looks like this:

package com.sap.engine.examples.ejb.quickcarrental;

import javax.ejb.EJBLocalObject;

 

import com.sap.engine.examples.util.QuickBookingModel;

import com.sap.engine.examples.util.QuickCarRentalException;

public interface QuickOrderProcessorLocal extends EJBLocalObject {

 

   /**

    * Business Method.

    */

   public QuickBookingModel saveBooking (

       String vehicleTypeId,

       String dateFromString,

       String dateToString,

       String pickupLocation,

       String dropoffLocation) throws QuickCarRentalException;

 

   /**

    * Business Method.

    */

   public String cancelBooking(String bookingId) throws QuickCarRentalException;

 

   /**

    * Business Method.

    */

   public QuickBookingModel[] viewActiveBookings() throws QuickCarRentalException;

}

 

       5.      Save the contents of the editor by choosing the appropriate icon in the toolbar.

Throwing QuickCarRentalException in the remote interface

       6.      Choose Navigate to Remote Interface and repeat steps 3-5 as appropriate for the remote interface QuickOrderProcessorRemote. Add QuickCarRentalException as a second exception (to  throws RemoteException). Separate the two exceptions with a comma.

The source code of the remote interface now looks like this:

package com.sap.engine.examples.ejb.quickcarrental;

import java.rmi.RemoteException;

 

import javax.ejb.EJBObject;

 

import com.sap.engine.examples.util.QuickBookingModel;

import com.sap.engine.examples.util.QuickCarRentalException;

public interface QuickOrderProcessor extends EJBObject {

 

   /**

    * Business Method.

    */

   public QuickBookingModel saveBooking(

       String vehicleTypeId,

       String dateFromString,

       String dateToString,

       String pickupLocation,

       String dropoffLocation)

       throws RemoteException, QuickCarRentalException;

 

   /**

    * Business Method.

    */

   public String cancelBooking(String bookingId) throws RemoteException , QuickCarRentalException ;

 

   /**

    * Business Method.

    */

   public QuickBookingModel[] viewActiveBookings() throws RemoteException , QuickCarRentalException ;

 

}

 

 

Throwing QuickCarRentalException in the bean class

       7.      Choose Navigate to Bean Class and add throws QuickCarRentalException  to the end of the method header of the methods saveBooking, cancelBooking, and viewActiveBookings (before the curly bracket { ), in the JavaBean class QuickOrderProcessorBean.

Then add the necessary import statements by choosing Source -> Organize Imports from the context menu. Finally, save the contents of the editor.

The source code now looks like this:

 

   /**

    * Business Method.

    */

   public QuickBookingModel saveBooking(

      String vehicleTypeId,

      String dateFromString,

      String dateToString,

      String pickupLocation,

      String dropoffLocation) throws QuickCarRentalException {

      // TODO : Implement

      return null;

   }

   /**

    * Business Method.

    */

   public String cancelBooking(String bookingId) throws QuickCarRentalException {

       // TODO : Implement

       return null;

   }

 

   /**

    * Business Method.

    */

   public QuickBookingModel[] viewActiveBookings() throws QuickCarRentalException  {

       // TODO : Implement

       return null;

   }

 

 

Result

The three business methods saveBooking, cancelBooking, and viewActiveBookings can now throw the application-specific exception QuickCarRentalException.

 

Next step:

Implementing the saveBooking() Method

 

 

End of Content Area