Calling Java Class Using DataWeave
In this tutorial, learn how to call a Java class using DataWeave while observing the Java Static Method on Linux and Windows OS.
Join the DZone community and get the full member experience.Join For Free
Recently, I worked on an application to read barcode images from aURL or Base64 encoded payload and provide the result.
For that, I have used a jar from Dynamsoft and created a Java package importing the classes of the barcode reader from Dynamsoft and creating a class for ImageReader.
Below is the structure of the application and the Java package:
I wrote two static methods — one for reading the normal URL of the image and another for reading the Base64 encoded payload.
Write the below code to call the ImageReader class from DataWeave:
When executed locally on Windows OS, it worked and returned the expected results:
But when executing the same code by deploying it over the server, I was unable to find the static method for Base64 and returned an error:
To overcome the error, I changed the Java code. In place of using multiple static methods, I used the
if else condition. This time, I changed the package name and introduced a new variable in the static method to validate the
if else condition. 0 - For Base64 and 1 - For URL.
New code in DataWeave:
New Java Code URL:
The development of the applications signifies that a Java class can be called using DataWeave and the static method behaves differently on Linux and Windows OS.
Opinions expressed by DZone contributors are their own.