HTTP Request from Business Logic

I have tried numerous libraries to make HTTP request from my Business Logic code, however they’ve all ended up giving me different types of errors (namely calls that are designed to be synchronous actually making asynchronous calls and so unable to run on server side Java).

Are there any recommendations for making a simple HTTP GET request from Backendless business logic? Any examples of working code?

Thank you; I’ve spent many hours with this :confused:

Hi,

You can use HttpURLConnection. But don’t forget to add host you are trying to call to external hosts in backendless application settings.

Regards,

Denys

What exactly do you mean by “external host”? I’m just trying to retrieve data from the following API’s:

https://api.forecast.io/forecast/
https://api.seatgeek.com/2/events

Do I have to add something related to those to be able to access their API’s from server side code?

Is that why I am getting this error:

SEVERE: access denied ("java.net.SocketPermission" "api.forecast.io:443" "connect,resolve")

Thank you

Denys meant this:

https://backendless.com/documentation/manage/mgmt_external_hosts.htm

Yes, I see but I am now wondering if the API’s I referenced are considered “external hosts”. When I try to add “http://api.forecast.io:443/” as an external host it does not let me enter it.

this:
http://api.forecast.io:443/

is a URL

but this:
api.forecast.io

is a hostname…

So add just the hostname and that will start the approval process.

I got the host name approved yet I still get the error:


SEVERE: access denied ("java.net.SocketPermission" "api.forecast.io:443" "connect,resolve")

Hi,

Internal ticked has been created for this issue.

Regards,

Denys

Any update?

Okay well I don’t know how I’m supposed to use Backendless business logic if it doesn’t let me access any API’s. The previous BaaS I used did all this fine and there wasn’t even an approval process for every API I wanted to access.

Is this for debug mode or production?

If the former, the hostname must be added to bin/runner.properties file (see the property at the bottom of the file). If the latter, the problem might be related to the host responding with different IP addresses. This is what Denys referred when he said there is an internal ticket.

Added it to my properties file as you recommended:

http://support.backendless.com/public/attachments/015dfd14887dd8601f38e41cbbd45695.png</img>
And still get the same error:

SEVERE: access denied ("java.net.SocketPermission" "api.forecast.io:443" "connect,resolve")

015dfd14887dd8601f38e41cbbd45695.png

Please, check the availability of this host using the following code:
InetAddress.getByName(“api.forecast.io”).isReachable(5000);