开发者

TypeError: Error #1034: Type Coercion failed: cannot convert Object@1456c7b9 to mx.messaging.messages.IMessage

Im trying to connect a Flash client to BlazeDS. There 开发者_开发百科has been some success with this from others using the vanilla BlazeDS setup. However I'm using the new Spring BlazeDS Integration from springsource and running aground. The flash client actually seems to be working in that I can see the correct data in the body of the returned object, but for some reason unknown it fails casting as an IMessage. It fails in PollingChannel.as on this line with the subject line error

            var messageList:Array = msg.body as Array;
            for each (var message:IMessage in messageList)  <--

On application load I register a whole bunch of classes like so

registerClassAlias( "flex.messaging.messages.RemotingMessage", RemotingMessage ); registerClassAlias("mx.messaging.messages.IMessage", IMessage); etc..

my code is basically

        var channelSet:mx.messaging.ChannelSet = new mx.messaging.ChannelSet();
        var channel:mx.messaging.channels.AMFChannel = new AMFChannel("my-amf", "http://localhost:8400/SpringA/messagebroker/amf");
        channelSet.addChannel(channel);

        var consumer:mx.messaging.Consumer = new Consumer();
        consumer.channelSet = channelSet;
        consumer.destination = "simple-feed";
        consumer.subscribe();
        consumer.addEventListener(MessageEvent.MESSAGE, test);


    private function test(event:IMessage)
    {
        trace("msg..");
        // breakpoint never makes it here
    }

I have a flex client which works 100% with same destination/channel.


The error in the title means that you, for some reason, got an object that is not implementing or extending the IMessage interface, therefore the loop can not cast it in this part:

for each (var message:IMessage in messageList){

Either you should somehow make sure that you don't add anything that is not extending or implementing IMessage, or check if the variable IS actually ext./imp. it. Also - if you want to do that, you will have to change the for each like this:

for each (var obj in messageList){
    if (obj is IMessage){
        var message:IMessage = obj as IMessage;
        // DO STUFF HERE
    }
}


Add this Object mapping:

registerClassAlias("flex.messaging.io.ObjectProxy", ObjectProxy); 


If on your Java VO objects you have overridden the hashcode() method, this situation could happen.

Remove the hashcode() override (if you are able to).

See my blog for the backstory on how I discovered this. http://squaredi.blogspot.com/2013/12/remoting-landmine-without-stack-trace.html


I had the same error when trying to send an actionscript object to the backend. My problem was that my c# equivalent object was missing an public parameterless constructor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