GWT---Google Web Toolkit
2009/6/22
今天使用gwt做bbs的分类版面遇到了许多问题,从上午到现在都在调试错误,遇到了一个又一个从来没遇到过的异常
异常一:
2009-6-22 10:48:28 com.google.apphosting.utils.jetty.JettyLogger warn 警告: Nested in java.lang.ExceptionInInitializerError: java.security.AccessControlException: access denied (java.lang.RuntimePermission modifyThreadGroup) at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:122) at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkAccess(DevAppServerFactory.java:149) at java.lang.ThreadGroup.checkAccess(Unknown Source) at java.lang.Thread.init(Unknown Source) at java.lang.Thread. at java.util.TimerThread. at java.util.Timer. at java.util.Timer. at com.mysql.jdbc.Connection. at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:84) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2073) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1298) at com.perperyu.bbs.utils.HibernateSessionUtil. at com.perperyu.bbs.filters.SessionTranxFilter.doFilter(SessionTranxFilter.java:39) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084) at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405) at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:54) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139) at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:306) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139) at org.mortbay.jetty.Server.handle(Server.java:313) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506) at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:830) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396) at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442) |
这个异常。。太牛了,简直不是拿给我这种新手折腾的,想了几个小时也未果,然后按异常的关键词上google搜索,有让改java jre的配置文件的,grant几个permission.我尝试了修改,但是依然不行。于是上google的gwt论坛上寻求答案,
论坛中一共有四个帖子发布了这个问题的求助,我期盼着能从中找到答案。结果,有个人给了个解决方案,这个方案能成功解决这个异常,但这个异常究竟是什么意思,我还是搞不懂,涉及到安全控制这种底层的东西,我的java之路还很长啊。!解决办法很简单:不要使用goole的app engine就可以了。具体如下:
在eclipse3.4中,选中项目名,右键选择à属性àGoogleàApp Engineàuse Google App Engine(取消选中状态!)à确定,即可!
本来可以用这个方法迅速解决问题的,但是按网上提供的方法找不到这个选项:
选择Windowàpreferenceà GoogleàApp Engineàuse Google App Engine(取消选中状态!)………….但是我按这种方法怎么也找不到那个checkbox!用text 搜索也没找到,真晕!于是就以为那个方法不行!多次运行,尝试之后,我偶然的终于用右键的方式找到了。。。。果然可以不报这个异常了!
这个异常过后,又一个异常耗费了我大量时间:
异常二:
com.google.gwt.user.client.rpc.StatusCodeException: The call failed on the server; see server log for details at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:192) at com.google.gwt.http.client.Request.fireOnResponseReceivedImpl(Request.java:264) at com.google.gwt.http.client.Request.fireOnResponseReceivedAndCatch(Request.java:236) at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:227) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.ie.IDispatchImpl.callMethod(IDispatchImpl.java:126) at com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:155) at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294) at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194) at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117) at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method) at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966) at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:235) at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:558) at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405) at com.google.gwt.dev.HostedMode.main(HostedMode.java:232)
同因 com.google.gwt.user.client.rpc.IncompatibleRemoteServiceException: This application is out of date, please click the refresh button on your browser. at com.google.gwt.user.client.rpc.impl.RequestCallbackAdapter.onResponseReceived(RequestCallbackAdapter.java:204) at com.google.gwt.http.client.Request.fireOnResponseReceivedImpl(Request.java:264) at com.google.gwt.http.client.Request.fireOnResponseReceivedAndCatch(Request.java:236) at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:227) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103) at com.google.gwt.dev.shell.ie.IDispatchImpl.callMethod(IDispatchImpl.java:126) at com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:155) at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:294) at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:194) at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117) at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method) at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1925) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2966) at com.google.gwt.dev.SwtHostedModeBase.processEvents(SwtHostedModeBase.java:235) at com.google.gwt.dev.HostedModeBase.pumpEventLoop(HostedModeBase.java:558) at com.google.gwt.dev.HostedModeBase.run(HostedModeBase.java:405) at com.google.gwt.dev.HostedMode.main(HostedMode.java:232) |
发生这个异常,其实原因在我创建这个gwt项目的时候就注意到了,还想了好一会儿解决方案,但是未果。这时候我遇到了这个异常,由于被前一个异常搞的费神不少,所以一时半会儿也没想到。绕了很大一个弯儿,测试client端代码,测试server端代码,一步步把问题逼出来,但是症结还是找不到。后来才恍然大悟,原来就是我创建项目时想到的那个问题,这会儿正好在回调函数这里报异常了!
这个问题是这样的:由于client端的实体domain都必须实现IsSerializable接口,但是为了让项目更易于扩展,灵活更换组件,我的server端没有直接使用client端的domain,而是写了和client-domain一样的domain放在了server端,为了方便区别,client端的都以C开头。于是这里就涉及到一个问题:需要client-domain与server-domain之间进行数据拷贝。对于domain的简单属性当然很好操作,用
BeanUtils就可以方便的实现,但是对于复杂属性的就不那么好做了!比如我的
Category类中有一个Set集合,里面放的是:Forum domain类,相应的client端为CCategory,Set
由于对于这种有特殊要求的复杂属性拷贝我还没有想到一个好办法,就暂时把那些相关的代码都注释掉了,这时所有的domain都是只有简单属性了,运行程序后,不再出现上述异常,成功的通过异步方法经过逻辑层得到了持久层的数据!
但这并不是最终的方案,如果一个domain全是简单属性,那hibernate也不需要用进来了,我一定要想出一个好办法来!