如何将 Java 对象的 AMF (BlazeDS) 序列化调试为 Actionscript?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/979617/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 14:40:37  来源:igfitidea点击:

How can I debug AMF (BlazeDS) serialization of Java objects to Actionscript?

javaapache-flexblazedsamflivecycle

提问by Boden

I'm using BlazeDS to remote some Java objects that I'm consuming in a Flex application. I'm getting a type coercion error with one of my classes that I can't for the life of me figure out. I have other classes that are working fine using the same data types, and I've gone over my mapping a dozen times. I'm following all of the necessary conventions for getters and setters as far as I know...

我正在使用 BlazeDS 远程访问我在 Flex 应用程序中使用的一些 Java 对象。我在我的一个课程中遇到了类型强制错误,这是我一生都无法弄清楚的。我有其他类使用相同的数据类型可以正常工作,并且我已经检查了我的映射十几次。据我所知,我正在遵循 getter 和 setter 的所有必要约定......

Anyhow, my question is: how can I debug this problem?Running the Flex app in debug mode spits out some generic errors to the console that don't really help much (TypeError: Error #1034: Type Coercion failed: cannot convert Object@5d1d809 to valueObjects.SomeClass.).

无论如何,我的问题是:我该如何调试这个问题?在调试模式下运行 Flex 应用程序会向控制台输出一些没有多大帮助的通用错误(类型错误:错误 #1034:类型强制转换失败:无法将 Object@5d1d809 转换为 valueObjects.SomeClass。)。

I'm new to this whole AMF / Flex + Java thing, so any tips would be greatly appreciated.

我是整个 AMF / Flex + Java 的新手,所以任何提示都将不胜感激。

回答by Stu Thompson

These are two of the tools I use when working with BlazeDS, AMF, etc.:

这是我在使用 BlazeDS、AMF 等时使用的两个工具:

  • Use an HTTP proxy toolthat shows the calls between your client and server, like Charles
  • 使用 HTTP 代理工具显示客户端和服务器之间的调用,例如Charles

Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and SSL / HTTPS traffic between their machine and the Internet. This includes requests, responses and the HTTP headers (which contain the cookies and caching information).

Charles 是一个 HTTP 代理/HTTP 监视器/反向代理,使开发人员能够查看他们的机器和 Internet 之间的所有 HTTP 和 SSL/HTTPS 流量。这包括请求、响应和 HTTP 标头(其中包含 cookie 和缓存信息)。

  • Turn on the logging for BlazeDS. Within WEB-INF/conf/services-conf.xml, lower the debugging level to 'debug' like in the below snippit. The output, which is fairly detailed, will appear in {tomcat-home}/logs/localhost.yyyy-mm-dd.log

    <target class="flex.messaging.log.ConsoleTarget" level="debug">

  • 打开 BlazeDS 的日志记录。在 内WEB-INF/conf/services-conf.xml,将调试级别降低到 ' debug',如下面的代码片段所示。输出相当详细,将出现在{tomcat-home}/logs/localhost.yyyy-mm-dd.log

    < target class="flex.messaging.log.ConsoleTarget" level="debug">

回答by FidelGonzo

The easiest way to check on the communication between service-clients AMF messages is to use FireFox, install FireBugextension and add the AMF Explorer. You can see the structured requests and responses.

检查服务客户端 AMF 消息之间的通信的最简单方法是使用 FireFox,安装FireBug扩展并添加AMF Explorer。您可以看到结构化的请求和响应。

回答by Rivet

The java class that is being deserialized in the client side must have a reference to an object of the corresponding AS3 class in the application (mxml or as3). Otherwise, the as3 class will not be loaded in the swf file and will result in deserializing the java class to a generic as3 object.

在客户端反序列化的 java 类必须引用应用程序中相应 AS3 类的对象(mxml 或 as3)。否则,将不会在 swf 文件中加载 as3 类,并导致将 java 类反序列化为通用 as3 对象。

updatedThis will happen despite having the mapping, getters and setters. Just declare an object of the corresponding AS3 class in script section of your mxml.

更新尽管有映射、getter 和 setter,这仍会发生。只需在 mxml 的脚本部分声明相应 AS3 类的对象。

回答by Philip

I use Flex Builder and have it set up for both client and server side debugging. It was a pain to set up at first, but you can Google for step-by-step tutorials. I find it quite valuable for debugging RPCs. Last I checked, Flex Builder has a free trial and is free to students and the unemployed.

我使用 Flex Builder 并将其设置为客户端和服务器端调试。一开始设置很痛苦,但你可以谷歌搜索分步教程。我发现它对于调试 RPC 非常有价值。最后我查了一下,Flex Builder 有一个免费试用版,对学生和失业者免费。

回答by Darren Bishop

It's also worth noting that instrumentation in Java can also cause a loss of information and/or interfere with the serialization process and stream.

还值得注意的是,Java 中的检测也会导致信息丢失和/或干扰序列化过程和流。

I've experienced this TypeError: Error #1034: Type Coercion failedon a project (Flex<->BlazeDS+Spring) where our data-access layer was implemented with iBatis and had lazy-loading switched on - we turned it off as that measure represented the lesser loss of efficiency (theoretically, at least), as compared to other workarounds we had in place.

TypeError: Error #1034: Type Coercion failed在一个项目 (Flex<->BlazeDS+Spring) 中遇到过这种情况,其中我们的数据访问层是用 iBatis 实现的并打开了延迟加载 - 我们将其关闭,因为该措施代表了较小的效率损失(理论上,至少),与我们现有的其他解决方法相比。