Loading Property Files in WSO2 MI Serverr API during Startup without Class Mediator

75 views Asked by At

I'm working with WSO2 Micro Integrator (MI) Server and I have a set of property files that I need to access within the API using a function like get-property('propName'). However, I want these properties to be loaded during the server startup, without using a class mediator to load the files and set the properties every time.

Is there a recommended approach or best practice specific to WSO2 MI Server for achieving this? I'm looking for a solution that allows the properties to be loaded once during server startup. Any guidance or suggestions would be greatly appreciated.

Tags: wso2 [wso2-micro-integrator], [api], [property-files], [class-mediator], [server-startup]

I need to get that property with in API by using xpath expressions like get-property('file','propertyName')

1

There are 1 answers

2
ycr On

This is supported OOB by Micro Integrator. You can add your properties to a file named file.properties and place it in the <MI_HOME>/conf directory and it will be picked up automatically. If you have a custom properties file, let's say custom.properties you can pass the file path on server startup like below by adding it to the startup script so it will be loaded.

-Dproperties.file.path=/home/user/ei_configs/dev/custom.properties

Once the file is loaded. You can read the properties as Properties like below.

<property name="someProp" expression="get-property('file','propName')" scope="default" />

Read more here

Update

As you can pass multiple files, as a workaround you can create a shell script or batch script based on the environment, to read multiple properties files and merge them to a single file. You can add this script to micro-integrator.sh so it will be executed on server startup. An sample script blow.

# Assume that the properties files are available the location you are executing the server startup script.

output_file="${CARBON_HOME}/conf/file.properties"

for properties_file in *.properties; do
    if [ -f "$properties_file" ]; then
        cat "$properties_file" >> "$output_file"
    fi
done