2010-01-13 30 views
1

有沒有人在GAE/J上使用grails timeZoneSelect標記?我在應用引擎中發現了以下錯誤。我知道反射是不允許的,但錯誤的線似乎是調用一個簡單的公共函數(inDaylightTime)?有誰知道如何解決這個問題(短硬編碼的時區列表)? 。IllegalAccessException與谷歌應用程序引擎/ java的grails timeZoneSelect標記

感謝

 
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) 
+0

暫且我身邊有這樣使用時區的硬編碼清單的工作。 grails時區標籤每次都遍歷所有時區,導致執行時間超過限制,所以不得不優化頁面。 – aldrin 2010-01-15 14:32:49

+0

您可能想要向Grails和/或GAE報告此問題。也許他們會解決它。 – Thilo 2010-01-18 00:45:54

回答

1

我有一個類似的問題,當我試圖調用TimeZone.getTimeZone()來得到一個時區,並通過使用一個不同的庫,約達時間圍繞這一工作。

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

有相當的時間/日期的方法在這個包,工作比那些在底層的JDK好。

1

這是特定於使用反射來調用方法太陽動態語言*對象由java.util.TimeZone中的工廠方法返回;我通過在Java中編寫包裝器方法,然後調用該方法來解決TimeZone中類似的侷限性,以便對sun. *對象的調用不會通過反射。

+0

你能提供一個這種技術的例子嗎? – aldrin 2010-01-18 03:04:00

0

這裏是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中定義的抽象是否可以很容易地調用進入這樣一個類或不是。但在我的應用程序中,我繼續實例化此對象的本地幫助器副本,並在需要計算時區偏移量時調用該副本。

1

下面的作品對我來說

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