关于messagebroker/amf的相关问题

来源:互联网 发布:数据的重要性的名言 编辑:程序博客网 时间:2024/04/30 07:01

 这个问题,我也遇到过了,不过,最后都解决了。感觉太普遍了,所以想写篇文章,分享一下我的解决办法。根据我的经历,目前发现此问题出现的原因有如下三点:
      1.相关路径设置错误。比如,flex build path,flex server等。首先要检查这些。我有一次就是flex build path设置错误。比如,编译成swf文件放在a文件夹,结果去b文件夹访问。不要笑。后来,查明原因是因为我直接把别人的项目拿来运行。但相关设置都没更改。
      2.WEB-INF\flex\services-config.xml这个文件缺少相关配置。
      3.在tomcat 5.5\webapps\Root这个目录下缺少crossdomain.xml文件。它是允许跨域访问的。没有它,肯定会遇到flex中沙箱安全问题。
针对以上提到三个可能原因,可以从以下三方面予以解决。
      1.检查相关路径设置。
      2.在services-config.xml中找到节点channel-definition id="my-amf" 部分。endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" 中的url就需要根据你的工程作相关设置。比如我有一个名为eoso的flex+java工程。我的设置如下:
endpoint url="http://localhost:8080/eoso/messagebroker/amf"
     还有此文件最下面有如下内容:
 <watch-file>{context.root}/WEB-INF/flex/services-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/proxy-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/remoting-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/messaging-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/data-management-config.xml</watch-file>
            <touch-file>{context.root}/WEB-INF/web.xml</touch-file>
也要作类似上面的设置。
       3.在tomcat 5.5\webapps\Root(注我用的是tomcat5.5,)这个目录下缺少crossdomain.xml文件(名字不要改)。其中完整内容如下:
<?xml version="1.0"?>    
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">    
<cross-domain-policy> <site-control permitted-cross-domain-policies="all" />      
    <allow-access-from domain="*" />      
    <allow-http-request-headers-from domain="*" headers="*"/>   
</cross-domain-policy>

     

     以下是个人观点:

     在第二种方法中,修改services-config.xml中的相应配置并不能起作用,而是直接在RemoteObject中加属性endpoint指明相应的URL,如下:

     <mx:RemoteObject destination="firstJavaFlex" id="remoteHello" fault="error(event)" endpoint="/JavaFlex/messagebroker/amf">  
  </mx:RemoteObject> 

     其中JavaFlex是工程名。