Java Services in WebMethods

Java Service :
Java service in webMethods refers to a service implemented using the Java programming language within the webMethods Integration Server platform. webMethods Integration Server is an enterprise integration and application platform that provides a range of features for designing, developing, and managing integrations and business processes.

 

Java services allow you 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.

key points about Java services :
  1. Implementation: Java services are implemented as Java classes within the Integration Server environment. You can write code in Java using standard Java syntax and leverage the Java Development Kit (JDK) libraries and APIs.
  2. Access to Integration Server Services: Java services have access to various Integration Server services, such as the built-in services, document types, and other components provided by webMethods. This allows you to interact with the Integration Server infrastructure and utilize its capabilities within your custom Java code.
  3. Integration Server APIs: webMethods Integration Server provides a set of APIs that allow Java services to interact with its core components. These APIs enable you to perform actions like accessing and manipulating data, invoking services, logging, and error handling.
  4. Deploying and Executing: Java services are packaged and deployed within the Integration Server as part of a package or project. Once deployed, they can be invoked like any other service within Integration Server. You can execute Java services synchronously or asynchronously, depending on your requirements.
  5. Integration with other webMethods Components: Java services can also interact with other webMethods components, such as the Universal Messaging messaging system, the Broker publish/subscribe messaging system, or the Trading Networks component for B2B integration. This allows you to leverage the capabilities of these components within your custom Java code.

Create a Java service to concatenate two strings  :

  1. Create a Java service with a name concat.

     

  2. If you observe the Java service you’ll notice that it comes with a pre-generated code structure, leaving you with the task of writing your business logic within the designated white space.

     

  3. Create two variables named “inString1” and “inString2”. These variables will be used to accept input values. Additionally, in the output section, create a variable named “concatValue” of type String and save it. This variable will hold the concatenated result or output of the service.

     

  4. Now right-click on the service and select “Generated Code” from the available options.
  5. Upon opening the window, you will be presented with various options. To proceed, please select the option as shown in the screenshot, and then click on the “Finish” button. This process will generate the necessary code for handling the service’s input and output.

     

  6. After clicking the “Finish” button, the scaffolded code will be automatically copied to your clipboard. You can then paste this code into your Java service.

     

  7. If you observe the screenshot provided, you will notice that two string variables have been generated for inputs. These variables can be utilized for performing concatenation operations within the Java service.

     

  8. Please add the following code to concatenate the values of “inString1” and “inString2” and store the resulting output in another String variable named “output”.

     

  9. To update the code and populate the concatenated value stored in the “output” string variable into the “concatValue” variable in the output section, you can make the following modification:

     

  10. With all the necessary steps completed to perform the concatenate operation using the Java service, it is now time to run the service by providing suitable input values and observe the resulting output.
  11. Let’s run the service by providing the input values “Harmoni” for “inString1” and “Gate” for “inString2”.

 
 
Invoke Java service in flow service :
  1. Create a flow service with name invokeJavaService.

     

  2. In the input section of the service, please create two variables named “inString1” and “inString2”. These variables will be used to accept input values. Additionally, in the output section, create a variable named “result”. This variable will hold the output or result of the service.

     

  3. To integrate the Java service into your flow service, simply drag and drop the Java service component into your flow. Once added, you can proceed to perform the required mapping by following the instructions and mappings provided in the provided screenshot.

     

  4. Let’s run the service by providing the input values “Harmoni” for “inString1” and “Gate” for “inString2”.

 
Invoke flow service in Java service :
  1. Create a Java service with the name invokeFlowService.
  2. Create two variables named “string1” and “string1”. Additionally, in the output section, create a variable named “concatResult” of type String and save it.

     

     

     

  3. Now, generate the code for this Java service, both for the input and output sections, similar to what we did in the initial exercise, and place it in the Java service.

     

     

     

  4. As developers, we sometimes prefer a shortcut, so instead of manually writing the code to invoke the flow service, let’s generate the code automatically.
  5. Now right-click on the “invokeJavaService” flow service click generate code and perform the below steps shown in the screenshot.

     

  6. Now, paste the scaffolded code into your Java service, ensuring that it resembles the code structure depicted in the provided screenshot.

     

  7. Now we need to update few things in the code to map the input from the Java service to the flow service as marked in the below screenshot.

     

  8. Please update the code in your Java service to reflect the mappings shown in the provided screenshot. By incorporating these changes, you will ensure that the input and output variables of the Java service are correctly mapped to the corresponding input and output variables of the flow service

     

  9. With all the necessary steps completed for invoking the flow service within the Java service, it’s time to run the code by providing the input values “Harmoni” for “string1” and “Gate” for “string2”
  10. Congratulations! We have successfully obtained the expected result😊.

     

Debug java service :

  1. Now right click on the “invokeFlowService” java service and click on the generated code option.
  2. After clicking the “Generate Code” option, a window will appear, prompting you to select the reason for generating the code. Please follow the instructions displayed in the provided screenshot to select the appropriate reason and proceed with the code generation process.

     

  3. After clicking the “Finish” button, a .java file will be generated with the name of your service. This file can be utilized for debugging purposes.

     

  4. Now update the following things in the , java code as mentioned in the screenshot.

     

     

     

  5. Now add the break point in your “invokeFlowService” java service and right click on the auto-generated java code and debug it as a java service, it will ask you to provide the server user name and password, if you want then you can hard code the user name and password in the java service itself as well.

     

     

     

  6. Now It will open the debug perspective where you can see the runtime values like below.

     

    1. Resume button : The “Resume” button is used in the debugging perspective to continue the execution of the program after a breakpoint. When a breakpoint is encountered, the program execution pauses, allowing you to inspect variables, step through the code, and analyze the program’s state. Once you have examined the necessary information and made any required modifications, you can click the “Resume” button to continue the program execution from the current breakpoint onwards. This allows the program to continue running until the next breakpoint or until it completes execution. The “Resume” button is particularly useful for stepping through the code and observing the program flow in a controlled manner during the debugging process.
    2. Step Into: The “Step into” button in the debugging perspective allows you to execute the line of code and delve into any method or function calls encountered, providing a detailed understanding of the program’s execution flow within webMethods Integration Server.
    3. Step Over: The “Step Over” button in webMethods debugging perspective allows you to execute the next line of code without diving into individual method or service calls, simplifying the debugging process while maintaining visibility of the program flow.
    4. Step Return: The “Step Return” button in webMethods debugging perspective quickly returns from the current method or service call, allowing you to skip the remaining code and focus on the higher-level program flow.
  7. We are done now

Hope you have enjoyed this article, click below download button to download the source code😊

 

Download Package

 

 

1 thought on “Java Services in WebMethods”

Leave a Comment