[英]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.