I want to send ping stream which is in StringBuffer sb, to server but I am getting
java.security.AccessControlException: access denied (java.lang.RuntimePermission createSecurityManager)
Please help someone still struggling for day......
private void pushRawDataFilesToServer(StringBuffer sb) {
URL url;
try {
url = new URL("http://<ip>:8080/<appname>/WritePingData");
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection)url.openConnection();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setDefaultUseCaches(false);
try {
BufferedWriter serverbfw = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()));
serverbfw.write(sb.toString());
serverbfw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
You can't create your own SecurityManager in an applet (in any thread). The SecurityManager is configured by the local system as the whole point of a SecurityManager is to protect the local system (so it would be pointless to allow the applet to control its own security).
finally My problem is solved, after calling my own function from below block of code.
AccessController.doPrivileged(new PrivilegedAction<String>() {
@Override
public String run() {
myFunctionToPing();
return null;
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.