-
Notifications
You must be signed in to change notification settings - Fork 1
Quick Start
The following steps show how to create a Java service for getting the maximum of two numbers. At the same time, it shows how to set up the library in a new Integration Server package.
You'll need access to Designer and access to the filesystem where Integration Server is installed.
Go to the releases section and download the following JAR files:
wmboost-data-x-standalone.jar
wmboost-data-x-source.jar
wmboost-data-x-javadoc.jar
For this example, go to Designer and create a new Integration Server package named Example1.
On the webMethods server, copy the downloaded JAR files into the code/jars
folder inside your IS package on the server. For instance, for package Example1 and assuming a base installation path of C:\SoftwareAG\IntegrationServer, then use:
- for webMethods 9.6 or higher:
C:\SoftwareAG\IntegrationServer\instances\default\packages\Example1\code\jars
, where default is the name of your Integration Server instance - for previous versions:
C:\SoftwareAG\IntegrationServer\packages\Example1\code\jars
In this example, we'll implement a Java service that returns the maximum of two numbers. The result is returned in a string variable.
Go to Designer and locate the Example1 package. Create a new folder named example1. Inside it, create a new Java service called maxInt. Go to the Input/Output tab to add num1 and num2 as two input strings and max as an output string.
In Designer, go to the Java perspective. Locate the Java project for the Example1 package. Get the JAR files you downloaded previously and copy them into the lib folder inside the Example1 java project.
Go back to the Service Development perspective and select the Java service you created. Switch to the Source tab and copy the following code inside the max method:
public static final void maxInt(IData pipeline) throws ServiceException {
Document pipeDoc = Documents.wrap(pipeline);
int num1 = pipeDoc.intEntry("num1").getNonNullVal();
int num2 = pipeDoc.intEntry("num2").getNonNullVal();
int max = java.lang.Math.max(num1, num2);
pipeDoc.stringEntry("max").putConverted(max);
}
then add the appropriate source code imports at the top of the Java file:
// other imports...
import au.com.innodev.wmboost.data.Document;
import au.com.innodev.wmboost.data.preset.Documents;
Save the changes to the service.
You're now ready to run the service to try it in action. If you enter 8 and 3 as the input, you'll get this:
That's it. You've just implemented your first service with wmboost-data!
The example presented here is mainly for illustrative purposes, but these considerations are important:
-
Integers are used in this example because they are very popular. If you expect larger numbers, another type such as long or even BigInteger would be more appropriate. If the value had decimal numbers, double or BigDecimal would be good options.
-
webMethods comes with the
pub.math:max
built-in service. Taking aside the difference that it takes a list instead of two elements, there's a flexibility advantage for the code in the example.pub.math:max
only takes strings whereas our example also accepts instances of Long, BigInteger, etc. If a conversion to Integer was necessary, it'd be performed automatically. As you'd expect, if a value can't be converted, an exception is raised. -
In the example, both input variables are mandatory and null is not accepted, as enforced by the
getNonNullVal
method. This may be desired in certain cases; in other cases, more lenientget*
methods may be more appropriate.