[英]IllegalAccessException with grails timeZoneSelect tag on google app engine/java
有人在GAE / J上使用过grails timeZoneSelect标签吗? 我在应用引擎上遇到以下错误。 我知道不允许反射,但是错误行似乎正在调用简单的公共函数(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)
这是特定于动态语言的,这些动态语言使用反射在sun。*对象上调用方法。java.util.TimeZone工厂方法返回的对象; 通过在Java中编写包装方法,然后调用该方法,我解决了TimeZone方面的类似限制,以便对sun。*对象的调用不会通过反射进行。
当我尝试调用TimeZone.getTimeZone()来获取TimeZone并通过使用另一个库Joda Time解决该问题时,我遇到了类似的问题。
http://joda-time.sourceforge.net/index.html
此程序包中的等效时间/日期方法比基础JDK中的方法更有效。
下面对我有用
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;
}
这是我所做的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定义的抽象是否可以使调用此类的类变得容易。 但是在我的应用程序中,我只是继续实例化此对象的本地帮助程序副本,并在需要计算时区偏移量时调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.