Page 1 of 1

application.getServerUrl() returns the wrong server url

PostPosted: Fri Aug 26, 2016 10:08 am
by edwin.boon
Hello all,

We have built a web service that give back a max of 200 records. When there are more than 200 records there will be a link at the bottom of the response xml with a new link people can connect to. To build this link we use the application.getServerUrl() + some hard coded code.
The challenge we face right now is that the application.getServerUrl returns localhost:8080/ in the response xml instead of the actual server URL https://autoflex10.nl. When I use logging level to output it in the server log in our application it gives back the actual server URL.
The application and the web-service run on the same server.

Anyone with an idea of where things can go wrong? For us there is nog logic in here.

Thanks in advance

Re: application.getServerUrl() returns the wrong server url

PostPosted: Fri Aug 26, 2016 12:33 pm
by mboegem
Hi Edwin,

I assume that you get the application.getServerUrl() in the webservice.
But for the webservice the serverUrl is localhost as it runs on the application server itself.
So this is expected behaviour.

I think you just need to return the 'hard coded' code that you're speaking of and concatenate that with the server-url you send the request to on the client.

Hope this helps.

Re: application.getServerUrl() returns the wrong server url

PostPosted: Fri Aug 26, 2016 1:19 pm
by edwin.boon
Thanks for the reply. In the end its logical after all.

But is there a way to get lets say the ip adress from that server? We have more then one server (test server, live server)
So it would be nice if we can write the code once instead of change the code for every server.

Re: application.getServerUrl() returns the wrong server url

PostPosted: Fri Aug 26, 2016 3:20 pm
by mboegem
edwin.boon wrote:But is there a way to get lets say the ip adress from that server? We have more then one server (test server, live server)

Not directly, you could use a webservice to request the public IP. There are multiple of those WS out there, although the free of charge ones are not always that stable.

But I wonder why you need it, the way I visualise your situation is:
1) browser sends request to the webservice on the Servoy application server
2) the webserver will do its actions and responds with xml, including your 'more records' code.
3) in the browser you will show the result, and you can concatenate the url you used in step 1 with the 'more records' code from step 2

So in my opinion you already know this external IP as you used this in step 1, no need to do difficult things to retrieve it in step 2

Re: application.getServerUrl() returns the wrong server url

PostPosted: Fri Aug 26, 2016 3:51 pm
by sbutler
Just use the IT2BE Tools plugin: http://www.servoycomponents.com/plugins/tools.php
You can get the server hostname with that plugin, so assuming you have the server configured to return its proper hostname, that would work. Then you can use that in your return URL. So onSolutionOpen, get the hostname, store it in a global, and use it where needed.

Alternatively, you can use application.executeProgram and usually there is a system call to get the hostname of the machine, so you can store that in a global for later use.

Lastly, if you have multiple servers, this kind of stuff can be useful to store in a properties file on the server. So each server has a file myconfig.properties or something, and you set it up with all its own configuration variables, like hostname or ip. Then you read that onSolutionOpen, and set your globals for later user.