I try to access url like by browser i can access it,but by servlet i get :
java.security.AccessControlException: access denied (java.net.NetPermission
setDefaultAuthenticator)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:270)
at java.security.AccessController.checkPermission(AccessController.java:401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
at java.net.Authenticator.setDefault(Authenticator.java:83)
...
I use a following code:
public class MyServlet extends HttpServlet {
public void service(HttpServletRequest req, HttpServletResponse res) throws IOException{
String userName = "username";
String password = "password";
URL url=new URL(" Authenticator.setDefault (new MyAuthenticator (userName,password));
URLConnection uc=url.openConnection();
uc.setAllowUserInteraction(true);
InputStream fi = uc.getInputStream();
}
java.security.AccessControlException: access denied (java.net.NetPermission
setDefaultAuthenticator)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:270)
at java.security.AccessController.checkPermission(AccessController.java:401)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:542)
at java.net.Authenticator.setDefault(Authenticator.java:83)
...
I use a following code:
public class MyServlet extends HttpServlet {
public void service(HttpServletRequest req, HttpServletResponse res) throws IOException{
String userName = "username";
String password = "password";
URL url=new URL(" Authenticator.setDefault (new MyAuthenticator (userName,password));
URLConnection uc=url.openConnection();
uc.setAllowUserInteraction(true);
InputStream fi = uc.getInputStream();
}