Backendless Support
 
Solved

Approved host is causing access denied exception in business logic timer.

I had the host api.datamarket.azure.com approved in the management console. I get the following exception when executing a debug version of a timer. What can I do to fix this? I have re-downloaded the generated code, rebuilt it, and restarted CodeRunner.sh several times.

Code which is being used:

  1. final String accountKey = "(MY KEY)";
  2. final String bingUrlPattern = "https://api.datamarket.azure.com/Bing/Search/v1/News?Query=%27QUERY%27&$format=JSON";;
  3. System.out.println(bingUrlPattern);
  4. final String accountKeyEnc = Base64.getEncoder().encodeToString((accountKey + ":" + accountKey).getBytes());
  5. final URL url = new URL(bingUrlPattern);
  6. final URLConnection connection = url.openConnection();
  7. connection.setRequestProperty("Authorization", "Basic " + accountKeyEnc);

Exception I get:

  1. Feb 26, 2016 5:41:42 AM com.backendless.coderunner.runtime.task.EventInvocationTask runImpl
  2. SEVERE: access denied ("java.net.SocketPermission" "api.datamarket.azure.com:443" "connect,resolve")
  3. java.lang.reflect.InvocationTargetException
  4. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  5. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  6. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  7. at java.lang.reflect.Method.invoke(Method.java:497)
  8. at com.backendless.coderunner.runtime.task.EventInvocationTask.runImpl(EventInvocationTask.java:92)
  9. at com.backendless.coderunner.runtime.concurrent.ExtendedRunnable.run(ExtendedRunnable.java:22)
  10. at java.lang.Thread.run(Thread.java:745)
  11. Caused by: java.security.AccessControlException: access denied ("java.net.SocketPermission" "api.datamarket.azure.com:443" "connect,resolve")
  12. at java.security.AccessControlContext.checkPermission(AccessControlContext.java:472)
  13. at java.security.AccessController.checkPermission(AccessController.java:884)
  14. at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
  15. at com.backendless.coderunner.runtime.security.CodeRunnerSecurityManager.checkPermission(CodeRunnerSecurityManager.java:52)
  16. at java.lang.SecurityManager.checkConnect(SecurityManager.java:1051)
  17. at sun.net.http://www.http.HttpClient.openServer(HttpClient.java:510)
  18. at sun.net.http://www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
  19. at sun.net.http://www.protocol.https.HttpsClient.New(HttpsClient.java:367)
  20. at sun.net.http://www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
  21. at sun.net.http://www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1105)
  22. at sun.net.http://www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:999)
  23. at sun.net.http://www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
  24. at sun.net.http://www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1513)
  25. at sun.net.http://www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
  26. at sun.net.http://www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
  27. at com.backendless.zikaapp.timers.NewsQueryTimer.execute(NewsQueryTimer.java:46)
  28. ... 7 more

Best Answer
photo

Hi Evan,

Open bin/runner.properties. The very last config item is going to be a list of permitted hosts. Add yours in there (twice - with and without necessary port). Make sure to restart your code runner.

Hope this helps.

Mark

Leave a Comment

Comments (4)

photo
1

Hi Evan,

Open bin/runner.properties. The very last config item is going to be a list of permitted hosts. Add yours in there (twice - with and without necessary port). Make sure to restart your code runner.

Hope this helps.

Mark

photo
1

This did it, thank you so much for your incredibly prompt reply!

photo
1

I tried this. Still get this:

java.net.UnknownHostException: backendlesstest.chargify.comm backendlesstest.chargify.comm backendlesstest.chargify.comm backendlesstest.chargify.comm backendlesstest.chargify.comm: unknown error

at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)

at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)

at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)

How should I add api.sendgrid.com using port 443 when that site is https?

photo
1

I get this also when I try to deploy:

[INFO] Waiting for events...

[INFO] Publishing 0 event handlers and 1 timer and 1 service to the server…

java.net.UnknownHostException: backendlesstest.chargify.comm backendlesstest.chargify.comm backendlesstest.chargify.comm backendlesstest.chargify.comm backendlesstest.chargify.comm: unknown error

at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)

at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)

at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)

at java.net.InetAddress.getAllByName0(InetAddress.java:1276)

at java.net.InetAddress.getAllByName(InetAddress.java:1192)

at java.net.InetAddress.getAllByName(InetAddress.java:1126)

at com.backendless.coderunner.holder.ExternalHostHolder.resolveIP(ExternalHostHolder.java:176)

at com.backendless.coderunner.holder.ExternalHostHolder.addUrl(ExternalHostHolder.java:99)

at com.backendless.coderunner.holder.ExternalHostHolder.lambda$setUrls$1(ExternalHostHolder.java:70)

at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1374)

at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)

at com.backendless.coderunner.holder.ExternalHostHolder.setUrls(ExternalHostHolder.java:70)

at com.backendless.coderunner.holder.ExternalHostHolder.getOrCreateAllowedHostsForApp(ExternalHostHolder.java:58)

at com.backendless.coderunner.holder.ExternalHostHolder.setUrls(ExternalHostHolder.java:93)

at com.backendless.coderunner.debugger.BusinessLogicDebugger.publish(BusinessLogicDebugger.java:120)

at com.backendless.coderunner.debugger.InstructionsFetcher.executeCommandSafe(InstructionsFetcher.java:34)

at com.backendless.coderunner.LocalCodeRunner.start(LocalCodeRunner.java:59)

at com.backendless.coderunner.CodeRunnerLoader.launch(CodeRunnerLoader.java:44)

at com.backendless.coderunner.CodeRunnerLoader.main(CodeRunnerLoader.java:30)

[INFO] Successfully published all event handlers and timers.