'플레이즈디에스'에 해당되는 글 1건

  1. 2009.10.29 [Flex] Flash Builder Beta2에서 Data/Services기능을 통한 BlazeDS연동. 3
 
다운로드는 여기서....-_- adobe.com 사이트에 가입하셔야 합니다.

BlazeDS버전이 4.X대여야 잘 됩니다. 3.X대면 안되더군요.
그리고 BlazeDS버전이 4.x의 Beta1버전이 있는데, 이걸로 하면 요런 에러가 뜹니다.
ERROR : XML parse error : Error on line 1 of document : cvc-elt.1: Cannot find the declaration of element 'model'. Nested exception: cvc-elt.1: Cannot find the declaration of element 'model'.>$2
그래서 전 Night Build중에 4.0.0.11030버전을 사용해서 하니 되더군요.
다운로드는 여기서 http://opensource.adobe.com/wiki/display/blazeds/download+blazeds+trunk

제 환경은 Eclipse 3.5, Flash Builder 4 Beta 2, JDK 1.6.0 U 16입니다.
플러그인으로 못깐 이유가 기존의 Flex Builder 3가 플러그인으로 깔려있는데, 왠지 꼬일 것 같아서(새가슴 ㄷㄷ)-_-

우선 blazeds.war파일을 Eclipse에서 import.
web.xml을 보면 이상한 Servlet이 하나 더 생겼는데요. RDSDispatchServlet.
이거 풀고, 인증부분을 false로 바꾸면 됩니다. 자체적으로 할 수 있는 인증이 생긴 것 같은데, 이건 더 해봐야 알겠네요.
web.xml
[code]<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

    <display-name>BlazeDS</display-name>
    <description>BlazeDS Application</description>

    <!-- Http Flex Session attribute and binding listener support -->
    <listener>
        <listener-class>flex.messaging.HttpFlexSession</listener-class>
    </listener>

    <!-- MessageBroker Servlet -->
    <servlet>
        <servlet-name>MessageBrokerServlet</servlet-name>
        <display-name>MessageBrokerServlet</display-name>
        <servlet-class>flex.messaging.MessageBrokerServlet</servlet-class>
        <init-param>
            <param-name>services.configuration.file</param-name>
            <param-value>/WEB-INF/flex/services-config.xml</param-value>
       </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
   
<!-- begin rds -->
    <servlet>
        <servlet-name>RDSDispatchServlet</servlet-name>
        <display-name>RDSDispatchServlet</display-name>
        <servlet-class>flex.rds.server.servlet.FrontEndServlet</servlet-class>
        <init-param>
            <param-name>useAppserverSecurity</param-name>
            <param-value>false</param-value>
        </init-param>       
        <load-on-startup>10</load-on-startup>
    </servlet>

    <servlet-mapping id="RDS_DISPATCH_MAPPING">
        <servlet-name>RDSDispatchServlet</servlet-name>
        <url-pattern>/CFIDE/main/ide.cfm</url-pattern>
    </servlet-mapping>
<!-- end rds -->

    <servlet-mapping>
        <servlet-name>MessageBrokerServlet</servlet-name>
        <url-pattern>/messagebroker/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
    </welcome-file-list>
</web-app>[/code]
테스트 클래스를 하나 만듭니다.
Test.java
[code]package com.mudchobo.test;

public class TestService {

    public String sayHello(String name)
    {
        return "Hello! " + name;
    }
}[/code]
remoting-config.xml에 destination을 추가.
remoting-config.xml
[code]<destination id="test">
    <properties>
          <source>com.mudchobo.test.TestService</source>
          <scope>application</scope>
     </properties>
     <adapter ref="java-object" />
</destination>[/code]
서버를 이제 작동을 시켜서 띄워둡니다.

이제 Flash Builder로...

프로젝트 생성 -> 타입은 Web, Server type은 J2EE(BlazeDS)
Server location은 Root Folder는 해당 blazeds임포트한 폴더에 있는 WebContent.
Root URL은 http://localhost:8080/blazeds
Context root는 blazeds
Validate Configuration하면 왜 안되지...-_- 암튼 그냥 Finish를 누릅니다-_-

맨 하단에 Data/Services 탭이 있는데, 거기서 Connect to Data/Service.. 클릭.
BlazeDS선택, destionation으로 설정한 test가 하나 보일꺼임. 선택 Finish.
그럼 해당 Destination에 있는 함수인 sayHello가 보이는군요. 사용해봅시다.
여러가지 기능이 있는데요. 저도 잘 몰라서 많이 안해봤는데, 우선 기존에 삽질을 덜어주기 위한 많은 기능을 넣은 것 같습니다. 테스트도 할 수 있고, 자동으로 remoteObject코드도 만들어주고, 뭐 그런 것 같습니다.
Form도 만들어주네요-_-

Test Opeartion을 했더니 파라메터를 던지니 Response value로 나오네요.
사용자 삽입 이미지
버튼 클릭 시 데이터를 요청하는 걸 만들기 위해 Design모드로 변경.
Button과 TextInput, 결과 Label을 하나 추가.
button은 id를 btn, TextInput은 input. button에 오른쪽버튼 누르면 generate Service Call클릭.
그러면 자동으로 click핸들러 함수 만들어지고, sayHello함수 파라메터만 넣으면 되는데, 여기에는 input.text를 넣으면 끝.
Label에는 text에다가 sayHelloResult.lastResult를 바인딩.

DataTest.mxml
[code]<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768" xmlns:test="services.test.*">
    <fx:Script>
        <![CDATA[
            import mx.controls.Alert;

            protected function btn_clickHandler(event:MouseEvent):void
            {
                sayHelloResult.token = test.sayHello(input.text);
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <s:CallResponder id="sayHelloResult"/>
        <test:Test id="test" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:Button x="248" y="245" label="Button" click="btn_clickHandler(event)" id="btn"/>
    <s:TextInput x="223" y="215" id="input"/>
    <s:Label x="260" y="274" text="{sayHelloResult.lastResult}"/>
   
</s:Application>
[/code]
이런 코드가 됨. 개판임-_-
사용자 삽입 이미지

PS. 자동으로 다 해줘서 좋긴 한데...왠지 익숙하지 않은 코드가.....

참고자료
http://sujitreddyg.wordpress.com/2009/06/01/building-flex-application-for-blazeds-remoting-service-using-flash-builder-4/
 
Posted by 머드초보
,