IBM Worklight - How to change dynamically domain/h

2019-01-19 23:10发布

问题:

When configuring WL HTTP Adapters, the domain and port are part of the adapter configuration .xml file build and uploaded on the WL server. For our use case (especially beta testing and demos) the endpoint server url needs to be configurable for the end user. Example, same builds are tested by QA on test envs, while BA connects to demo. We have only one WL Server up and setting environment specific servers is not an option.

Is it possible to change domain/hostname dynamically at application launch or runtime ? Ideally it would be to get and use the domain/hostname value from a drop down or free input from the client and use it.

<connectivity>
        <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
            <protocol>http</protocol>
            <domain>{hostname}</domain>
            <port>80</port>         
        </connectionPolicy>
        <loadConstraints maxConcurrentConnectionsPerNode="2" />
    </connectivity>

回答1:

Update: This answer is useful, so I leave it here for reference, but accept that it doesn't correctly answer this question!

There is a specific Worklight feature designed to address your scenario (for the Infocenter detail, see here).

You can do this by using a combination of worklight.properties and JNDI properties.

For example, let's say you had this setup in your adapter XML:

 <connectivity>
        <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
            <protocol>${my.adapter.protocol}</protocol>
            <domain>${my.adapter.domain}</domain>
            <port>${my.adapter.port}</port>         
        </connectionPolicy>
        <loadConstraints maxConcurrentConnectionsPerNode="2" />
 </connectivity>

You then define default values for these in your worklight.properties file (in the server/conf directory of your Worklight project, and "burnt in" to the .WAR file when you build it):

my.adapter.protocol=http
my.adapter.domain=some.host.com
my.adapter.port=80

You can then override these values in individual environments, by setting JNDI properties. For example, if you are using WebSphere Liberty, you might put this in your server.xml:

<jndiEntry jndiName="my.adapter.protocol" value="https"/>
<jndiEntry jndiName="my.adapter.domain" value="some.other.host.com"/>
<jndiEntry jndiName="my.adapter.port" value="8080"/>


回答2:

You could create 3 adapters: 2 adapters connect to each backend servers, and one "proxy" adapter.

Your application would call the proxy adapter, passing some variable (the dropdown). Then the proxy would call one of the 2 real adapters.



回答3:

You can´t. An option is to use MashUps.

See:

  • IBM Worklight 6.1 - Can a HTTP adapter call another HTTP adapter on server-side?

  • http://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v620/04_11_Advanced_adapter_usage_and_mashup.pdf

The idea is to have an Adapter responding to app mobile than this adapter call other deployed adapter (QA, Test Env, Prod Env, etc) considering any logic.



回答4:

I think if you override WL.Server.invokeHttp so you can specify the domain name in each request instead of using the one set in the XML file, would a good alternative . You can get the domain name as parameter in the invocation request.

There is question that may interest you regarding that, you should check it because I'm not sure if it's possible or not. Worklight Adapter Override Origin of request