norman-d
(Norman D)
April 7, 2016, 12:50pm
1
Hey Guys,
I just tried to test my Hosted Service by using it in debug mode. I get the following exception:
{
"code": 0,
"message": "Type:\"java.lang.RuntimeException\", Description:\"java.security.AccessControlException: access denied (\"java.net.SocketPermission\" \"api.football-data.org:80\" \"connect,resolve\")\"\nExceptionClass:\"ServiceException\" {Msg:\"none\", Cause:\"none\"}"
}
I use CodeRunner to debug the code locally. Here I can´t see any problems.
Furthermore the mentioned URL is already approved for my account.
Any idea?
Thanks!
Hi Norman,
you have to define the host you want to use in Developer’s console.
Manage → External Hosts in Business Logic
Once the host is reviewed by Backendless, you will receive an email informing you about the approval decision. Most reviews are done with 24 hours of submission.
Regards,
Stanislav
norman-d
(Norman D)
April 7, 2016, 1:05pm
3
Thanks you Stanislav -
As I said:
Furthermore the mentioned URL is already approved for my account.
Any other ideas?
Sorry, I missed that its already approved…
I’ve created an internal ticket to investigate this issue, soon our developer will contact with you to solve your problem.
Assigned tag is BKNDLSS-12275.
Stanislav
norman-d
(Norman D)
April 7, 2016, 1:21pm
5
Thank you very much for the prompt resonse!
Hi, Norman.
Could you send your application-id on support@backendless.com for investigation you problem.
i just tried to make connection from your app to http://api.football-data.org - and all works.
Coud you print here code example ?
norman-d
(Norman D)
April 8, 2016, 9:31am
9
Hi Oleg,
Thanks for your answer.
Exactly, I use the API for other hosted files as well and it works. But if I try to use CodeRunner to debug my code, I get the mentioned error.
This would be the code:
try {
String urlString = "http://api.football-data.org/v1/soccerseasons/" + season + "/fixtures?matchday=" + matchday;
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("X-Auth-Token", "12345");
conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
}
// read from the URL
Scanner scan = new Scanner(url.openStream());
while (scan.hasNext())
str += scan.nextLine();
scan.close();
conn.disconnect();
}
Here my code example (and it works):
String urlString = “http://api.football-data.org ”;
URL url = new URL(urlString);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod(“GET”);
conn.setRequestProperty(“X-Auth-Token”, “12345”);
conn.setRequestProperty(“Content-Type”, “application/json;charset=utf-8”);
if (conn.getResponseCode() != 200)
throw new RuntimeException("Failed : HTTP error code : " + conn.getResponseCode());
// read from the URL
Scanner scan = new Scanner(conn.getInputStream());
String str = “”;
while (scan.hasNext())
str += scan.nextLine();
scan.close();
conn.disconnect();
return str;
norman-d
(Norman D)
April 8, 2016, 2:04pm
11
I think it must be related to the code runner environment. When I upload the file the exception does not show up, it´s just when I test it via Idea.
If you debug you code locally, you should add hosts to …/bin/runner.properties
norman-d
(Norman D)
April 8, 2016, 3:53pm
13
That´s it! Thank you very much!!!