关于ActionScript项目中使用RemoteObject遇到的问题

关于在ActionScript项目中,使用RemoteObject的时候遇到的如下Exception

[WARN ] [2013-01-04 22:41:26] org.springframework.flex.core.DefaultExceptionLogger  The following exception occurred during request processing by the BlazeDS MessageBroker and will be serialized back to the client:
java.lang.NullPointerException
at java.util.concurrent.ConcurrentHashMap.get(Unknown Source)
at flex.messaging.MessageBroker.routeMessageToService(MessageBroker.java:1373)
at flex.messaging.endpoints.AbstractEndpoint.serviceMessage(AbstractEndpoint.java:1005)
at flex.messaging.endpoints.AbstractEndpoint$$FastClassByCGLIB$$1a3ef066.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:689)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.flex.core.MessageInterceptionAdvice.invoke(MessageInterceptionAdvice.java:66)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.invoke(ThrowsAdviceInterceptor.java:124)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.Cglib2AopProxy$FixedChainStaticTargetInterceptor.intercept(Cglib2AopProxy.java:573)
at flex.messaging.endpoints.AMFEndpoint$$EnhancerByCGLIB$$8f3a8faa.serviceMessage(<generated>)
at flex.messaging.endpoints.amf.MessageBrokerFilter.invoke(MessageBrokerFilter.java:103)
at flex.messaging.endpoints.amf.LegacyFilter.invoke(LegacyFilter.java:158)
at flex.messaging.endpoints.amf.SessionFilter.invoke(SessionFilter.java:44)
at flex.messaging.endpoints.amf.BatchProcessFilter.invoke(BatchProcessFilter.java:67)
at flex.messaging.endpoints.amf.SerializationFilter.invoke(SerializationFilter.java:166)
at flex.messaging.endpoints.BaseHTTPEndpoint.service(BaseHTTPEndpoint.java:291)
at flex.messaging.endpoints.AMFEndpoint$$EnhancerByCGLIB$$8f3a8faa.service(<generated>)
at org.springframework.flex.servlet.MessageBrokerHandlerAdapter.handle(MessageBrokerHandlerAdapter.java:109)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)


在ActionScript端,Error
TypeError: Error #1034: Type Coercion failed: cannot convert Object@5425371 to mx.messaging.messages.ErrorMessage.
再无其他任何错误信息


解决办法:在要执行RemoteObject的远程方法之前,注册下在BlazeDS通信时需要用到的通信类,即,添加如下语句
RpcClassAliasInitializer.registerClassAliases();

-------------------------------------
分析

看后台的错误日志,可以分析出,是对于BlazeDS内部的报错,而又是空指针错误,说明是
有些对象没有成功被实例化
再通过前端的错误信息分析,是转换对象的类型失败。

而对于Flex项目来说,就可以直接使用RemoteObject,无论是标签的方式还是AS代码的方式。

那么写法都一样的情况下,其实Flex工程是多了一个initilization的步骤,也就是说,对于ActionScript中的相应通信类,没有成功的转换成BlazeDS中的类。

加的这条语句在以前博客里也写过类似的,就是手动注册需要AS和Java相对应的类

registerClassAliases的源码里注册了如下
// Flex classes
        registerClassAlias("flex.messaging.io.ArrayCollection", ArrayCollection);
        registerClassAlias("flex.messaging.io.ArrayList", ArrayList);
        registerClassAlias("flex.messaging.io.ObjectProxy", ObjectProxy);
       
        // rpc classes
        registerClassAlias("flex.messaging.messages.AcknowledgeMessage", AcknowledgeMessage);
        registerClassAlias("DSK", AcknowledgeMessageExt);
        registerClassAlias("flex.messaging.messages.AsyncMessage", AsyncMessage);
        registerClassAlias("DSA", AsyncMessageExt);
        registerClassAlias("flex.messaging.messages.CommandMessage", CommandMessage);
        registerClassAlias("DSC", CommandMessageExt);
        registerClassAlias("flex.messaging.config.ConfigMap", ConfigMap);
        registerClassAlias("flex.messaging.messages.ErrorMessage", ErrorMessage);
        registerClassAlias("flex.messaging.messages.HTTPMessage", HTTPRequestMessage);
        registerClassAlias("flex.messaging.messages.MessagePerformanceInfo", MessagePerformanceInfo);
        registerClassAlias("flex.messaging.messages.RemotingMessage", RemotingMessage);
        registerClassAlias("flex.messaging.messages.SOAPMessage", SOAPMessage);

你可能感兴趣的:(actionscript,RemoteObject,blazeds)