Now that support for connecting to external sites with CBL has been released, I applied for (and was accepted) weather.livedoor.com. This site has REST API to get Japanese weather info. Using the following Java code I still get a socket permission error and am unable to connect.
@Asset( "Order" )
public class OrderTableEventHandler extends com.backendless.servercode.extension.PersistenceExtender<Order>
{
@Override
public void beforeCreate( RunnerContext context, Order order ) throws Exception
{
// add your code here
String openURL = "http://weather.livedoor.com/forecast/webservice/json/v1?city=400010";
System.out.println( "opening URL: " + openURL);
URL u;
InputStream is = null;
DataInputStream dis;
String s;
u = new URL(openURL);
is = u.openStream();
dis = new DataInputStream(new BufferedInputStream(is));
while ((s = dis.readLine()) != null) {
System.out.println(s);
}
is.close();
}
}
When I run the following curl command I get the error below it, and on the CodeRunner console all I see is the above System.out.println( "opening URL: " + openURL); output but with no JSON response content thereafter, as I would expect if able to successfully connect.
curl -H application-id:XXXXX -H secret-key:XXXXXXX name\":\"foobar corp\"}" -v https://api.backendless.com/v1/data/Order
error:
* Connection #0 to host api.backendless.com left intact
{"message":"access denied (\"java.net.SocketPermission\" \"weather.livedoor.com:80\" \"connect,resolve\")","code":0}