Executing a service from a custom ServiceHandler is very easy.
ServiceHandlers always extend the ServiceHandler class. So within a custom ServiceHandler Java class, you have access to the Service object using the variable m_service. From this Service object, you can get a ServiceRequestImplementor object: m_service.getRequestImplementor(). With the ServiceRequestImplementor object, you can execute services with a few different methods (executeSubServiceCode, executeSafeServiceInNewContext, executeServiceEx, executeServiceDirect, executeServiceTopLevelSimple). I typically tend to use the executeServiceTopLevelSimple method.
The executeServiceTopLevelSimple method signature looks like the following:
ServiceHandlers always extend the ServiceHandler class. So within a custom ServiceHandler Java class, you have access to the Service object using the variable m_service. From this Service object, you can get a ServiceRequestImplementor object: m_service.getRequestImplementor(). With the ServiceRequestImplementor object, you can execute services with a few different methods (executeSubServiceCode, executeSafeServiceInNewContext, executeServiceEx, executeServiceDirect, executeServiceTopLevelSimple). I typically tend to use the executeServiceTopLevelSimple method.
The executeServiceTopLevelSimple method signature looks like the following:
public void executeServiceTopLevelSimple(DataBinder binder, String serviceName, UserData userData) {}.
Below is a sample method I use to wrap the executeServiceTopLevelSimple method:
/**
* This method executes a service.
* @throws ServiceException
*/
private void executeService(final String DataBinder serviceBinder, final String serviceName) throwsServiceException {
traceVerbose("Start executeService");
try {
trace("Calling service " + serviceName + ": " + serviceBinder.getLocalData().toString());
// Execute service
m_service.getRequestImplementor().executeServiceTopLevelSimple(serviceBinder, serviceName, m_service.getUserData());
trace("Finished calling service");
} catch (final DataException e) {
trace("Something went wrong executing service " + serviceName);
e.printStackTrace(System.out);
throw new ServiceException("Something went wrong executing service " + serviceName, e);
} finally {
traceVerbose("End executeService");
}
}
| | | |
RSS Feed