Saturday, September 30, 2023

Java Service { } Implementation

What is a Java Service?

Java service in webMethods refers to a service implemented using the Java programming language within the webMethods.

Java services allows us to write custom code using Java to extend the functionality of webMethods Integration Server. They provide a way to incorporate complex business logic or perform custom operations that are not easily achievable using the built-in services provided by webMethods.

A Java service is a public static method in a Java class file on webMethods Integration Server.

webMethods Designer provides an Integrated Development Environment (IDE) that you can use to create, compile, and publish Java services.

Java services follow a simple naming scheme:
  • The interface name represents the fully qualified Java class name.
  • The service name represents the Java method name.

All Java services that reside in the same folder are methods of the same class.

When you build a Java service with Designer, it automatically combines your service into the class file associated with the folder in which you created it.

Java is the native language for services Used to implement the complex logic

Basic stages involved in creating a Java service:

  • Specify the inputs and outputs of the service.
  • Create the Java service using Designer.

How to compile a Java Service.?
When you save the source file, the IDE automatically compiles it and registers it on the server.  

Editable Sections of a Java Service 
  • imports : where you can specify the names of additional Java packages whose classes you want to make available to the current class. 
  • extends : where you can specify a super class for the implementation. 
  • implements : where you can specify the Java interfaces that the Java service implements. 
  • source code : where you add the code for the primary Java service method.
  • shared code : where you can specify declarations, methods, etc. that will be shared by all services in the current folder. 

IData 
The IData object is the universal container that services use to receive input from and deliver output to other programs. 
It contains an ordered collection of key/value pairs on which a service operates.

IDataCursor
IDataCursor interface defines the methods you use to access, traverse, and manipulate the contents of an IData object

IDataUtil
The IDataUtil class provides various utility methods for populating, converting, copying, and merging the elements within an IData object.

IDataFactory
This class provides methods for creating an IData object.

Creating IData objects:
IData obj=IDataFactory.create();

Create IDataCursor:
IDataCursor pipelinecursor=pipeline.getCursor();

Read from the pipeline: 
IData docint = IDataUtil.getIData( pipelineCursor, "docint" );
IData[] docint1 = IDataUtil.getIDataArray( pipelineCursor, "docint1" );

Invoke a service:
IData output = Service.doInvoke(<Folder Name>, <Service Name>, <IData input>);

Put IData to pipeline:
IDataUtil.put(pipelineCursor, "outputValue1", sampleOutput);


Let's see how to create a Java service in webMethods.
I am using wM 10.15 at the time of writing this blog. If you're using older or newer versions of wM, the Designer IDE views might be different.

How to create a simple Java Service.?

Create a Java service  from File>Package>Folder> Java Service (as you do for flow services)


Specify inputs / outputs based on your requirement.



Next, go to source tab then right select Generate Code


Then select "For implementing this service" to generate code for this service only.


And save the code, code will be compiled automatically. If there are no errors means you're good to go. Else we need to check and fix the errors.

The Output is :


In next blog, we will see How to debug a Java Service.?

Thanks for reading :-)

No comments:

Post a Comment

How to debug a Java Service.?

Please read my previous blog on Java Service Implementation to understand basics. After you have implemented Java Service successfully and e...