0
votes

I am building a HTTP Adapter in Worklight. Normal communication between the server and application works great, but I need to retrieve an image from the server. The image can be downloaded using a URL which contains the image ID, but I don't know how I can return the whole URL and not only the path. A simple version of my function is:

function getFile(id) {
    if (typeof id == 'undefined') return {isSuccesful : false};

    return {isSuccesful : true, url : '/api/media/get/' + id.toString()};
}

But my path returns only:

'/api/media/get/1'

The URL I need is:

'http://www.example.com/api/media/get/1'

How can I retrieve the domain from the .xml file?

1
Are you asking you want to return the URL of the WorklightServer ?Kawinesh SK
I want to retrieve the URL the Worklight Server communicates with. At the moment this is a Tomcat server which runs local on my computer, but in the future it will be another URL. The reason I need to know this, is because this adapter will be used in multiple occasions and I don't want to change to much in the settings (one file if possible).Sietse
Saying you want the adapter URL which you are trying to access right :)Kawinesh SK
No, I think I can't explain it right. I am trying to get the domain which is set in de adapter .xml file. Which is my local tomcat server at the moment, but will be hosted on another server when going into production. It is the domain in the .xml file inside the connectivity -> connectionPolicy -> domain node.Sietse

1 Answers

1
votes

Starting MobileFirst Platform (Worklight) 6.3, there is client-side API to get/get the Server URL the application will attempt connecting to/send requests to.

See the following blog post which expends and demonstrates using WL.App.getServerURL/getServerURL: Changing the Server URL during runtime

If you are referring to the URL that you have set in the Adapter XML file (meaning the address the adapter request will be sent to from the server), then you cannot retrieve this address during runtime.

If you are using MobileFirst Platform 7.0, then you can now use multiple URLs in the same adapter: Changing the adapter host at runtime