Posts

Showing posts with the label code

How to Modularize your custom DataWeave 2.0 scripts

Image
     DataWeave is the main expression language in Mule 4, and with the recent version 2.0, it is the sole transformation language in a Mule 4 application. DataWeave is a powerful and rich scripting language, which  supports a variety of useful functions for data manipulations and transformations. It employs a functional programming principle, which means that functions don't have states and side effects. DataWeave functions can also be called recursively (I have done some recursive functions before but will think of a simple concrete example).     If you want to read and study more about DataWeave, and familiarize yourself with the different supported functions, go to  https://docs.mulesoft.com/mule-runtime/4.2/dw-functions     The DataWeave related functions are organized into modules. There are core modules, string modules, binary, cryptography, and a lot more. DataWeave is quite extensible, and I think in future upgrades of Mule we will se...

Creating Java Custom Functions

Image
You can create custom XPath functions that you can directly use in the Activity Input. These functions come very handy especially when you expect to use them repeatedly for mapping. You can do that by creating a Java Custom Function shared resource. You will have to write a Java class that has a public and static method and returns a value. The method cannot be void or explicitly throw an exception. Supposed you want to have a custom function that replaces all occurrences of a string with another string. This is, in my experience, a common function that is not readily available in TIBCO BW because it doesn't support XSLT 2.0; it's limited to XSLT 1.0. But it allows us to write a Java method and call it via XSLT! To demonstrate that, we can have a Java method that accepts three parameters: the input text, the regular expression or pattern, and the replacement text. I have named this method "replaceRegex" but it could be any descriptive name. I used the String...

Learning Ruby

Just recently I started learning a new programming language called Ruby. The first language that I ever learned way back in college is Java so I can't help but compare the two languages. Learning a new language for me is apparently not very difficult since I have a strong foundation in programming logic theoretically as well as based on experience. I was quite amazed on how Ruby has made coding fast, easy, and simple with its intuitive, shorter syntax, and also available online sources ( http://ruby-doc.com/docs/ProgrammingRuby /) will help you learn the language quickly. So, I started reading the first five sections of the documentation and I was too eager to put my hands on it and write some codes. By the way, installing the compiler on Windows is no sweat and you can download it on  http://rubyonrails.org/download . The installer automatically appends C:\Ruby200\bin to the system path so you can run the code right away on the command prompt. You just have to create a file wit...