How to permanently change or add configuration in WSO2 API Manger 3.1.0

What is the problem?

In my previous post, i show how to modify configuration in axis2.xml to set API Manager to work with RabbitMQ as endpoint. Sadly it doesn’t work on WSO2 API Manager version 3.1.0. From this version, the deployment was changed. The standard configuration is overwritten every WSO2 API Manager is started. That is because, first the configuration files are automatic generated from templates, before WSO2 API Manager starts.

What we can do?

After a small investigation, I found the solution. Because, configuration files are generating, from Jinja2 templates – files with extension .j2, we need to edit it. The simplest way is to found them and add or change what we need to change, and then save them. In WSO2 API Manager 3.1.0 the files can be found in <API-M_HOME>\repository\resources\conf\templates\. You will see, the structure of directories, in this path is familiar. You can found the axis2 template here:
<API-M_HOME>\repository\resources\conf\templates\repository\conf\axis2\axis2.xml.j2 Now you can open this file with your text editor, and permanently change what you want. Be careful, because it is not XML but j2 template.

Can we do it in better way?

Yes we can. Considering my previous post, where i was configuring RabbitMQ introduced changes in accordance with the Jinja2 template documentation. So my changes was looking like following:

{% if transport.rabbitmq.connection is defined %}
	<transportSender name="rabbitmq" class="org.apache.axis2.transport.rabbitmq.RabbitMQSender">
		<parameter name="CachedRabbitMQConnectionFactory" locked="false">
			<parameter name="rabbitmq.server.host.name" locked="false">{{transport.rabbitmq.connection.parameters.host.name}}</parameter>
			<parameter name="rabbitmq.server.port" locked="false">{{transport.rabbitmq.connection.parameters.port}}</parameter>
			<parameter name="rabbitmq.server.user.name" locked="false">{{transport.rabbitmq.connection.parameters.user.name}}</parameter>
			<parameter name="rabbitmq.server.password" locked="false">{{transport.rabbitmq.connection.parameters.password}}</parameter>
	</transportSender>
{% endif %}

It simply add the configuration node TransportSender for RabbitMQ, but it is adding dynamically. You can See the notation with double bracket – that is part of the Jinja2 template. But wher comes from this dynamicly variables? All of those templates variables, are defined in: <API-M_HOME>\repository\resources\conf\default.json. For my configuration, I need to add in json configuration rows like this:

"transport.rabbitmq.connection.parameters.host.name": "localhost",
"transport.rabbitmq.connection.parameters.port": "5672",
"transport.rabbitmq.connection.parameters.user.name": "guest",
"transport.rabbitmq.connection.parameters.password": "guest",

After that, is done, when i start my WSO2 API Manager 3.1.0, a proper axis2.xml are generated including my RabbitMQ config and works exacly what i expected.

Additional information

In addition to this product, I see, that newly released WSO2 products are also based on configuration using j2 templates, including WSO2 Micro Integrator.