简体   繁体   English

Google App Engine / Java上带有grails timeZoneSelect标记的IllegalAccessException

[英]IllegalAccessException with grails timeZoneSelect tag on google app engine/java

Has anyone used the grails timeZoneSelect tag on GAE/J ? 有人在GAE / J上使用过grails timeZoneSelect标签吗? I've come across the error below on app engine. 我在应用引擎上遇到以下错误。 I know reflection is not allowed, but the line in error seems to be calling a straightforward public function (inDaylightTime)? 我知道不允许反射,但是错误行似乎正在调用简单的公共函数(inDaylightTime)? Does anyone know how to workaround this (short of a hardcoded list of time zones)? 有谁知道如何解决此问题(缺少硬编码的时区列表)?

thanks 谢谢

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)

This is specific to dynamic languages which use reflection to invoke methods on the sun.* objects returned by java.util.TimeZone factory methods; 这是特定于动态语言的,这些动态语言使用反射在sun。*对象上调用方法。java.util.TimeZone工厂方法返回的对象; I worked around a similar limitation in the TimeZone stuff by writing a wrapper method in Java and then calling that method, so that the invocations on the sun.* objects wouldn't be via reflection. 通过在Java中编写包装方法,然后调用该方法,我解决了TimeZone方面的类似限制,以便对sun。*对象的调用不会通过反射进行。

I had a similar problem when I tried to call TimeZone.getTimeZone() to get a TimeZone and worked around this one by using a different library, Joda Time. 当我尝试调用TimeZone.getTimeZone()来获取TimeZone并通过使用另一个库Joda Time解决该问题时,我遇到了类似的问题。

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

There are equivalent time/date methods in this package that work better than those in the underlying JDK. 此程序包中的等效时间/日期方法比基础JDK中的方法更有效。

the below works for me 下面对我有用

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;
}

Here's the Java half of what I did: 这是我所做的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);
    }
}

My application isn't Grails, and I don't know enough about Grails to know whether the abstractions defined by Grails would make it easy to call into a class like this one or not. 我的应用程序不是Grails,而且我对Grails的了解还不足以了解Grails定义的抽象是否可以使调用此类的类变得容易。 But in my app I just went on to instantiate a local helper copy of this object and call into it when I needed to calculate timezone offsets. 但是在我的应用程序中,我只是继续实例化此对象的本地帮助程序副本,并在需要计算时区偏移量时调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM