Published Business Service Model
Two methods are required to expose a published business service class as a web service: a public method and a protected method. The sole purpose of the public method is to be called as a web service. The protected method manages and processes the call to the business service classes.
You can use this code sample as a model for your published business service class:
/**
* RI_AddressBookManager is the published business service class exposing
* functionality within Address Book processes.
*/
public class AddressBookManager extends PublishedBusinessService {
/**
* published business service Public Constructor
*/
public AddressBookManager() {
}
/**
* Published method for Adding an AddressBook Record.
* Acts as wrapper method, passing null context and null connection,
* will call protected addAddressBook.
* @param vo the value object representing input data for Adding an
* AddressBook record
* @return confirmVO the response data from the business process for adding an
* AddressBook record.
* @throws BusinessServiceException
*/
public ConfirmAddAddressBook addAddressBook(AddAddressBook vo) throws
BusinessServiceException {
return (addAddressBook(null, null, vo));
}
/**
* Protected method for RI_AddressBookManager published business
* service.
* addAddressBook will make calls to business service classes
* for completing business process.
* @param vo the value object representing input data for adding an
* AddressBook record.
* @param context conditionally provides the connection for the
* database operation and logging information
* @param connection can either be an explicit connection or null.
* If null, the default connection is used.
* @return response value object is the data returned from the
* business process for adding an AddressBook record.
* @throws BusinessServiceException
*/
protected ConfirmAddAddressBook addAddressBook(IContext context,
IConnection connection,
AddAddressBook vo) throws BusinessServiceException {
//perform all work within try block, finally will clean up any
//connections
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, "addAddressBook", vo);
//Create new published business service messages object for holding
//errors and warnings that occur during processing.
E1MessageList messages = new E1MessageList();
// Create a new internal value object.
InternalAddAddressBook internalVO =
new InternalAddAddressBook();
vo.mapFromPublished(context, internalVO);
//Call business service passing context, connection and
//internal VO
E1MessageList bssvMessages = AddressBookProcessor.
addAddressBook(context,connection, internalVO);
//Add messages returned from business service to message list
//for published business service.
messages.addMessages(bssvMessages);
//A 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);
}
//Exception was not thrown, so create the confirm VO from
internal VO ConfirmAddAddressBook confirmVO =
new ConfirmAddAddressBook(internalVO);
confirmVO.setE1MessageList(messages);
finishPublishedMethod(context, "addAddressBook");
//return outVO, filled with return values and messages
return confirmVO;
} finally {
//Call close to clean up all remaining connections and
//resources.
close(context, "addAddressBook");
}
}