Skip to Content

Property File is simple but smart phenomenon discussed in this blog. Use of property file is not new in integration arena, but not discussed/used widely in XI context. This blog describes only some of usages of property file, however it can be used with great versatility if deployed with little intelligent.

Many times In Message Mapping we required to use hardcode or constant values to be incorporated in validations and mapping rules. These hardcode/ constants are mainly required in form of properties like data formats, ranges or default values for passing to target, system specific values etc. Many time these property values are system and environment dependent ( Dev, QA, Prod etc.). This makes us to change Message Mapping code every time whenever there is change in these hardcode values. We can avoid disturbing Message Mapping using Property Files to store these values and read generically from Message Mapping code. It will certainly save lot of time in changing the mapping frequently. Also it avoids complexity in case of User Defined functions or java mapping. Whenever there is change in any of values we just need to update property file without changing actual mapping program.

What is Property file?

  • >>To explain in simple language; Property file is text file with “.properties” as an extension. It can be created and edited using NOTEPAD.

Where to put this property file in XI?

  • >>Property file can be stored in local folder in XI system.

How to access property file?

  • >> It can be accessed by ‘file path’ using JAVA I/O. Piece of JAVA code (demonstrated below)can be used in form of either User Defined Function in graphical mapping or in JAVA mapping.

Example of file path.
/home/xiuser/folder/xiprop.properties e.q. /home/user name/folder name/file name.properties

Sample Property file contents

# String Key values string_key1 = 1258 string_key2 = 8974 # Project IDs PROJECT_ID_1 = 9500 PROJECT_ID_2 = 2400 # Interface IDs O01.INTERFACE_ID = 3000304 O02.INTERFACE_ID = 3000344 # Control For 310 Client 310RCVPRN = GP0CLNT310 # Control For 810 Client 810RCVPRN = GP0CLNT810

JAVA code demonstrated to read a property file.
(Also code can be added with trace and catch for IO exceptions to know more about errors)

import java.util.properties; private properties _propSet; _propSet= new Properties(); _propSet.load(new FileInputStream(("/home/xiuser/folder/xiprop.properties")); String value = _propSet.getProperty("string_key1"); return value;

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

  1. Ananth Chinnaraj
    Hi Anand,

    One suggestion from my side. If you store the property file in local XI server directory it will be difficult to transport to QA and PROD systems. So you can bundle your property file along with Jar and read the values from Property files. This will avoid headaches in transporting the property files to QA and PROD.

    Regards,
    Ananth

    (0) 
  2. Béla Suranyi
    Hello Anand,

    Even if you bundle the file in a jar how will you manage the transport of the values that  change from dev to qa and prod?

    Best regards,
    Bela

    (0) 
  3. For this feature to work properly inside an UDF, you need to use it like this:

    imports: java.util.Properties;

         Properties _propSet;

         try{
              _propSet= new Properties();
              _propSet.load(new FileInputStream(“/path/file.properties”));
         
              Enumeration enum = _propSet.propertyNames();
              for (; enum.hasMoreElements(); ) {
                   // Get property name
                   String propName = (String)enum.nextElement();
                 
                   // Get property value
                   String propValue = (String)_propSet.getProperty(propName);
              
              }
         }
         catch (Exception e)
         {
              trace.addWarning(e.getMessage());
         }

    (0) 

Leave a Reply