Show TOC Start of Content Area

Procedure documentation Adjusting the Message Handling Locate the document in its SAP Library structure

Use

As an intermediate step in this tutorial, you must adjust the message handling to display the access error messages produced by the EJB if the user does not have the necessary authorizations. These messages are produced by the EJB in the QuickCarRentalException.

To retrieve these error messages, use the _getFaultString() method for the quick car rental exception. Add the processing of this method to each of the methods that will produce access control error messages. These are execute_ActiveBookings(), execute_Save(), and execute_Cancel().

Prerequisites

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

The Web Dynpro perspective is displayed in the SAP NetWeaver Developer Studio.

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

The Web Dynpro project, TutWD_CarRental, is displayed in the Web Dynpro Explorer.

Procedure

...

       1.      Switch to the Web Dynpro perspective.

       2.      Open or return to the Component Controller (under TutWD_CarRental ® Web Dynpro ® Web Dynpro Components ®CarRentalComp).

       3.      Choose the Implementation tab page.

       4.      Add the QuickCarRentalException class to the list of imports.

import com.sap.tut.wd.carrental.model.proxies.QuickCarRentalException;

       5.      Adjust the code in each of the methods to process the QuickCarRentalException. Adjust the code for each of the methods execute_ActiveBookings(), execute_Save(), and execute_Cancel().To retrieve the error message use this class’s _getFaultString() method.

Note

Because the CarRentalCompcontroller handles the errors as the class Exception, but the actual error message is contained in the QuickCarRentalException class, you have to cast the exception accordingly before retrieving the error message.

See the examples below.

Method execute_ActiveBookings()

      try {
      //wdContext.currentActiveBookingsElement().modelObject().execute();
      Request_QuickCarRentalServiceViDocument_viewActiveBookings modObj =
            wdContext.currentActiveBookingsElement().modelObject();
         modObj._setHTTPDestinationName("CarRental");
         modObj.execute();

         wdContext.nodeResponse_ActiveBookings().invalidate();

      } catch (Exception ex) {
        
if (ex instanceof QuickCarRentalException) {
            QuickCarRentalException qex = (QuickCarRentalException) ex;
            msgMgr.reportException(qex._getFaultString(), true);
         } else {
            msgMgr.reportException(ex.getMessage(), false);
     
   }
      }
      //@@end
   }

Method execute_Save()

   public void execute_Save() {
      //@@begin execute_Save()
      try {
      //wdContext.currentSaveBookingElement().modelObject().execute();
         Request_QuickCarRentalServiceViDocument_saveBooking modObj =
            wdContext.currentSaveBookingElement().modelObject();
         modObj._setHTTPDestinationName("CarRental");
         modObj.execute();
         wdContext.nodeResponse().invalidate();

         MessageManager msgMgr =
            (MessageManager) wdComponentAPI.getMessageManager();
         msgMgr.reportSuccess("Success! ");

      } catch (Exception ex) {

         if (ex instanceof QuickCarRentalException) {
            QuickCarRentalException qex = (QuickCarRentalException) ex;
            MessageManager msgMgr =
               (MessageManager) wdComponentAPI.getMessageManager();
            msgMgr.reportException(qex._getFaultString(), true);
         } else {
            MessageManager msgMgr =
               (MessageManager) wdComponentAPI.getMessageManager();
            msgMgr.reportException(ex.getLocalizedMessage(), true);
     
   }
      }
      //@@end
   }

Method execute_Cancel()

   public void execute_Cancel() {
      //@@begin execute_Cancel()
      try {
         //wdContext.currentCancelBookingElement().modelObject().execute();
         Request_QuickCarRentalServiceViDocument_cancelBooking modObj =   
            wdContext.currentCancelBookingElement().modelObject();
         modObj._setHTTPDestinationName("CarRental");
         modObj.execute();       wdContext.nodeResponse_CancelBooking().invalidate();

         MessageManager msgMgr =
            (MessageManager) wdComponentAPI.getMessageManager();
         msgMgr.reportSuccess(
            "Success! "
               + wdContext
                  .currentResponse_CancelBookingElement()
                  .getResult());

      } catch (Exception ex) {
        
if (ex instanceof QuickCarRentalException) {
            QuickCarRentalException qex = (QuickCarRentalException) ex;
            MessageManager msgMgr =
               (MessageManager) wdComponentAPI.getMessageManager();
            msgMgr.reportException(qex._getFaultString(), true);
         } else {
            MessageManager msgMgr =
               (MessageManager) wdComponentAPI.getMessageManager();
            msgMgr.reportException(ex.getLocalizedMessage(), true);
        
}
      }
      //@@end
   }

       6.      After adjusting the code, save the metadata.

Result

The component controller will process the access control exceptions produced by the EJB.

Next Step:

Rebuilding the Projects and Redeploying the Application

 

 

End of Content Area