IBM Worklight - How to change dynamically domain/hostname to which the adapter connects from the client at launch or runtime? - ibm-mobilefirst

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>

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"/>

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.

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.

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

Related

how to configure http adapter for physic device

Good days
Please i am working with mobilefirst in one project which needs http adapter.
My adapter give a good answers when in run it in to mobilefirst server,but when i create an android environement and deside to run the same project in my physic android device (my android phone),this return error.
I try to get solution without reponse please help me thank you.
this is the adapter xml file :
<wl:adapter name="RSSFeed"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wl="http://www.ibm.com/mfp/integration"
xmlns:http="http://www.ibm.com/mfp/integration/http">
<displayName>RSSFeed</displayName>
<description>RSSFeed</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>http</protocol>
<domain>www.ibm.com</domain>
<port>80</port>
<connectionTimeoutInMilliseconds>30000</connectionTimeoutInMilliseconds>
<socketTimeoutInMilliseconds>30000</socketTimeoutInMilliseconds>
<maxConcurrentConnectionsPerNode>50</maxConcurrentConnectionsPerNode>
<!-- Following properties used by adapter's key manager for choosing specific certificate from key store
<sslCertificateAlias></sslCertificateAlias>
<sslCertificatePassword></sslCertificatePassword>
-->
</connectionPolicy>
</connectivity>
<procedure name="getFeeds"/>
<procedure name="getFeedsFiltered"/>
</wl:adapter>
this is the error message :
enter image description here
this is complete error message :
enter image description here
Would've been easier had you provide basic information such as:
The error message...
The adapter XML file
Since you did not provide anything, here are some basic debugging items you should check for:
Make sure that in the adapter XML you are point in the host property to an actual IP address of the server the adapter should connect to. i.e not localhost
Make sure the device and the MobileFirst Server are connected to the same network
Print the error you receive in the client once the adapter request fails, and act upon it: http://www.ibm.com/developerworks/websphere/techjournal/1212_paris/1212_paris.html

How do I set an adapter's security test to come from worklight.properties?

My company is working on an application developed with MobileFirst v6.3. I'm looking at creating a server configuration that will allow the server to bypass our standard security test.
This is the type of entry I'm looking to make in my worklight.properties file:
#############
# Worklight Security Test
#############
mt.adapter.security=custom-security-test
And this is how I'm trying to place the value in the adapter's procedure:
<procedure name="getTechUserAdapter" securityTest="${mt.adapter.security}"/>
When I build and deploy it, I get this error:
<error mbeanName="com.worklight.common.server.jmx.api:qualifier=worklight,type=ProjectManagement" node="worklight///10.16.109.75" date="2016-06-02T19:58:02.889Z" phase="PREPARE" code="FAILURE" details="Procedure &apos;getTechUserAdapter&apos; in adapter &apos;TechUserServiceAdapter&apos; requires security test &apos;${mt.adapter.security}&apos; which is not defined in authenticationConfig.xml.">
Worklight is trying to translate it the security test as a string, and not the value that was placed in the worklight.properties file. Does anyone know how to make it use the variable value?
The security test definition does not support custom properties like what you're trying to do... it looks at the authenticationConfig.xml file.
Instead you may need to keep multiple configurations and swap between them before you build the adapter.

How to enable Worklight adapter to do remote JMS lookup

I have a Worklight 6.1 environment installed on a WAS ND application server profile.
My requirement is to connect to an external WebSphere MQ JMS queue manager using the Worklight JMS adapter component
I have created the necessary JMS definitions on the MQ queue manager
Connection Factory = mqWLCF
Queue Definition = TESTQ
I'm unable to get the adapter to work when installed to the Worklight environment on the WAS ND server
The connection code in the adapter xml file is -
<connectivity>
<connectionPolicy xsi:type="jms:JMSConnectionPolicyType">
<namingConnection url="tcp:/192.168.0.100:1417"
initialContextFactory="com.sun.jndi.fscontext.RefFSContextFactory"/>
<jmsConnection
connectionFactory="mqWLCF"/>
</connectionPolicy>
</connectivity>
What is the correct syntax in the adapter xml file ??
<connectivity>
<connectionPolicy xsi:type="jms:JMSConnectionPolicyType">
<namingConnection url="tcp:/127.0.0.1:61616"
initialContextFactory="org.apache.activemq.jndi.ActiveMQInitialContextFactory"
user="admin"
password="admin"/>
<jmsConnection
connectionFactory="ConnectionFactory"
user="admin"
password="admin"
/>
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="10"/>
</connectivity>
You can find more information regarding JMS adapter here:
http://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v620/04_05_JMS_adapter_-_Communicating_with_JMS.pdf
The naming connection URL and initial context factory must go hand in hand. For example, in the example you have provided, the ICF is RefFSContextFactory whereas the URL is a tcp:/ URL (this corresponds to Active MQ - as Shmulik has answered). If you do not want to use file system, then you must mention what ICF do you want to use.
You can use LDAP for which the ICF will be com.sun.jndi.ldap.LdapCtxFactory and you must have the URL as ldap://.....
Similarly, for a lookup within WAS environment, you must have an ICF com.ibm.websphere.naming.WsnInitialContextFactory and the corresponding URL.

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.

IBM Worklight 5.0.6.1 - Failed adapter deployment

I'm having a problem while trying to deploy an adapter to Worklight Console.
I figured out that the adapter which is reading the worklight.properties file does not get deployed. But an adapter that does not read the worklight.properties file is able to deploy without any problem.
I looked at the WAS log and its seems that the unsuccessful adapter deployment was actually deployed, but then they got rollbacked (undeployed) immediately.
Using Worklight 5.0.6.1 with latest iFix.
Edit:
Verified that both server and studio are using the same worklight version
The same configuration working fine in the UAT environmenet; problem happens only in the Production environment.
The Adapter XML:
<displayName>ConfigFileAdapter</displayName>
<description>ConfigFileAdapter</description>
<connectivity>
<connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
<protocol>${adapter.config.protocol}</protocol>
<domain>${adapter.config.domain}</domain>
<port>${adapter.config.port}</port>
<!-- Following properties used by adapter's key manager for choosing specific certificate from key store
<sslCertificateAlias></sslCertificateAlias>
<sslCertificatePassword></sslCertificatePassword>
-->
</connectionPolicy>
<loadConstraints maxConcurrentConnectionsPerNode="30" />
</connectivity>
<procedure name="getConfigData" securityTest="adapterProtectionTest" requestTimeoutInSeconds="10" />
<procedure name="getLoggingLevel" securityTest="adapterProtectionTest" requestTimeoutInSeconds="10" />
</wl:adapter>
Logs captured in SystemOut.log:
com.worklight.integration.services.impl.DeployServiceImpl
syncAdaptersFromDB FWLSE0084I: Deployed adapter 'xxx' successfully.
com.worklight.integration.services.impl.DeployServiceImpl
deleteAdapterInternal FWLSE0039I: Deleted adapter 'xxx' successfully.
From the log the adapter were deleted immediate after deployed.
Make sure that the .war file you have deployed to the Production environment contains a worklight.properties file that contains these adapter.config.protocol/host/port properties.
In my testing the only time I could not deploy an adapter that uses custom properties from worklight.properties was when these properties did not exist in worklight.properties. When this happened I saw this error: Failed to deploy adapter 'test.adapter'. Could not resolve placeholder 'test.idan'