'Web/Flex'에 해당되는 글 5건

  1. 2013.07.26 Flex Blazeds + Spring 3 연동시 Flex RemoteObject 설정
  2. 2013.04.22 (Flex 4)Blazeds + Spring 연동 Test
  3. 2013.04.19 (Flex 4)Blazeds + Spring 연동 Test Project 생성

Flex Blazeds + Spring 3 연동시 Flex RemoteObject 설정

|

Flex Remote Object 설정

    <fx:Declarations>
        <s:RemoteObject id="re" destination="ShmObj">
            <s:channelSet>
                <s:ChannelSet>
                    <s:AMFChannel uri="http://hostname/messagebroker/amf"/>
                </s:ChannelSet>
            </s:channelSet>
            <s:method name="getObject" fault="fltEvent(event)" result="rltEvent(event)">
                <s:arguments>
                    <Name>
                        {paramName}
                    </Name>
                </s:arguments>
            </s:method>
        </s:RemoteObject>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>

tomcat + spring 3 + blazeds 연동 설정이 끝났을 경우 어노테이션 기반 코딩을 할 것이다.

Service 등록과 amf채널 설정이 끝났는데 Flex에서 값을 실제 Service 되는 곳에서 받아 오고 싶을 경우 위와 같이 채널을 지정해 버리면 된다.

그런데 이 경우 보안 문제로 Reslt 가 아닌 Fault를 뱉어 낼 것이다.

이 경우 crossdomain을 설정해 주면 되는데


호스팅이 되는 root에 crossdomain.xml을 등록해 줘야 된다.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">

<cross-domain-policy>
 <site-control permitted-cross-domain-policies="all"/>
 <allow-access-from domain="*"/>
</cross-domain-policy>


이렇게 하면 보안상에 문제가 되겠지만(?) 값을 확인해서 받아 볼 수 있다.

잘 돌아간다 판단 되면 Flex를 서버에서 돌아가는 형식으로 다시 전환후 배포해 보쟈!

문제가 되지 않느다 판단되면 그냥 계속 사용해도 문제 없겠다.


And

(Flex 4)Blazeds + Spring 연동 Test

|

web.xml

Test 진행에서는 딱히 손댈만한 곳이 없다!


