Quantcast
Channel: SCN : All Content - Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 7030

Add External Jar files in your UDF - Working with API's

$
0
0

Background

 

Writing UDF was always more easier than writing a Java code outside ESR and bring it back as Imported Archive. You can find all the details in this blog about implementing Java Mapping directly in your ESR : Write Java Mapping directly in ESR!


It was always been straight forward to add External Jar files in different Java IDE (Like Eclipse, SAP NWDS etc.) you used to develop your Java mappings. But other than you are using NWDS as your Service Repository, you always have to perform couple of extra steps in case of Java mapping compared with UDFs (User Defined Functions). This blog will be helpful for Swing client.


Also we add these Jar files locally to compile our Java code and it has to be available next time to us for further enhancements of the code. But with Function Library feature this Jar would be available throughout the SWCV.

 

Now with availability of different Open source API's and Java libraries, you would always want to add them in your code to reduce the development effort or to achieve specific functionality.


Example API

In PI, we commonly use String related functions. org.apache.commons.lang.StringUtils is a very powerful API available and it provides nice utilities to work with strings like checking for numeric/alphanumeric, finding difference or reversing other than common string functionality I will take this one as an example.


You can download Jar file from below website:

https://commons.apache.org/proper/commons-lang/download_lang.cgi


Now you need to download correct API depending on your PI server JDK version (Not JRE). Commons Lang 2 for Java 1.2+ and Commons Lang 3 is for Java 6.0+.  I will be using Lang 2.


Pic1.JPG


Now the file 'commons-lang-2.6-bin.zip' file is downloaded. Now unzip and you can see like below:

Pic2.JPG

Keep in mind we need to upload ".jar" file in our PI ESR and not the ".zip" file.


Now open ESR, create Imported Archive ('Apache_StringUtils' in the Pic) and upload 'commons-lang-2.6.jar', you can see Class files like below available within the library:

 

Pic3.JPG

 

Use of Jar inside Function Library UDF

Create Function Library as described in the blog:PI 7.1 Concept of Function Library in Process Integration - Process Integration - SCN Wiki


Go to 'Archives Used':

 

Pic4.JPG

Select your Archive created above.

Pic5.JPG

Now in your 'Import Instructions' tab, add the Package name just like you use in your Java code.

Pic6.JPG

It is ready to be used under UDF. I am going to use "equals" function to test. Now all the StringUtils functions are NULL safe.

 

Sample UDF Code

public String StringManipulation(String firstStr, String secondStr, Container container) throws StreamTransformationException{
if(StringUtils.equals(firstStr,secondStr))      return "YES";
else  return "NO";

 

Pic10.JPG


Access the code inside Message Mapping

You can use your Function Library inside any Message Mapping throughout the SWCV. It would look like below:Pic11.JPG

 


With the use of Open Source API's you can find easy solution for different difficult requirements, sometimes few are beyond the capability of basic Java functions.


Viewing all articles
Browse latest Browse all 7030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>