작업환경 : 이클립스 J2EE  & FLEX 환경 (설치 참조 : http://wonsama.tistory.com/180 )
테스트 목적 : Remote Object를 확인하기 위해 테스트를 진행.
작업진행 : Eclipse에서 환경설정 및 클래스 생성 이후 Flex에서 해당 서비스 호출 소스 작성을 실시한다.

[Eclipse]
// WEB-INF/flex/remoting-config.xml :  리모트 오브젝트 관련 환경을 설정한다.

<?xml version="1.0" encoding="UTF-8"?>
<service id="remoting-service" class="flex.messaging.services.RemotingService">

    <adapters>
        <adapter-definition id="java-object"
            class="flex.messaging.services.remoting.adapters.JavaAdapter"
            default="true" />
    </adapters>

    <default-channels>
        <channel ref="my-amf" />
    </default-channels>

    <destination id="empRO">
        <properties>
            <source>book.EmployeeManager</source>           
        </properties>
    </destination>

</service>

RO를 사용하기 위하여 추가적으로 설정한 내용임.
1: destination id - FLEX에서 호출하는 RemoteObject의 destination 를 지정한다.
2: source - 참조하는 클래스 소스를 설정한다.

[Eclipse]
// src/book/Employee.java

package book;

import java.io.Serializable;

public class Employee implements Serializable {
    /**
     *
     */
    private static final long serialVersionUID = 1L;
    public String name;
    public String phone;
    public String email;
    public Employee(){

    }

    public Employee(String name, String phone, String email){
        this.name = name;
        this.phone = phone;
        this.email = email;
    }
}

[Eclipse]
// src/book/EmployeeManager.java

package book;

import org.apache.log4j.Logger;
import java.util.ArrayList;

public class EmployeeManager {
    /**
     * Logger for this class
     */
    private static final Logger logger = Logger.getLogger(EmployeeManager.class);
   
    public EmployeeManager(){

    }

   
    public Object[] getList(String deptId){

        if (logger.isDebugEnabled()) {
            logger.debug("getList(String) - start"); //$NON-NLS-1$
        }

        ArrayList<Employee> list = new ArrayList<Employee>();
        if(deptId.equals("ENG")){
            list.add(new Employee("Christina Coenreaets", "555-219-270","ccoenraets@fictitious.com" ));
            list.add(new Employee("Louis Freligh", "555-219-2270", "lfrelight@fictitious.com" ));
        }else if(deptId.equals("PM")){
            list.add(new Employee("Ronnie Hodgman", "555-219-2270", "ccoenraets@fictitious.com" ));
            list.add(new Employee("Joanne Wall", "555-219-2270", "lfrelight@fictitious.com" ));  
        }else if(deptId.equals("MKT")){
            list.add(new Employee("Maurice Smith", "555-219-2270", "ccoenraets@fictitious.com" ));
            list.add(new Employee("Mary Jones", "555-219-2270", "lfrelight@fictitious.com" ));  
        }
        Object[] returnObjectArray = list.toArray();

        if (logger.isDebugEnabled()) {
            logger.debug("getList(String) - end"); //$NON-NLS-1$
        }else{
            System.out.println("err");
        }

        return returnObjectArray;
    }
}

[FLEX]
// src/blaze.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 <mx:Script>
  <![CDATA[
   import mx.controls.Alert;
   import mx.rpc.events.FaultEvent;
   import mx.rpc.events.ResultEvent;
  
   private function resultHandler(event:ResultEvent):void{
    dg.dataProvider = event.result;
   }
  
   private function faultHandler(event:FaultEvent):void{
    mx.controls.Alert.show(event.fault.message);
   }
  
  ]]>
 </mx:Script>
 
 <mx:RemoteObject id="emp" destination="empRO" showBusyCursor="true"  result="resultHandler(event)" fault="faultHandler(event)"/>


 <mx:Panel width="95%" height="95%" layout="absolute"
     title="RemoteObject UTF8" >
  <mx:DataGrid id="dg" width="100%" height="100%" />
  <mx:ControlBar horizontalAlign="center">
   <mx:HBox>
    <mx:Label text="Select a department :" />
    <mx:ComboBox id="dept" width="150">
     <mx:dataProvider>
      <mx:Array>
       <mx:Object label="Engineering" data="ENG" />
       <mx:Object label="Product Management" data="PM" />
       <mx:Object label="Marketing" data="MKT" />
      </mx:Array>
     </mx:dataProvider>
    </mx:ComboBox>
    <mx:Button label="Get Employee List" click="emp.getList(dept.selectedItem.data)" />
   </mx:HBox>
  </mx:ControlBar>
 
 </mx:Panel>
 
</mx:Application>


<mx:RemoteObject id="emp" destination="empRO" showBusyCursor="true"  result="resultHandler(event)" fault="faultHandler(event)"/>
=> RO를 설정한 부분
=> destination : Eclipse에 설정된 클래스를 호출하기 위한 Destination

<mx:Button label="Get Employee List" click="emp.getList(dept.selectedItem.data)" />
=> RO를 호출하는 부분
=> emp.getList :  getList 메소드를 호출한다. 처리 결과는 위에서 설정한 리스너를 통해 들어온다.

[처리 결과]


결론 및 요약 :

- [Eclipse] remoting-config.xml 설정 => 설정에 맞춰 클래스 생성 => [Flex] RO호출
- RO를 통해 처리를 JAVA로 위임한 이후 결과를 받아 처리 할 수 있음. 매우 유익한듯.





'기타 > Old' 카테고리의 다른 글

MS '윈도7 RC 버전' 공개됐다  (0) 2009.05.01
구글·네이버, 닮은꼴 서비스 경쟁 '후끈'  (0) 2009.04.30
설치하기  (0) 2009.04.29
이벤트 링크  (0) 2009.04.29
삼성電, 'AM-OLED 안드로이드폰' 6월 출시  (1) 2009.04.28

+ Recent posts