Google App Engine in Java crashes with 'AccessControlException: access denied...' Exception

3 views
Skip to first unread message

Earthling via StackOverflow

unread,
Mar 28, 2016, 7:55:04 AM3/28/16
to google-appengin...@googlegroups.com

Basically trying to connect to my Cloud SQL Database via my Eclipse Java Web Project

Checklist

1) Updated my Google App Engine SDK to the latest 1.9.34 version

2) Updated my JDBC com.mysql.jdbc.Driver to the latest 5.1.38 version

3) Added the JDBC Driver to the build path

I can't connect at all to Google Cloud SQL and crashes with this error:

java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "modifyThreadGroup")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:372)
    at java.security.AccessController.checkPermission(AccessController.java:559)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:429)
    at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkAccess(DevAppServerFactory.java:454)
    at java.lang.ThreadGroup.checkAccess(ThreadGroup.java:315)
    at java.lang.Thread.init(Thread.java:391)
    at java.lang.Thread.init(Thread.java:349)
    at java.lang.Thread.<init>(Thread.java:445)
    at java.util.TimerThread.<init>(Timer.java:499)
    at java.util.Timer.<init>(Timer.java:101)
    at java.util.Timer.<init>(Timer.java:146)
    at com.mysql.jdbc.ConnectionImpl.<clinit>(ConnectionImpl.java:208)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:191)
    at com.google.appengine.tools.development.agent.runtime.RuntimeHelper.checkRestricted(RuntimeHelper.java:70)
    at com.google.appengine.tools.development.agent.runtime.Runtime.checkRestricted(Runtime.java:65)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)
    at java.sql.DriverManager.getConnection(DriverManager.java:571)
    at java.sql.DriverManager.getConnection(DriverManager.java:233)
    at com.dinuka.myapp.servlets.PlanServlet.doPost(PlanServlet.java:59)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Searched all day and literally went through every related question on Stackoverflow. I'm about to pull my hair out :D

Here's my ridiculously simple code to connect to my DB. Can't believe what I've done wrong:

public class MyServlet extends HttpServlet {

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {

        String url = null;
        try {
            if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
                // Load the class that provides the new "jdbc:google:mysql://" prefix.
                Class.forName("com.mysql.jdbc.GoogleDriver");
                url = "jdbc:google:mysql://app_id:instance_id/data?user=root";
            } else {
                // Local MySQL instance to use during development.
                Class.forName("com.mysql.jdbc.Driver");
                url = "jdbc:mysql://instance-ip:3306/data?user=root";
            }
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

        PrintWriter out = resp.getWriter();
        try {
            Connection conn = DriverManager.getConnection(url);
            System.out.println("Connection established");
            out.println("Connection established");
            try {
            } finally {
                conn.close();
            }
        } catch (SQLException e) {
            out.append(e.getMessage());
            e.printStackTrace();
        }
    }

}

Please fix this bug, Google team! And in the meantime, can someone help me get through this?



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/36261678/google-app-engine-in-java-crashes-with-accesscontrolexception-access-denied

Earthling via StackOverflow

unread,
Mar 28, 2016, 11:05:04 AM3/28/16
to google-appengin...@googlegroups.com

FINALLY! Fixed it! To anyone who's out there facing this problem. Here's how you fix it!

STEP 1: Keep your moral up and Stay positive (Trust me, I know)

STEP 2: Update your Google App Engine SDK to the latest. Check the latest SDK from this link => https://cloud.google.com/appengine/downloads

STEP 3: Update your JDBC Driver to the latest. Check the latest from this link => https://dev.mysql.com/downloads/connector/j/

STEP 4: Here's how you properly add your JDBC jar to your Project: Copy and paste it to your lib folder (war/WEB-INF/lib). Right click on your Eclipse Project and click on Build Path -> Configure Build Path. Click on 'Add JARs' and go to your lib folder and select the mysql-connector-java file you just copied. Click Apply and Ok.

STEP 5: Clean and Build your Project

STEP 6: I don't know if this is necessary BUT let's do this anyway. Right click on your project and go to Properties.

STEP 7: Expand the 'Google' section and select App Engine. Make sure Google Cloud SQL is enabled (checked) and select the Use Google Cloud SQL instance radio button.

STEP 8: On the right of that radio button, you'll see a link called 'Configure'. Click on that and fill the fields with your instance name, database name, etc and click OK.

STEP 9: Below the radio button we saw earlier, you should see another link called configure next to a label called 'App Engine SQL instance'. Click on the configure and fill the fields with the instance name, db name, etc like we did before. Click OK and close the Properties Window.

LAST STEP: Clean and Build your project again and Run it. If you followed all the steps correctly, you should be connected to the all mighty Google Cloud.

Took me way too much time to figure this out and I know I can simplify someone else's day with this answer. Good luck!

-Dinuka Jayasuriya, Future Googler ;)



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/36261678/google-app-engine-in-java-crashes-with-accesscontrolexception-access-denied/36265015#36265015
Reply all
Reply to author
Forward
0 new messages