2

when i have run java code in server it will showing below exception:

java.security.AccessControlException: access denied ("java.net.SocketPermission" "localhost:15990" "listen,resolve")

here is my java code:

 public String getSessionCookies(String user, String pass,String loginUrl,String phantomPath) {
         StringBuilder builder=new StringBuilder();        
        try{        
             PhantomJSDriverService service = new PhantomJSDriverService.Builder().usingAnyFreePort().usingPhantomJSExecutable(new File(phantomPath)).build();

            DesiredCapabilities caps = new DesiredCapabilities();
            caps.setJavascriptEnabled(true);// not really needed: JS enabled by default
            caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,phantomPath);  
            driver = new PhantomJSDriver(service,DesiredCapabilities.phantomjs());
            driver.get(loginUrl);
            System.out.println(driver.getTitle());
            driver.findElement(By.id("login:loginName")).sendKeys(user);
            driver.findElement(By.id("login:password")).sendKeys(pass);
            waitForJQueryProcessing(driver, 5);
            driver.findElement(By.xpath("/html/body/div[3]/div/div[1]/div[1]/div[15]/div[2]/form/div[2]/button[1]")).click();
            Thread.sleep(10000);
            driver.get("https://ecf.ca2.uscourts.gov/");  
            Thread.sleep(10000);
            Set<org.openqa.selenium.Cookie> allCookies=driver.manage().getCookies();
            for ( org.openqa.selenium.Cookie loadedCookie : allCookies) {
                   builder.append(String.format("%s->%s, ", loadedCookie.getName(),loadedCookie.getValue()));
                   //System.out.println(String.format("%s->%s, ", loadedCookie.getName(),loadedCookie.getValue()));
            }    
            driver.close();
        }catch(Exception e){
            System.out.println(e.getStackTrace());
            writeFile(e.toString(),phantomPath);
        }
        return builder.toString();
    }

above code run perfectly in local system but when i have to call in server it will generate above exception.

please provide your suggestion.

thanks

Atul Thakre
  • 502
  • 3
  • 8
  • 24
  • 1
    possible duplicate of [java.security.AccessControlException: access denied ("java.net.SocketPermission" "localhost:10648" "listen,resolve")](http://stackoverflow.com/questions/27655288/java-security-accesscontrolexception-access-denied-java-net-socketpermission) – Surya Dec 29 '14 at 12:11
  • @Surya: how to resolved this? – Atul Thakre Dec 29 '14 at 12:27
  • This link my be of help? - http://rijkswatch.blogspot.in/2014/02/start-java-db-access-denied.html – Surya Dec 29 '14 at 12:33
  • @Surya:i have check my local system java.policy is it already available and my code working perfectly in local system. how to run on server? – Atul Thakre Dec 29 '14 at 12:37

1 Answers1

1

Add permission java.net.SocketPermission "localhost:15990", "listen, resolve"in your java.policy file. You can find this file located in your jre > lib > security folder

Vivek Singh
  • 3,641
  • 2
  • 22
  • 27