Java Services are written using the Developer tool. Here is a quick introduction:
1) Create the java service
(This presumes that you have created a package, and some folders)
Right click on the folder that you want to contain the java service.
Choose New à Java Service
Developer will create a new java service for you (it looks like a
coffee cup), highlighting its default name:
Untitled
Type a new name for the service and hit enter
2) Code your service
The main window will show the empty service. A service is basically a static method that can is called by other flows.
Notice that the method signature (at the top of the pane) is
public static void (IData pipeline) throws ServiceException {
Your method call can get information set in the input/output tab by accessing the IData pipeline object. There are several ways to get information from the pipeline. (The pipeline is basically a wM proprietary hashmap). One way is to get an IDataCursor using the pipeline’s getCursor() method. Once you have a cursor, you can use it to traverse the pipeline, getting and setting values. There are several ways to use the cursor to get data. My preferred way is to use the IDataUtil static methods to access the cursor, but it is by no means the only way. At the end of your code, you should destroy your cursor (cursor.destroy()). If your code needs to throw an exception, use
throw new ServiceException(“”) or
throw new ServiceException(Exception).
Example code:
Here is an example that i created named ‘reverse’. It will reverse any String. I created it by making a new java service. Then on the input/output tab, i added a new String called ‘string’ for the input, and a new output called ‘result’. and then typed the following code:
IDataCursor cursor = pipeline.getCursor();
String input = IDataUtil.getString(cursor, “string”);
if (input != null) { //This is enforced in this example by ‘string’ being
//a required field, but is included for general
//good coding.
StringBuffer buffer = new StringBuffer();
buffer.append(input);
buffer.reverse();
cursor.insertAfter(“result”, buffer.toString());
}
cursor.destroy();
Oddities and Notes:
Compiler
The Integration Server must be able to see a java compiler. This means that the path on the Integration Server machine should have a java compiler visible. To test this, go to the command prompt of the IS machine, and type:
javac
When you hit enter, you should see the javac usage. If you can’t see this, javac (the java compiler) is not in your path.
method conflicts
Keep in mind that each service is a static method for the same class. Classes are defined for each folder that contains a java service, not for each Java Service.
more than one method
You can make more than one method in a service. Just end the method ‘}’, and then start a new one (e.g. ‘public static void someOtherMethod {‘). At the end of the last method, don’t put the ending parenthesis in ‘}’, as wM Developer automatically does this for you. This allows you to create extra variables, methods, static initializers (ummm, i personally never use static initializers – they can be dangerous and are not OO) if you need them.
imports
On the shared tab (below the main method pane), you can extend specific classes, and import classes if you need to.
wM introspection
You can invoke various wM introspective classes from within your code (e.g. Session object). Please see wM java API for details.
optional inputs
To make inputs optional, select the input in the input/output tab, then change the properties (upper right) to Required: False.
testing your code
Save often (each save forces a recompile). To test press the run button (looks like a green play button). A modal dialog will popup allowing you to type input values. Pressing ‘Ok’ will run the service. Results will show up in the ‘results’ pane (to the right).
Complex data structures
If you are dealing with documents, you must create new IData for the structure. Here is an example that creates a document (for output) named ‘context’ that contains four string fields (currency, encoding, language, timeZone).
IDataCursor cursor = pipeline.getCursor();
Session session = Service.getSession();
IData context = IDataFactory.create();
IDataCursor contextCursor = context.getCursor();
contextCursor.insertAfter(“currency”,session.getIContext().getCurrency());
contextCursor.insertAfter(“encoding”,session.getIContext().getEncoding());
contextCursor.insertAfter(“language”,session.getIContext().getLanguage());
contextCursor.insertAfter(“timeZone”,session.getIContext().getTimeZoneID());
cursor.insertAfter(“context”, context);
contextCursor.destroy().
…
#Integration-Server-and-ESB#Flow-and-Java-services#webMethods