yl197837 发表于 2017-2-7 11:08:16

Tomcat下远程调式分析学习Flex服务器Blazeds (二)

        在网页游戏中,经常使用AmfPhp,Zend_AMF或Blazeds,LiveCycle之类作为webserver服务器。如果服务器选择php,则amfphp当然是首选。如果服务器是j2ee,通常选择Blazeds或LiveCycle。由于Blazeds开源性,我更倾向于Blazeds。它是居于java servlet基础上开发的flex-java通讯框架,支持http服务,amf服务以及发布订阅式服务。工欲善其事,必先利其器。想深入了解blazeds框架,我们得搭建一个运行环境来一步一步调式。不过大家先要去adob网站下载blazeds-bin-4.0.1.17657.zip和blazeds-src-4.0.1.17657.zip两个安装包
      1.解压blazeds-bin-4.0.1.17657.zip到D:\blazeds。,它里面自带一个tomcat服务器。
         将blazeds-src-4.0.1.17657解压到d:\fff目录
      2.在D:\blazeds\tomcat\webapps目录下web应用目录myblazeds,做过j2ee的童鞋应该很熟悉.当然你也可以使用配置方式指定应用目录。并拷贝原有blazeds目录下原有所有文件夹以及文件到myblazeds
      


 
 
  

   
      3.启动D:\blazeds\tomcat的tomcat服务器测试服务器是否Ok:
  

 

 
       4.打开flashbuilder4建立一个flex工程,应用服务器类型选择j2ee以及Blazeds
  

 
     5.设置flex使用j2ee服务器路径以及上下文为当前tomcat对应路径:
      根目录:D:\blazeds\tomcat\webapps\myblazeds
      根URL(就是tomcat下 webapp访问路径):http://127.0.0.1:8400/myblazeds
      上下文根目录:/myblazeds
     注意flex输出路径一定为D:\blazeds\tomcat\webapps\myblazeds
      如果不出现错误这一步就OK了

   
    6.在blazeds.mxml文件中编写如下代码,这个代码我是从blazeds使用指南中copy过来的:
     这个很简单,就是请求java服务器端的远程对象echo函数:
   <?xml version="1.0"?>
<!-- intro\intro_remoting.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
    width="100%" height="100%">
 <mx:Script>
  <![CDATA[
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
   // Send the message in response to a Button click.
   private function echo():void {
    var text:String = ti.text;
    remoteObject.echo(text);
   }
   // Handle the recevied message.
   private function resultHandler(event:ResultEvent):void {
    ta.text += "Server responded: "+ event.result + "\n";
   }
   // Handle a message fault.
   private function faultHandler(event:FaultEvent):void {
    ta.text += "Received fault: " + event.fault + "\n";
   }
  ]]>
 </mx:Script>
 <mx:RemoteObject id="remoteObject"
      destination="echoServiceDestination"
      result="resultHandler(event);"
      fault="faultHandler(event);"/>
 <mx:Label text="Enter a text for the server to echo"/>
 <mx:TextInput id="ti" text="Hello World!"/>
 <mx:Button label="Send" click="echo();"/>
 <mx:TextArea id="ta" width="100%" height="100%"/>
</mx:Application>
  
  7.使用myeclipse建立一个web工程,工程文件输出路径为我们在上面建立myblazeds下的web-inf/class:  myblazeds/WEB-INF/classes
  

 
  
   8.copy d:\fff目录下的lib中所有文件夹以及文件到D:\blazeds\tomcat\webapps\myblazeds\WEB-INF\lib
       copy d:\fff目录下的modules目录下的所有lib目录下的所有jar包到              D:\blazeds\tomcat\webapps\myblazeds\WEB-INF\lib
     copycopy d:\fff目录下的modules目录下的src目录下所有目录到我们工程下的src目录下。现在工程就变成所辖
  所示了。

 
  9.在java工程建立java类EchoService:
  package remoting;
  public class EchoService {
  public String echo(String text) {
     return "Server says: I received '" + text + "' from you";
  }
}
  

 
  在java工程下的WEB-INF/flex/remoting-config.xml文件添加如下:
  
 <destination id="echoServiceDestination" channels="my-amf">
  <properties>
   <source>remoting.EchoService</source>
  </properties>
 </destination>
  

 
   10.在D:\blazeds\tomcat\bin目录下建立一个用于远程调式tomcat批处理文件mydebug.bat:
      cd %CATALINE_HOME%/bin
     set JPDA_ADDRESS=8090
     set JPDA_TRANSPORT=dt_socket
  
   set CATALINA_OPTS=-server -Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8090
  startup
   
    11.启动tomcat并启动fle工程:
  

 
   12.在myeclipse中建立远程连接tomcat:
    host:localhost
    port:8090
  

 
   13。在MessageBrokerServlet.java类中的service函数打断点,点击Flex工程页面中send按钮开始调式:
  

 
  

 
  好了,到此我们的调式环境已经准备好了。下一编我就开始实际分析blazeds架构原理。
页: [1]
查看完整版本: Tomcat下远程调式分析学习Flex服务器Blazeds (二)