2

我正在尝试将使用 Weld 1.1.8 的应用程序移植到 Google App Engine。我在 web.xml 中使用一个监听器来引导 Weld:

<listener>
  <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>

该应用程序在常规 Jetty 7 上启动良好。但在 GAE 上启动时,出现问题:

com.google.common.collect.ComputationException: java.security.AccessControlException: access denied (java.lang.RuntimePermission accessDeclaredMembers)
    at com.google.common.collect.ComputingConcurrentHashMap$ComputingMapAdapter.get(ComputingConcurrentHashMap.java:397)
    at org.jboss.weld.resources.ClassTransformer.loadClass(ClassTransformer.java:163)
    at org.jboss.weld.bootstrap.BeanDeployer.loadWeldClass(BeanDeployer.java:108)
    at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:79)
    at org.jboss.weld.bootstrap.BeanDeployer.addClasses(BeanDeployer.java:123)
    at org.jboss.weld.bootstrap.BeanDeployment.createBeans(BeanDeployment.java:184)
    at org.jboss.weld.bootstrap.WeldBootstrap.deployBeans(WeldBootstrap.java:350)
    at org.jboss.weld.environment.servlet.Listener.contextInitialized(Listener.java:182)
    at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:548)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:202)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:171)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:123)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:446)
    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)
Caused by: 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 java.lang.Class.getEnclosingMethod(Class.java:919)
    at sun.reflect.generics.scope.ClassScope.computeEnclosingScope(ClassScope.java:50)
    at sun.reflect.generics.scope.AbstractScope.getEnclosingScope(AbstractScope.java:74)
    at sun.reflect.generics.scope.AbstractScope.lookup(AbstractScope.java:90)
    at sun.reflect.generics.scope.AbstractScope.lookup(AbstractScope.java:90)
    at sun.reflect.generics.factory.CoreReflectionFactory.findTypeVariable(CoreReflectionFactory.java:109)
    at sun.reflect.generics.visitor.Reifier.visitTypeVariableSignature(Reifier.java:165)
    at sun.reflect.generics.tree.TypeVariableSignature.accept(TypeVariableSignature.java:43)
    at sun.reflect.generics.repository.MethodRepository.getReturnType(MethodRepository.java:68)
    at java.lang.reflect.Method.getGenericReturnType(Method.java:254)
    at org.jboss.weld.introspector.jlr.WeldMethodImpl.of(WeldMethodImpl.java:70)
    at org.jboss.weld.introspector.jlr.WeldClassImpl.<init>(WeldClassImpl.java:235)
    at org.jboss.weld.introspector.jlr.WeldClassImpl.of(WeldClassImpl.java:119)
    at org.jboss.weld.resources.ClassTransformer$TransformTypeToWeldClass.apply(ClassTransformer.java:59)
    at org.jboss.weld.resources.ClassTransformer$TransformTypeToWeldClass.apply(ClassTransformer.java:50)
    at com.google.common.collect.ComputingConcurrentHashMap$ComputingValueReference.compute(ComputingConcurrentHashMap.java:355)
    at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.compute(ComputingConcurrentHashMap.java:184)
    at com.google.common.collect.ComputingConcurrentHashMap$ComputingSegment.getOrCompute(ComputingConcurrentHashMap.java:153)
    at com.google.common.collect.ComputingConcurrentHashMap.getOrCompute(ComputingConcurrentHashMap.java:69)
    at com.google.common.collect.ComputingConcurrentHashMap$ComputingMapAdapter.get(ComputingConcurrentHashMap.java:393)
    ... 25 more

我尝试使用旧版本的 Weld 到 1.1.0 无济于事。有关如何解决此类问题的任何线索?

4

2 回答 2

2

您遇到了沙盒限制。

特别是,WeldClassImpl构造函数遍历注解类的层次结构调用WeldMethodImpl.of()每个方法:如果有问题的类扩展了 JRE 或 API 类,那么沙箱将拒绝访问非公共方法;如果 does 类不属于应用程序,沙箱将完全拒绝所有访问。我认为您需要完整的堆栈跟踪来确定在这种情况下它是哪个。

文档中所述

反射

允许应用程序对其自己的类进行完全的、不受限制的、反射式的访问。它可以查询任何私有成员、使用java.lang.reflect.AccessibleObject.setAccessible()和读取/设置私有成员。

应用程序还可以反映 JRE 和 API 类,例如java.lang.Stringjavax.servlet.http.HttpServletRequest。但是,它只能访问这些类的公共成员,而不是受保护的或私有的。

应用程序不能针对不属于自己的任何其他类进行反射,也不能使用该setAccessible()方法来规避这些限制。

于 2012-05-31T21:19:18.937 回答
0

似乎是一个匿名的番石榴函数是原因。

于 2012-06-01T19:46:39.437 回答