0

我正在使用谷歌应用引擎。当我从我的网站发送 ajax 请求时。我得到以下异常:

 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)

我正在使用 Eclipse 和 JDK 1.6.6 的谷歌应用引擎插件。对于持久性,我使用以下类: public class PMF {

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

private PMF(){}

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

在代码中我坚持一个对象,如下所示:

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

我的用户类的代码如下:

 @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

 }  

我正在使用简单的 java Servlet。

本地一切正常,但是当我在 google appengine 上上传我的网络应用程序时,就会出现这个异常。谁能知道它为什么会发生,我该如何解决?提前致谢。

4

1 回答 1

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?

于 2012-07-20T23:41:37.333 回答