Using environment variables in camel.xml to configure endpoints - variables

I have a cxf endpoint configuration in my camel.xml like this:
<cxf:cxfEndpoint id="callbackInbound"
serviceClass="ch.axpo.emis.v1.timeseriesservice.Callback"
wsdlURL="wsdl/timeseries.wsdl" endpointName="tss:CallbackPort"
address="http://somehost.com:9090/CallbackService" serviceName="tss:CallbackService"/>
In one of my routes I call this endpoint like this:
.to("cxf:bean:callbackInbound?dataFormat=PAYLOAD")
So, now instead of having a fix address (http://somehost.com:9090/CallbackService) I want to be able to configure the address for different environments (DEV, TEST, PROD, ...) using system variables. This is because I use JBoss 7 as runtime environment for camel and there is a quite simple way to add system variables with JBoss.
Is there a way to do that? Or is there a better way to configure cxf endpoints in different environments?
Thanks,
Sven

You can use the properties components and define the cxfEndpoint like this
System.setProperty("environment", "junit");
<cxf:cxfEndpoint id="routerEndpoint" address="{{router.address}}"
serviceClass="org.apache.camel.component.cxf.HelloService"/>
You can define the property file just like this
router.address={{{{environment}}.router.address}}
# LOCAL SERVER
junit.router.address=junit
# LOCAL SERVER
local.router.address=local
# TEST
test.router.address=test
# PROD
prod.router.address=prod

Related

RabbitMQ : How to set and use custom environment variable in RabbitMQ Advance config file

We have configured RabbitMQ server to communicate with LDAP server for authentication which is working as expected. But we are facing one challenge where we need to externalize one value from configuration to environment variable.
so below is the current configuration present in advance.config file
{other_bind, {"CN=Service_Account,OU=Service Accounts,DC=XYZ,DC=com",{string,"123456"}}},
and want to make it something like this
{other_bind, {"CN=Service_Account,OU=Service Accounts,DC=XYZ,DC=com",{string,"${RABBITMQ_SERVICE_ACCOUNT_PASSWORD}"}}},
so as a result we wanted to externalize our password to some environment variable and use the same in advance.config file.
I tried setting value in rabbitmq-env.conf file but no luck.
Also as per this article we can't set a custom environment variable in rabbitmq-env.conf file, is it right? and if yes then where we can set this value?
https://riptutorial.com/rabbitmq/example/14032/configuring-rabbitmq-on--nix-systems
No, this is not supported:
{other_bind, {"CN=Service_Account,OU=Service Accounts,DC=XYZ,DC=com",{string,"${RABBITMQ_SERVICE_ACCOUNT_PASSWORD}"}}},
One option is to generate the advanced.config from a template before RabbitMQ starts. If RabbitMQ starts via systemd in your environment, you can use the ExecStartPre hook to run a custom script or program.
To create a drop-in override for the RabbitMQ systemd unit (and add ExecStartPre), follow these instructions:
https://wiki.archlinux.org/title/systemd#Editing_provided_units
NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.

Mulesoft ESB Environment Variable per Project

I'm starting two Mule projects from studio. How can I set different environment variables for each project inside this one app?
If I have an application run configuration called RunBothProjects and that launches two projects: hellomule and hellomule8082.
For hellomule I want to add either an argument or environment variable that says MULE_APP=AppOne and for hellomule8082 I want to add MULE_APP=AppTwo.
Is this possible?
No, it is not possible to have separate environment variables because both Mule applications are deployed to the same Mule server. Environment variables are global per server.

How to set Spring active profile while running in WebLogic?

I want to set spring active profile in weblogic settings.
I have three properties in src/main/resources. For examp : application-dev.properties , application-qa.properties , application-test.properties.
I dont want to keep spring.profiles.active property in my application.properties file. As I have to change it every time whenever I want to deploy in different server.
I want to active the profile in weblogic (my deploying server for application). Whats is the way and how to fetch the value in springboot application?
Thanks
Pass the profile as java argument -Dspring.profiles.active=dev
A secure way to set profiles in springboot applications is to set environment variables with it. In general, it is a good approach, so you can define it differently for each one of your environments (dev, qa and prod).
Please check this discussion, which explains specifically about Weblogic. In java, you need the SPRING_PROFILES_ACTIVE environment variable set.

DataSource naming JBossEAP 6.2 vs Web Logic

I am porting a suite of related applications from WebLogic to JBoss EAP v6.2.
I have set up a data source connection using the JBoss command line interface and hooked it to an oracle database. This database has a name of "mydatasource" and a JNDI name of
"java:jboss/datasources/mydatasource" as per JBoss standards. I can test and validate this database connection.
However, when I try to port the code and run it, the connection doesn't work. The code that worked in WebLogic was simply:
InitialContext ic = new InitialContext() ;
DataSource ds = (DataSource)ic.lookup(dataSource) ;
with a value in dataSource of "mydatasource".
This worked in Web Logic but in JBoss it throws a NameNotFoundException
javax.naming.NameNotFoundException: mydatasource-- service jboss.naming.context.java.mydatasource
Clearly there is a difference in how the InitialContext is set up between the two servers.
But this port involves a large number of small applications, all of which connect to the datasource via code like that above. I don't want to rewrite all that code.
Is there a way through configuration (InitialContextFactory, maybe) to define the initial context such that code like that above will work without rewriting, or perhaps is there another way of naming the datasource that JBoss will accept that would allow code like that above to work without rewriting?
Or must we bite the bullet and accept that this code needs a rewrite?
Update: Yes, I know that simply passing "java:jboss/datasources/mydatasource" to the InitialContext lookup solves the problem, but I am looking for a solution via configuration, rather than via coding if there is such a solution.
The way to do this correctly through configuration is to use
java:comp/env/jdbc/myDataSource
then use resource-ref in web.xml to map it to the declare datasource and use weblogic.xml or jboss-web.xml to actually map it to the real one
in weblogic admin console, when you define datasource it can be jdbc/realDataSource
JNDI path Tomcat vs. Jboss
For weblogic http://docs.oracle.com/cd/E13222_01/wls/docs103/jdbc_admin/packagedjdbc.html

IBM Worklight - How to use adapter domain and port properties taken from external file?

I have a web service. Its domain and port can be changed. So I want to read port and domain from file or db. When this information change, I update them in db or file.
Adapter XML:
<domain>${adp.hostname}</domain>
<port>${adp.port}</port>
worklight.properties:
adp.hostname=localhost
adp.port=10080
This is working fine. But I'd like to take adp.hostname and adp.port from file or db.
Something to remember about adapters is that you cannot change in real-time any of the properties set in the adapter XML once it is deployed.
Once the adapter is deployed, it is transformed into an object and is stored in memory. At this time, then, you can no longer interact with its "setup".
The only thing you can do, is to decide what will be the value of these properties before your deploy the adapter. For example, a different set of properties for QA/TEST/UAT/PROD environments...
To setup external properties, starting Worklight 6.0 and above, you can read this documentation topic: Configuring an IBM Worklight project in production by using JNDI environment entries
Specifically for Tomcat in its server.xml:
<Context docBase="app_context_path" path="/app_context_path">
<Environment name="publicWorkLightPort" override="false"
type="java.lang.String" value="9080"/>
</Context>
You change app_context_path to your project's context (project name)
You add environment child elements for each property you need
Important to remember: these properties must also exist in worklight.properties; those will be the default properties, and if using the above example they will be over-written and the environment properties will be used instead.
In the example above you can see that it will replace the default property publicWorkLightPort.