[Flex + Spring] Annotation 기반 Flex BlazeDS 서비스 개발하기

Flex 개발을 하다보면 서버와의 통신을 통해 다양한 방법을 사용할수 있다는 장점을 쉽게 알 수 있습니다.

하지만 안타까운게 Remote Object를 사용하기 위해서는 얼마인지 산출하기도 힘든 비싼 FDS (LCDS)를 구매해야 한다는 장벽이 있었죠.

이 장벽에 막혀 안정성이 확보되지 못한 일부 오픈 소스제품군을 사용하거나 다른 방식의 통신을 사용하여야 했습니다.

하지만 LCDS의 빠른 속도를 보장받을수는 없었죠. 현재 LCDS의 Remote Object 통신 프로토콜은 AMF3 (Action Message Format 3)까지 나왔습니다.

하지만 Adobe에서 BlazeDS라는 이름의 LCDS 무료버젼을 내놓았습니다. 또한 오픈소스로 개발 진행중입니다.

또한 Jeff Vroom 이라는 멋진 분이 Spring ↔ BlazeDS 간 통신할 수 있는 Factory를 개발하였습니다.

관련 정보는 다음을 참고하세요

[ 어도비 기술문서 ]
[ Sewon님 블로그 ]
[ 머드초보님 블로그 ]

하지만 위의 기술 내용들은 Spring Framework를 이용하여 어노테이션 기반으로 개발중이라면 여간 성가시게 만드는 부분이 많지 않은가 싶습니다.

위의 내용도 매우 간단해 지고 쉬워졌지만 BlazeDS도 어노테이션을 이용해 연동할 수 있으면 얼마나 좋을까 생각하게 만들었습니다.

그러던중에 좋은 자료를 발견하였습니다.

1. Spring에서 @RemotingDestination 어노테이션을 사용하기 위해 다음의 라이브러리를 다운받습니다. 여기에는 Jeff Vroom씨가 만든 Spring Factory도 포함하고 있습니다.

[ 다운받으러 가기 ]

2. remotingdestination-annotation.zip 파일을 개발중인 프로젝트의 WEB-INF/lib 디렉토리에 넣어줍니다.

3. BlazeDS의 설정파일인 services-config.xml 에 SpringAutowiringBootStrapService를 등록해 줍니다.
[code]<?xml version=”1.0″ encoding=”UTF-8″?>
<services-config>
    <services>
        <service-include file-path=”remoting-config.xml” />
        <service-include file-path=”proxy-config.xml” />
        <service-include file-path=”messaging-config.xml” />
            <service id=”spring-autowiring-bootstrap-service”
                class=”flex.contrib.services.SpringAutowiringBootstrapService”/>
        <default-channels>
            <channel ref=”my-amf”/>
        </default-channels>
    </services>


….

    <factories>
        <factory id=”spring” class=”flex.contrib.factories.flex.SpringFactory” />
    </factories>
</services-config>[/code]
SpringAutowiringBootStrapService은 BlazeDS 로딩시에 모든 @RemotingDestination 어노테이션이 포함된 클래스를 등록합니다. 이것은 Spring Factory를 통해 동적으로 Spring의 Bean을 불러다 사용할 수 있음을 뜻합니다. 밑에 추가한 factory의 경우 id는 꼭 spring이어야 합니다.

4. 마지막으로 당신의 서비스 클래스에 @RemotingDestination 어노테이션을 붙여줍니다.
[code]package flex.contrib.samples.mortgage;


import org.springframework.beans.factory.annotation.Autowired;
import flex.contrib.stereotypes.RemotingDestination;


@RemotingDestination(destination=”mortgageService”)
public class Mortgage {
    @Autowired RateFinder rateFinder;
    public void setRateFinder(RateFinder rateFinder) {
        this.rateFinder = rateFinder;
    }


    public double calculate(double amount) {
        int term = 360; // 30 years
        double rate = rateFinder.findRate();
        return (amount*(rate/12)) / (1 – 1 /Math.pow((1 + rate/12), term));
    }
}[/code]

5. 물론 Spring에서 component-scan과 annotation-config를 설정해 주는걸 잊지 말자고요.
[code]<?xml version=”1.0″ encoding=”UTF-8″?>
<beans xmlns=”http://www.springframework.org/schema/beans
       xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance
       xmlns:context=”http://www.springframework.org/schema/context
       xsi:schemaLocation=”http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-2.5.xsd“>


    <context:annotation-config/>
    <context:component-scan base-package=”flex.contrib.samples”/>
</beans>[/code]

