0

i am using google app engine. When i send an ajax request from my website. I get following exception:

 Uncaught exception from servlet
 java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:355)
at java.security.AccessController.checkPermission(AccessController.java:567)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
at com.google.apphosting.runtime.security.CustomSecurityManager.checkPermission(CustomSecurityManager.java:56)
at java.lang.SecurityManager.checkMemberAccess(SecurityManager.java:1679)
at java.lang.Class.checkMemberAccess(Class.java:2174)
at java.lang.Class.getDeclaredMethods(Class.java:1807)
at javax.servlet.http.HttpServlet.getAllDeclaredMethods(HttpServlet.java:426)
at javax.servlet.http.HttpServlet.doOptions(HttpServlet.java:477)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:102)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:249)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:135)
at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:477)
at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:449)
at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:455)
at com.google.tracing.TraceContext.runInContext(TraceContext.java:695)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:333)
at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:325)
at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:453)
at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
at java.lang.Thread.run(Thread.java:679)

I am using eclipse with google app engine plugin with JDK 1.6.6. For persistence i am using following class: public class PMF {

private static final PersistenceManagerFactory pmfInstance = JDOHelper.getPersistenceManagerFactory("transactions-optional");

private PMF(){}

public static PersistenceManagerFactory get(){
    return pmfInstance;
}
 }

and in code i am persisting an object like following:

 user.setEmail(userEmail);
 user.setAddress(address);
 user.setFirstName(fName);
 user.setLastName(lName);
 user.setPassword(pwd);
 pm.makePersistent(user);     

Code for my user class is following:

 @PersistenceCapable
 public class User{

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private String userEmail;

@Persistent
private String fName;

    @Persistent
private String lName;

    @Persistent
private String address;

    @Persistent
private String pwd;

    public User(){}

    // getters and setters for all

 }  

And i am using simple java Servlets.

Locally everything is working fine but when i upload my web app on google appengine then this exception comes. Can anybody knows why is it happening and how can i solve it? Thanks in advance.

Piscean
  • 3,069
  • 12
  • 47
  • 96

1 Answers1

0

You're running into an issue due to App Engine's sandboxed environment. This is discussed in other similar posts, and in the Runtime documentation.

Errors like these often only manifest in production because the local environment is similar, but not identical to, the production environment.

Edit

With that said, the following code works just fine locally and in production. It's based on the code you shared, so I'm not entirely sure what the error is.

My User class:

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable
public class User{

  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  private String userEmail;

  @Persistent
  private String fName;

  @Persistent
  private String lName;

  @Persistent
  private String address;

  @Persistent
  private String pwd;

  public User(){}

  public String getUserEmail() {
    return userEmail;
  }

  public void setUserEmail(String userEmail) {
    this.userEmail = userEmail;
  }

  public String getfName() {
    return fName;
  }

  public void setfName(String fName) {
    this.fName = fName;
  }

  public String getlName() {
    return lName;
  }

  public void setlName(String lName) {
    this.lName = lName;
  }

  public String getAddress() {
    return address;
  }

  public void setAddress(String address) {
    this.address = address;
  }

  public String getPwd() {
    return pwd;
  }

  public void setPwd(String pwd) {
    this.pwd = pwd;
  }
}

My servlet:

public class MyTestServlet extends HttpServlet {
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws IOException {
    resp.setContentType("text/plain");
    resp.getWriter().println("Hello, world");

    User user = new User();
    user.setUserEmail("email");
    user.setAddress("address");
    user.setfName("first");
    user.setlName("last");
    user.setPwd("password");
    PersistenceManager pm = PMF.get().getPersistenceManager();
    pm.makePersistent(user);
  }
}

The only thing I can think of is that you're possibly using the incorrect annotations. Can you confirm your annotations match mine?

Community
  • 1
  • 1
Dan Holevoet
  • 9,183
  • 1
  • 33
  • 49
  • i saw those posts before writing this question. But i couldn't solve it. Any solution? – Piscean Jul 21 '12 at 16:31
  • Can you list which libraries and/or annotations you are using in the class causing this exception? – Dan Holevoet Jul 21 '12 at 17:37
  • I edited my question with more details. I hope it will be enough. Thanks – Piscean Jul 23 '12 at 09:26
  • yeah i am using same annotations. Do i need to add any permission in my project? – Piscean Jul 25 '12 at 16:23
  • Do you get the error when you use the code I provided instead of your own? Perhaps the issue is in code you haven't included in your question (the servlet perhaps)? – Dan Holevoet Jul 25 '12 at 16:27
  • I created another application on google app engine and used the same code and it worked. i don't know what was the problem. – Piscean Aug 08 '12 at 10:15