终于在Google App Engine/Java(GAE/J)下成功部署运行Flex+BlazeDS
终于在Google App Engine/Java(GAE/J)上成功部署运行Flex+BlazeDShttp://www.iteye.com/topic/428326?话说
终于在Google App Engine/Java(GAE/J)上成功部署运行Flex+BlazeDS
http://www.iteye.com/topic/428326
?
话说近日Google App Engine终于开始了对Java的支持,让在下这个懒于学习Python的怂人,也有了一试GAE/J的可能。恰逢刚刚开始学习和接触Flex,因此有了将Flex+BlazeDS部署到GAE上的冲动,百度、谷歌了一下发现,尽管网上Flex+BlazeDS+Tomcat的配置方法已经泛滥成灾,但是在GAE/J上部署Flex特别是BlazeDS还没有动静。?
没办法,只好自己动手,丰衣足食了。不罗嗦了,首先配置好GAE/J的开发环境,在下用的是标准的eclipse ganymede-SR2和GAE的eclipse plugin,接下来是下载安装Abobe官方提供的Flex Builder 3 Plug-in For eclipse,同时下载BlazeDS-bin待用。?
首先建立Google的Web Application Project,然后手工往项目中添加Flex与BlazeDS需要的元素:?
(1)将BlazeDS需要的jar文件(blazeds.war\WEB-INF\lib,共12个jar包)拷到工程的lib目录下,并添加到项目的Java Build Path下。?
(2)然后要加入Flex BlazeDS需要的配置文件。在WEB-INF下新建一个名为flex的文件夹,将blazeds.war\WEB-INF\flex下的4个xml文件拷到该文件夹下。?
(3)修改web.xml文件,加入Flex的配置。?
Java代码??
- <context-param>??
- ????<param-name>flex.class.path</param-name>??
- ????<param-value>/WEB-INF/flex/hotfixes,/WEB-INF/flex/jars</param-value>??
- </context-param>??
- ??
- <!--?Http?Flex?Session?attribute?and?binding?listener?support?-->??
- <listener>??
- ????<listener-class>flex.messaging.HttpFlexSession</listener-class>??
- </listener>??
- ??
- <!--?MessageBroker?Servlet?-->??
- <servlet>??
- ????<servlet-name>MessageBrokerServlet</servlet-name>??
- ????<servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>??
- ????<init-param>??
- ????????<param-name>services.configuration.file</param-name>??
- ????????<param-value>/WEB-INF/flex/services-config.xml</param-value>??
- ????</init-param>??
- ????<init-param>??
- ????????<param-name>flex.write.path</param-name>??
- ????????<param-value>/WEB-INF/flex</param-value>??
- ????</init-param>??
- ????<load-on-startup>1</load-on-startup>??
- </servlet>??
- ??
- <servlet-mapping>??
- ????<servlet-name>MessageBrokerServlet</servlet-name>??
- ????<url-pattern>/messagebroker/*</url-pattern>??
- </servlet-mapping>??
作为一个几乎完全不懂Flex的怂人,在下在网上搜到了一个调用amf的简单例子,就马上Copy过来试试:?
引用
1)新建一个java类:Hello.java?
Java代码??
- package?com;??
- public?class?Hello?{??
- ????public?String?hello(String?name){??
- ????????System.out.println("flex调用我了,真好~~~~");??
- ????????return?"hello?"+name;??
- ????}??
- }??
2)为flex配置这个要调用的对象,修改WEB-INF/flex下remoting-config.xml?
加入:?
Xml代码??
- <destination?id="hello">?<properties>?<source>?com.Hello?</source>?</properties>?</destination>??
3)编写一个Flex程序?
Xml代码??
- <?xml?version="1.0"?encoding="utf-8"?>??
- <mx:Application?xmlns:mx="http://www.adobe.com/2006/mxml"?layout="absolute">??
- ????<mx:Script>??
- ????????<![CDATA[?
- ????????????import?mx.rpc.events.ResultEvent;?
- ????????????function?gg(evnet:ResultEvent):void{?
- ????????????var?ff:String?=?evnet.result?as?String;?
- ????????????ggg.text?=?ff;?
- ????????????}?
- ????????????function?remotingSayHello():void{?
- ????????????var?sname:String?=?nameInput.text;?
- ????????????h.hello(sname);?
- ????????????}?
- ????????]]>??
- ????</mx:Script>??
- ????<mx:RemoteObject?destination="hello"?id="h"?result="gg(event)"?endpoint="/messagebroker/amf"?>??
- ????</mx:RemoteObject>??
- ????<mx:TextArea?id="ggg"?x="109"?y="122"/>??
- ????<mx:Button?label="say?hello"?click="remotingSayHello();"?x="144"?y="193"/>??
- ????<mx:TextInput?id="nameInput"?x="111"?y="63"/>??
- ????<mx:Label?text="name"?x="47"?y="75"/>??
- </mx:Application>??
满心欢喜,马上在本地调试启动Google Web Application,出现以下错误:?
Java代码??
- "Channel.Connect.Failed?error?NetConnection.Call.Failed:??
- HTTP:?Status?500:?url:?'http://localhost:8080/messagebroker/amf'"??
控制台上打出log:?
Java代码??
- WARNING:?/messagebroker/amf??
- java.lang.RuntimeException:?Session?support?is?not?enabled?in?appengine-web.xml.To?enable?sessions,?put?true?in?that?file.?Without?it,?getSession()?is?allowed,?but?manipulation?of?sessionattributes?is?not.??
- at?com.google.apphosting.utils.jetty.StubSessionManager$StubSession.throwException(StubSessionManager.java:67)??
好吧,这是第一个挫败,修改WEB-INF/appengine-web.xml,在<appengine-web-app>下加入这句:?
Xml代码??
- <sessions-enabled>true</sessions-enabled>??
重新启动调试,一切正常,amf调用成功。然后的任务就是将项目部署到Google App Engine上验证我们的应用了。由于众所周知的原因,GAE的JVM对不少Java类的访问都是有限制的,本地运行的成功并不能完全说明问题,还需要实地验证。?
果不其然,马上就遇到了致命的错误:?
Java代码??
- Warning:****?MessageBrokerServlet?failed?to?initialize?due?to?runtime?exception:???Error:?java.lang.NoClassDefFoundError:?Could?not?initialize?class?com.google.apphosting.runtime.security.shared.stub.java.lang.management.ManagementFactory??
- ????at?flex.management.PlatformMBeanServerLocator.getMBeanServer(PlatformMBeanServerLocator.java:38)??
- ????at?flex.management.BaseControl.register(BaseControl.java:186)??
- ????at?flex.management.runtime.AdminConsoleDisplayRegistrar.<init>(AdminConsoleDisplayRegistrar.java:40)??
- ????at?flex.management.runtime.messaging.MessageBrokerControl.<init>(MessageBrokerControl.java:85)??
- ????at?flex.messaging.MessageBroker.<init>(MessageBroker.java:269)??
- ????at?flex.messaging.config.MessagingConfiguration.createBroker(MessagingConfiguration.java:105)??
- ????at?flex.messaging.MessageBrokerServlet.init(MessageBrokerServlet.java:112)??
- ????at?org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:433)??
- ????at?org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:256)??
- ????at?org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)??
- ????at?org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:612)??
- ????at?org.mortbay.jetty.servlet.Context.startContext(Context.java:139)??
- ????at?org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1218)??
- ????at?org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:500)??
- ????at?org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)??
- ????at?org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)??
- ????at?com.google.apphosting.runtime.jetty.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:190)??
- ????at?com.google.apphosting.runtime.jetty.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:167)??
- ????at?com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:127)??
- ????at?com.google.apphosting.runtime.JavaRuntime.handleRequest(JavaRuntime.java:235)??
- ????at?com.google.apphosting.base.RuntimePb$EvaluationRuntime$6.handleBlockingRequest(RuntimePb.java:4823)??
- ????at?com.google.apphosting.base.RuntimePb$EvaluationRuntime$6.handleBlockingRequest(RuntimePb.java:4821)??
- ????at?com.google.net.rpc.impl.BlockingApplicationHandler.handleRequest(BlockingApplicationHandler.java:24)??
- ????at?com.google.net.rpc.impl.RpcUtil.runRpcInApplication(RpcUtil.java:359)??
- ????at?com.google.net.rpc.impl.Server$2.run(Server.java:820)??
- ????at?com.google.tracing.LocalTraceSpanRunnable.run(LocalTraceSpanRunnable.java:56)??
- ????at?com.google.tracing.LocalTraceSpanBuilder.internalContinueSpan(LocalTraceSpanBuilder.java:516)??
- ????at?com.google.net.rpc.impl.Server.startRpc(Server.java:775)??
- ????at?com.google.net.rpc.impl.Server.processRequest(Server.java:348)??
- font-size: 1em; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 38px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 10px; border-left-width: 1px; border-left-style: solid; border-left-color: #d1d7dc; background-