IBM BPM, V8.0.1, All platforms > Authoring services in Integration Designer > Developing monitor models > Create monitor models > Authoring XPath functions > Examples of XPath functions
Example of a service-invocation function
Service invocation, sometimes referred to as web service call, is one of several XPath 2.0 functions supported in model expressions in IBM Business Monitor. Define service invocation XPath functions for use in monitor model XPath expressions.
The following code exemplifies the use of service invocation as a user-defined XPath function:
public class Examples { public static final String NAMESPACE = "http://www.jimbo.org/beverages/functions"; @XPathFunction( namespaceName = NAMESPACE, localName = "getCreditScore", description = "(targetHost, port, ssNumber) This function returns the credit score of a person given his social security number. ", isSelfContained = false, isDeterministic = false ) public static BigDecimal getCreditScore(final String targetHost, final String port, final String ssNumber) { BigDecimal score = null; try { // Define the service. QName serviceName = new QName("urn:CreditScore/mme/ibm/com", "CreditScoreService"); ServiceFactory factory = ServiceFactory.newInstance(); Service service = factory.createService(serviceName); // Create the dynamic invocation object from this service. Call call = service.createCall(); String url = "http://" + targetHost + ":" + port + "/CreditScoreService/services/port"; call.setTargetEndpointAddress(url); // Build the message. QName operationName = new QName("urn:CreditScoreService/mme/ibm/com", "getCreditScore"); call.setOperationName(operationName); call.addParameter( "ssNumber", // parameter name XMLType.XSD_STRING, // parameter XML type QName String.class, // parameter Java type class ParameterMode.IN); // parameter mode call.setReturnType(XMLType.XSD_STRING); call.setProperty(Call.OPERATION_STYLE_PROPERTY, "wrapped"); // Invoke the operation. Object[] actualArgs = {ssNumber}; String response = (String) call.invoke(actualArgs); score = new BigDecimal (response);} catch (Throwable t) { t.printStackTrace(); score = new BigDecimal (0);} return score;} }