일단 먼저 lcds를 설치 해야 한다.

설치가 완료되면 해당 폴더(기본적으로 c:\lcds에 위치함)안에 flex.war파일이 있다.

이 파일을 복사해서 톰캣홈/webapps폴더(기본적으로 C:\Program Files\Apache Software
 
Foundation\Tomcat 5.5\webapps에 위치함) 안에 넣은 후에 톰캣을 재가동 시키면

flex폴더가 새로 생기게 된다.

flex폴더를 생성하게 되면 그 하위 폴더로 WEB-INF\flex가 있는데 이 안에 보면

services-config.xml 파일과 remoting-config.xml 파일이 있는데 이 두개의 파일을

설정함으로써 RemoteObject를 사용할 수 있게 된다.


먼저 services-config.xml 파일을 수정해야 한다.

channels 안에 아래와 같은 소스를 입력한다.

톰캣을 사용하기 때문에 8080을 써주고 id값은 임의로 줘도 되므로 test-amf라고 하였다.

  1. <channel-definition id="test-amf" class="mx.messaging.channels.AMFChannel">  
  2.             <endpoint url=  
  3. "https://localhost:8080/flex/messagebroker/amf"   
  4. class="flex.messaging.endpoints.AMFEndpoint"/>  
  5.             <properties>  
  6.                 <polling-enabled>false</polling-enabled>  
  7.             </properties>  
  8.         </channel-definition>  


이렇게 해준 후, my-amf 가 있는데 두개의 amf를 한꺼번에 사용할 수 없으므로 아래와 같이

my-amf에 있는 url의 amf뒤에 2라고 써준다.

https://localhost:8080/flex/messagebroker/amf2


이번엔 remoting-config.xml을 수정할 차례다.

remoting-config.xml에서는 사용할 java클래스를 등록하고 사용할 수 있도록 한다.

아래 소스에서 services-config.xml 파일에서 만들어준 test-amf를 등록해 주었다.

그리고 destination안의 id는 플렉스 상에서 지정하게 될 id값으로 사용된다.

source안에는 사용할 클래스 이름을 써주게 되고 channel ref는 보면 알겠지만

사용할 channel이름을 입력해 주면 된다.

  1. <default-channels>  
  2.         <channel ref="test-amf"/>  
  3.     </default-channels>  
  4.   
  5.     <destination id="RO">  
  6.         <properties>  
  7.             <source>RemoteObject</source>  
  8.         </properties>  
  9.         <channels>  
  10.             <channel ref="test-amf" />  
  11.         </channels>  
  12.     </destination>  
  13.   
  14.     <destination id="STUDENT">  
  15.         <properties>  
  16.             <source>StudentManager</source>  
  17.         </properties>  
  18.         <channels>  
  19.             <channel ref="test-amf" />  
  20.         </channels>  
  21.     </destination>  


이와 같이 자바 클래스를 사용하고자 할때는 remoting-config.xml 파일에 등록하여

사용하면 되고 여기까지가 RemoteObject를 사용하기 위한 설정이였다.

이제부턴 실제로 프로그래밍을 통해 RemoteObject를 사용하면 된다.

 java클래스파일을 만드는데 java파일을 컴파일한 후 클래스파일은 톰캣홈

\webapps\flex\WEB-INF\classes 안에 위치하게 된다.

테스트용으로 아래와 같이 java파일을 만들었다.

  1. public class RemoteObject   
  2. {  
  3.     public String my_func()  
  4.     {  
  5.         return "Java 함수가 호출된다.";  
  6.     }  
  7. }  

RemoteObject라는 클래스 이름은 remotting-config.xml 파일에  

<source>RemoteObject</source>와 같이 등록되어 있어야 사용이 가능하며 위에

이미 설정되어있다.
 
그리고 마지막으로 Flex 상에서는 아래와 같이 해당 클래스의 메소드를 호출 할 수 있다는

것을 알 수 있다.

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"   
  3. layout="absolute">  
  4. <mx:Script>  
  5.     <![CDATA[  
  6.         import mx.rpc.events.FaultEvent;  
  7.         import mx.rpc.events.ResultEvent;  
  8.           
  9.         private function resultHandler(event:ResultEvent):void  
  10.         {  
  11.             txtResult.text = event.result.toString();  
  12.         }  
  13.           
  14.         private function faultHandler(event:FaultEvent):void  
  15.         {  
  16.             txtResult.text = event.toString();  
  17.         }  
  18.     ]]>  
  19. </mx:Script>  
  20. <mx:RemoteObject id="test" destination="RO" showBusyCursor="true"  
  21.     result="resultHandler(event)" fault="faultHandler(event)" >  
  22. </mx:RemoteObject>  
  23. <mx:Button x="19" y="10" label="RemoteObject호출" click="test.my_func()" />  
  24. <mx:TextArea id="txtResult" x="10" y="40" width="229" height="218" />  
  25. </mx:Application>  

Posted by 윤연식
,