Extending a Published Business Service

You can add functionality to an existing published business service. Custom processing must take place either before or after the business service call and typically, all processing is within the same transaction boundary. You extend a published business service by doing the following tasks:

  1. Create a new class that extends the original published business service class.

  2. Create a new public method that calls the inherited method for which you are extending functionality.

  3. Create custom processing that takes place either before or after the business service call. Typically, all processing will be within the same transaction boundary.

  /**
  * Published method for Customized Add Address Book 
  * This exposed method will call the method addAddressBook from 
  * parent class.
  * @param vo the value object representing input data for adding 
  * AddressBook record
  * @return confirmVO the response data from the business process for 
  * adding an address book record.
  * @throws BusinessServiceException
  */
       public ConfirmAddAddressBook customAddAddressBook
(AddAddressBook vo) throws BusinessServiceException {
           //perform all work within try block, finally will clean up 
           //any connections
           IContext context = null;
           IConnection connection = null;
           try {
               //Call start published method, passing context of null 
               //will return context object so BSFN or DB operation can
               //be called later.
               //Context will be used to indicate default transaction 
               //boundary, as well as access to formatting and logging 
               //operations.
               context = startPublishedMethod(context, 
"customAddAddressBook",vo);
               //Create new published business service messages object 
               //for holding errors and warnings that occur during 
               //processing.
               E1MessageList messages = new E1MessageList();
               
               //TODO:  This is where a customer customization would be
               //coded.
               //Whatever is coded here is included within the 
               //transaction but occurs prior to calling the published
               //business service.
               
               //Call published business service method
               ConfirmAddAddressBook confirmVO = this.addAddressBook
(context, connection, vo);
              
               //TODO:  This is where a customer customization would be
               //coded.
               //Whatever is coded here is included within the 
               //transaction but occurs after calling the published 
               //business service.
               
               //published business service will send either warnings 
               //in the Confirm Value Object or throw a published 
               //business service Exception.
               //If messages contains errors, throw the exception
               
              if (messages.hasErrors()) {
                   //get the string representation of all the messages
                   String error = messages.getMessagesAsString(); 
                   //Throw new BusinessServiceException
                   throw new BusinessServiceException(error, context);
               }
               
               //Call finish published method, passing the context  
               //to commit default implicit transaction(in case of no 
               //exceptions)
               finishPublishedMethod(context, "customAddAddressBook");
               //return confirmVO, mapped with return values and 
               //messages
               return confirmVO;
           } finally {
               
               //Call close to clean up all remaining connections and 
               //resources.
               close(context,"customAddAddressBook");
           }
          
       }