IBM Worklight - How to use adapter domain and port

2019-08-28 16:17发布

问题:

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.

回答1:

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>
  1. You change app_context_path to your project's context (project name)
  2. 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.