application.getServerUrl() returns the wrong server url

Questions and answers on designing your Servoy solutions, database modelling and other 'how do I do this' that don't fit in any of the other categories

application.getServerUrl() returns the wrong server url

Postby edwin.boon » Fri Aug 26, 2016 10:08 am

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
edwin.boon
 
Posts: 19
Joined: Fri Jul 29, 2016 11:40 am

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

Postby mboegem » Fri Aug 26, 2016 12:33 pm

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.
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image

Partner of Tower - The most powerful Git client for Mac and Windows
User avatar
mboegem
 
Posts: 1743
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

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

Postby edwin.boon » Fri Aug 26, 2016 1:19 pm

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.
edwin.boon
 
Posts: 19
Joined: Fri Jul 29, 2016 11:40 am

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

Postby mboegem » Fri Aug 26, 2016 3:20 pm

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
Marc Boegem
Solutiative / JBS Group, Partner
• Servoy Certified Developer
• Servoy Valued Professional
• Freelance Developer

Image

Partner of Tower - The most powerful Git client for Mac and Windows
User avatar
mboegem
 
Posts: 1743
Joined: Sun Oct 14, 2007 1:34 pm
Location: Amsterdam

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

Postby sbutler » Fri Aug 26, 2016 3:51 pm

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.
Scott Butler
iTech Professionals, Inc.
SAN Partner

Servoy Consulting & Development
Servoy University- Training Videos
Servoy Components- Plugins, Beans, and Web Components
Servoy Guy- Tips & Resources
ServoyForge- Open Source Components
User avatar
sbutler
Servoy Expert
 
Posts: 759
Joined: Sun Jan 08, 2006 7:15 am
Location: Cincinnati, OH


Return to Programming with Servoy

Who is online

Users browsing this forum: No registered users and 10 guests

cron