6. Flex 에서는 다양한 방법의 Remote Object 통신방법으로 서버의 서비스에 직접 접근할 수 있게 됩니다.
[code]var amfChannel:AMFChannel = new AMFChannel(“my-amf”, “http://localhost/messagebroker/amf“);
var channelSet:ChannelSet = new ChannelSet();
channelSet.addChannel(amfChannel);
   
var remoteObject:RemoteObject = new RemoteObject();
remoteObject.channelSet = channelSet;
remoteObject.destination = “mortgageService”;
remoteObject.addEventListener(ResultEvent.RESULT, resultHandler);
remoteObject.addEventListener(FaultEvent.FAULT, faultHandler);
remoteObject.calculate(5);[/code]

+. @RemotingDestination에서 지정한 destination이 Flex에서 지정하는 destination이 됩니다. 주의할점이 하나 있는데 web.xml의 contextConfigLocation 설정에서 정의한 컨텍스트의 Bean만 가져올 수 있습니다.

참고자료 : http://marceloverdijk.blogspot.com/2008/01/code-by-convention-with-flex-and-spring.html

[vi/vim] 진정한 멋쟁이는 VI를 사용합니다.

조금 웃기는 제목이지만 저도 어렸을적에 해킹 영화를 보면서 검은창에 알수없는 글자가 주르륵 올라가는것을 보며 왠지 모르게 멋지다는 생각을 했었던거 같습니다.

그래서 해커에 대해 끝없는 동경을 해왔었지만 지금 생각해 보면 아무것도 아닌 것이더군요;;

물론 아무것도 아닌것은 아니지만 모르고 보면 멋지지만 알고보면 평범함 그 자체….그것이 바로 Unix/Linux의 묘미가 아닐까요.

실예로 스크린샷은 없지만 모노폴리라는 국내의 양동근이 해킹 천재로 나오는 영화가 있습니다.

거기에 해킹하는 장면중에 뭐가 주르륵 올라가는것이 있는데 그걸 자세히 보니 리눅스 부팅 스크립트(rc.local) 이더군요;; 웃기죠;;ㅎㅎ

아무튼 유닉스던 리눅스던 쓰다보면 가장많이 사용하게 될 vi 에디터의 사용법에 대해 간단히 정리해 보겠습니다.

제가 자주 쓰는 명령어 위주로만 적어보겠습니다. emacs만큼은 아니지만 vi도 꽤 다양한 명령어 체계를 가지고 있습니다.

1. 기본 명령어
– 기본시작
[code]vi [filename][/code]
– 저장하고 종료
[code]ZZ
:wq[/code]
– 저장하지 않고 종료
[code]:q![/code]
– 명령어 모드로 진입
[code][esc][/code]

2. 커서 이동
– 왼쪽 / 아래 / 위 / 오른쪽
[code]h / j / k / l[/code]
– 줄의 시작 / 끝
[code]0 / $[/code]
– 이전단어 / 다음 단어
[code]b / e[/code]
– 화면상의 시작 / 중간 / 끝
[code]H / M / L[/code]

3. 화면 이동
– 이전 / 다음 페이지 이동
[code] ^B / ^F[/code]
– 가장 마지막 줄로 이동
[code]G[/code]
– 원하는 줄로 이동
[code][n]G[/code]

4. 커서 삽입 (명령어 모드에서 사용)
– 다음 칸에 삽입
[code]a[/code]
– 현재 칸에 삽입
[code]i[/code]
– 다음줄에 삽입
[code]o[/code]


5. 삭제
– 한글자 삭제
[code]x[/code]
– 한줄 삭제
[code]dd[/code]
– 현재 위치에서 원하는 줄 수만큼 삭제
[code][n]dd[/code]

6. 검색
– 이전 검색
[code]?[/code]
– 다음 검색
[code]/[/code]

7. 기타
– 현재위치 북마크
[code]m[x][/code]
– 저장된 북마크위치로 이동
[code]`[x][/code]

8. 탭 편집
– 새탭 생성
[code]:newtab [filename][/code]
– 탭탐색기실행
[code]:Te[/code]
– 다음탭 이동
[code]:tabn
gt[/code]
– 이전탭 이동
[code]:tabp
gT[/code]
– 탭 정렬 변경
[code]:tabm [n][/code]

9. 화면 분할
– 수평탭 나누기
[code]sp[/code]
– 수직탭 나누기
[code]vs[/code]
– 창 이동 (리눅스의 경우 hjkl 대신 방향키로도 가능)
[code]^ww / ^w[h / j / k / l][/code]
– 창 최대화
[code]^w_[/code]
– 창 원래대로
[code]^w+[/code]