<?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>FlexSpringTest</display-name>
    <description>FlexSpring Integration Test Application</description>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring/*-config.xml
        </param-value>
    </context-param>
    
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
      <filter-name>springSecurityFilterChain</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>

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

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Spring Dispatcher Servlet -->   
    <servlet>
        <servlet-name>flex</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <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>true</param-value>
        </init-param>
        <init-param>
            <param-name>messageBrokerId</param-name>
            <param-value>_messageBroker</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>flex</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>

    <!-- for WebSphere deployment, please uncomment -->
    <!--
    <resource-ref>
        <description>Flex Messaging WorkManager</description>
        <res-ref-name>wm/MessagingWorkManager</res-ref-name>
        <res-type>com.ibm.websphere.asynchbeans.WorkManager</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    -->

</web-app>

/flex/services-config.xml


<?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" />
        <default-channels>
           <channel ref="my-amf"/>
        </default-channels>        
    </services>

    <security>
        <login-command class="flex.messaging.security.TomcatLoginCommand" server="Tomcat"/>
        <!-- Uncomment the correct app server
        <login-command class="flex.messaging.security.TomcatLoginCommand" server="JBoss">
        <login-command class="flex.messaging.security.JRunLoginCommand" server="JRun"/>        
        <login-command class="flex.messaging.security.WeblogicLoginCommand" server="Weblogic"/>
        <login-command class="flex.messaging.security.WebSphereLoginCommand" server="WebSphere"/>
        -->

        <!--
        <security-constraint id="basic-read-access">
            <auth-method>Basic</auth-method>
            <roles>
                <role>guests</role>
                <role>accountants</role>
                <role>employees</role>
                <role>managers</role>
            </roles>
        </security-constraint>
         -->
    </security>

    <channels>

        <channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
        </channel-definition>

        <channel-definition id="my-secure-amf" class="mx.messaging.channels.SecureAMFChannel">
            <endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure" class="flex.messaging.endpoints.SecureAMFEndpoint"/>
            <properties>
                <add-no-cache-headers>false</add-no-cache-headers>
            </properties>
        </channel-definition>

        <channel-definition id="my-polling-amf" class="mx.messaging.channels.AMFChannel">
            <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amfpolling" class="flex.messaging.endpoints.AMFEndpoint"/>
            <properties>
                <polling-enabled>true</polling-enabled>
                <polling-interval-seconds>4</polling-interval-seconds>
            </properties>
        </channel-definition>

        <!--
        <channel-definition id="my-http" class="mx.messaging.channels.HTTPChannel">
            <endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/http" class="flex.messaging.endpoints.HTTPEndpoint"/>
        </channel-definition>

        <channel-definition id="my-secure-http" class="mx.messaging.channels.SecureHTTPChannel">
            <endpoint url="https://{server.name}:{server.port}/{context.root}/messagebroker/httpsecure" class="flex.messaging.endpoints.SecureHTTPEndpoint"/>
            <properties>
                <add-no-cache-headers>false</add-no-cache-headers>
            </properties>
        </channel-definition>
        -->
    </channels>

    <logging>
        <target class="flex.messaging.log.ConsoleTarget" level="Error">
            <properties>
                <prefix>[BlazeDS] </prefix>
                <includeDate>false</includeDate>
                <includeTime>false</includeTime>
                <includeLevel>false</includeLevel>
                <includeCategory>false</includeCategory>
            </properties>
            <filters>
                <pattern>Endpoint.*</pattern>
                <pattern>Service.*</pattern>
                <pattern>Configuration</pattern>
            </filters>
        </target>
    </logging>

    <system>
        <redeploy>
            <enabled>false</enabled>
            <!--
            <watch-interval>20</watch-interval>
            <watch-file>{context.root}/WEB-INF/flex/services-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/proxy-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/remoting-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/messaging-config.xml</watch-file>
            <watch-file>{context.root}/WEB-INF/flex/data-management-config.xml</watch-file>
            <touch-file>{context.root}/WEB-INF/web.xml</touch-file>
             -->
        </redeploy>
    </system>

</services-config>

remoting service를 사용하여 Test를 진행 할 테니 기본 채널을 설정해 준다!

java package를 만들어 준다!!

com.test.HelloTest.java

package com.test;

public class HelloTest {
    public String SayHello(String Name) { return Name + " Test !!"; }
}

com.test.HelloTest2.java

package com.test;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.stereotype.Service;

@Service("Hello2")
@RemotingDestination
public class HelloTest2 {
    public String SayHello(String Name) { return Name + " Test2 !!"; }
}

flex-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:flex="http://www.springframework.org/schema/flex"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context-2.5.xsd     
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/flex
        http://www.springframework.org/schema/flex/spring-flex-1.0.xsd">
 
    <flex:message-broker />
    <context:annotation-config />   
    <context:component-scan base-package="com.test" />
    
    <bean id="Hello" class="com.test.HelloTest">
        <flex:remoting-destination />
    </bean>
</beans>

java annotation사용을 위해 context스키마를 추가해 준다!

<flex:message-broker />

사용하여 message broker를 /felx/services-config.xml.에 있는 amf와 연결시킨다

<context:annotation-config />
<context:component-scan base-package="com.test" />

annotation 사용을 하는 package scan을 한다.

<bean id="Hello" class="com.test.HelloTest">
     <flex:remoting-destination />
</bean>

annotation 사용하지 않는 bean을 등록한다.

flexSource.mxml

<?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/mx" minWidth="955" minHeight="600">
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
        <s:RemoteObject id="re2" destination="Hello2">
            <s:channelSet>
                <s:ChannelSet>
                    <s:AMFChannel uri="http://localhost/FlexSpringTest/messagebroker/amf"/>
                </s:ChannelSet>
            </s:channelSet>
            <s:method name="SayHello" fault="OnReFault(event)" result="OnReResult(event)">
                <s:arguments>
                    <Name>
                        {paramName2}
                    </Name>
                </s:arguments>
            </s:method>
        </s:RemoteObject>
        <s:RemoteObject id="re" destination="Hello">
            <s:channelSet>
                <s:ChannelSet>
                    <s:AMFChannel uri="http://localhost/FlexSpringTest/messagebroker/amf"/>
                </s:ChannelSet>
            </s:channelSet>
            <s:method name="SayHello" fault="OnReFault(event)" result="OnReResult(event)">
                <s:arguments>
                    <Name>
                        {paramName}
                    </Name>
                </s:arguments>
            </s:method>
        </s:RemoteObject>
    </fx:Declarations>
    <fx:Script>
        <![CDATA[
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;

            [Bindable]
            var paramName:String;
            var paramName2:String;
            public function OnReFault(e:FaultEvent):void
            {
                trace(e.fault.message);
            }
            public function OnReResult(e:ResultEvent):void
            {
                trace(e.result);
            }
            
            protected function OnClick(event:MouseEvent):void
            {
                // TODO Auto-generated method stub
                paramName = txtName.text;
                paramName2 = txtName.text;
                lbHello1.text = re.SayHello();
                lbHello2.text = re2.SayHello();
                
            }
            
        ]]>
    </fx:Script>
    <s:Button x="118" y="114" label="확인" click="OnClick(event)"/>
    <s:Label id="lbHello1" x="118" y="162" text=""/>
    <s:Label id="lbHello2" x="118" y="195" text=""/>
    <s:TextInput id="txtName" x="118" y="72"/>
</s:Application>

Source를 build해서 확인 버튼을 눌렀을때 label에 값이 정상적으로 올라왔을 때 정상적으로 생성됬다고 볼 수 있다!


And

(Flex 4)Blazeds + Spring 연동 Test Project 생성

|

Test Project를 생성한다 Dynamic Web Project와 Flex Project방식 있는데 Dynamic web Project로 하겠다.

java_src를 하나 만들어준다.

자.. Project가 하나 생성 됬다! 여기에 Blazeds-spring war를 추가 할꺼다!

import를 선택해 주시고!

lib에 Spring까지 추가 됐는지 확인한다!

web.xml에 기본 정의되어 있는 index.jsp를 하나 만들어 준다.

여기까지가 웹설정!! 이제 Flex Project로 Convert 할꺼다!!

Convert 하면 Error가 하나 떨어진다! 간단하게 퇴치해 주쟈!!

여기까지 됬다면 대략 준비는 됬다!! 그런데 필자는 Flex Project환경과 최대한 비슷하게 만들어 줄려고 조금더 손을 봤다!

설정된 최종루틴은 이 정도 되겠다!!

tomcat server에 등록한 후에 Test해서 Page가 제대로 올라오면 정상적으로 생성됬다고 보면되겠다!

이렇게 말고 Flex Project를 생성해서 Blazeds-spring.war만 추가해줘도 간단하게 되긴한다! 우선 간단한 방법보다는 세세한 설정을 위해 복작한 방법을 채택해 봤다!! 연관관계가 어떻게 되는지 확인해 보쟈!! 우선 하는거보다는 이해하는게 우선이니!!

 


And
prev | 1 | 2 | next