You have a Mule Application that connects to external systems using connectors such as HTTP or SFTP. Usually, when deploying applications to different environments (Dev, QA, or Prod) you need to reach different endpoints, and depending on the environment, sometimes you require to go through a proxy or not.
In this article, we'll cover how to programmatically choose between proxied and non-proxied configurations reducing the number of code changes required.
In this example, we'll use the HTTP Connector defining a proxied configuration and a not proxied one for HTTP Requests (outbound), and we'll set the not proxied to be used in "dev" and the proxied one to be used in "prod".
In this guide, we'll use concepts from Configuring Properties documentation.
1- Define your connector configurations.
EG.
<http:request-config name="HTTP_Request_configuration_proxy" doc:name="HTTP Request configuration" > <http:request-connection host="yourHost" port="yourPort" > <http:proxy-config > <http:proxy host="yourProxyHost" port="yourProxyPort" /> </http:proxy-config> </http:request-connection> </http:request-config> <http:request-config name="HTTP_Request_configuration" doc:name="HTTP Request configuration" > <http:request-connection host="yourHost" port="yourPort" /> </http:request-config>
2- Create the properties files for your "dev" and "prod" environments and locate them under "src/main/resources".
In those files, we'll set the property "httpconfig" as the name of the HTTP Configuration we want to use in that environment.
EG.
File name: dev.properties
httpconfig=HTTP_Request_configuration
File name: prod.properties
httpconfig=HTTP_Request_configuration_proxy
3- Create a global property that you will use to select the properties file according to the environment.
EG.
<global-property doc:name="Global Property" name="env" value="dev" />
You can either hardcode its value in the component or set it dynamically through System properties or Environment variables.
4- Create a configuration properties element and set the naming convention for your properties files.
EG.
<configuration-properties doc:name="Configuration properties" file="${env}.properties" />
5- Configure the HTTP Request operation to pick the right HTTP configuration, based on the value of the property "httpconfig" in your properties files.
EG.
<http:request method="GET" doc:name="Request" config-ref="${httpconfig}" path="/"/>
6- Run the application.
Note 1:
If you deploy the application setting "env" as "dev" it will execute the HTTP Request operation using a non-proxy configuration, alternatively, if you set it as "prod" it will use the one with the proxy.
Note 2:
This kind of process can be followed for different connectors and can be tailored according to your needs for example using additional properties to resolve each configuration or using secure properties if needed.
You can find a sample application attached to this article where the steps described were applied. Make sure to modify the project to use your host, port, and proxy settings in case you want to test it.
Disclaimer: This solution provides a suggestion that should be considered in conjunction with your specific use case and requirements and does not represent a complete solution for all circumstances.
001115615

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.