代码之家  ›  专栏  ›  技术社区  ›  aldrin

google app engine/java上带有grails时区选择标记的IllegaAccess异常

  •  1
  • aldrin  · 技术社区  · 15 年前

    有人在GAE/J上使用过grails timeZoneSelect标记吗?我在AppEngine上遇到了下面的错误。我知道反射是不允许的,但出错的行似乎在调用一个简单的公共函数(inDaylightTime)?有人知道如何解决这个问题吗(除了硬编码的时区列表)?

    谢谢

    Uncaught exception from servlet
    org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: Error executing tag : org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Error executing tag : java.lang.IllegalAccessException: Reflection is not allowed on public boolean sun.util.calendar.ZoneInfo.inDaylightTime(java.util.Date)
        at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:97)
        at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
        at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
        at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:238)
        at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
        at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:135)
        at com.google.apphosting.runtime.JavaRuntime.handleRequest(JavaRuntime.java:235)
        at com.google.apphosting.base.RuntimePb$EvaluationRuntime$6.handleBlockingRequest(RuntimePb.java:5235)
        at com.google.apphosting.base.RuntimePb$EvaluationRuntime$6.handleBlockingRequest(RuntimePb.java:5233)
        at com.google.net.rpc.impl.BlockingApplicationHandler.handleRequest(BlockingApplicationHandler.java:24)
        at com.google.net.rpc.impl.RpcUtil.runRpcInApplication(RpcUtil.java:363)
        at com.google.net.rpc.impl.Server$2.run(Server.java:838)
        at com.google.tracing.LocalTraceSpanRunnable.run(LocalTraceSpanRunnable.java:56)
        at com.google.tracing.LocalTraceSpanBuilder.internalContinueSpan(LocalTraceSpanBuilder.java:536)
        at com.google.net.rpc.impl.Server.startRpc(Server.java:793)
        at com.google.net.rpc.impl.Server.processRequest(Server.java:368)
        at com.google.net.rpc.impl.ServerConnection.messageReceived(ServerConnection.java:448)
        at com.google.net.rpc.impl.RpcConnection.parseMessages(RpcConnection.java:319)
        at com.google.net.rpc.impl.RpcConnection.dataReceived(RpcConnection.java:290)
        at com.google.net.async.Connection.handleReadEvent(Connection.java:466)
        at com.google.net.async.EventDispatcher.processNetworkEvents(EventDispatcher.java:759)
        at com.google.net.async.EventDispatcher.internalLoop(EventDispatcher.java:205)
        at com.google.net.async.EventDispatcher.loop(EventDispatcher.java:101)
        at com.google.net.rpc.RpcService.runUntilServerShutdown(RpcService.java:251)
        at com.google.apphosting.runtime.JavaRuntime$RpcRunnable.run(JavaRuntime.java:394)
        at java.lang.Thread.run(Unknown Source)
    Caused by: org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Error executing tag : org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException: Error executing tag : java.lang.IllegalAccessException: Reflection is not allowed on public boolean sun.util.calendar.ZoneInfo.inDaylightTime(java.util.Date)
    
    4 回复  |  直到 15 年前
        1
  •  1
  •   Feargal    15 年前

    当我试图调用TimeZone.getTimeZone()来获取一个时区,并使用另一个库Joda Time来解决这个问题时,我遇到了类似的问题。

    http://joda-time.sourceforge.net/index.html

    这个包中有一些等效的时间/日期方法,它们比底层JDK中的方法工作得更好。

        2
  •  1
  •   David P. Caldwell    15 年前

    这是特定于使用反射在sun上调用方法的动态语言。*java.util.TimeZone工厂方法返回的对象;我绕过了时区的类似限制,用Java编写了一个包装器方法,然后调用该方法,这样sun.*对象上的调用就不会通过反射进行。

        3
  •  1
  •   Jonathan    15 年前

    public Date getDateWithTimeZone(Date date, String timeZone){
        def tz = TimeZone.getTimeZone(timeZone);
        def cal = Calendar.getInstance()
        cal.setTimeInMillis( date.getTime() )
        cal.setTimeZone( tz )
        def offset = cal.get(Calendar.ZONE_OFFSET)
        date.setTime( date.getTime()+offset )
        return date;
    }
    
        4
  •  0
  •   David P. Caldwell    15 年前

    以下是我所做工作的Java部分:

    package inonit.google.appengine.runtime;
    
    import java.util.*;
    
    public class Methods {
        public int getTimezoneOffset(String timezone, long time) {
            return TimeZone.getTimeZone(timezone).getOffset(time);
        }
    }
    

    我的应用程序不是Grails,而且我对Grails的了解还不够,不知道Grails定义的抽象是否能让调用像这样的类变得容易。但在我的应用程序中,我只是继续实例化这个对象的本地助手副本,并在需要计算时区偏移时调用它。

    推荐文章