posts - 495,comments - 227,trackbacks - 0
http://blog.sharpplus.com/content/%E5%9C%A8google-appegine%E4%B8%8A%E9%83%A8%E7%BD%B2blazeds%E5%92%8Cspring%E7%A8%8B%E5%BA%8F

在Google appegine上部署BlazeDS和Spring程序(一)

作者:陈省

首先参考http://ria.dzone.com/articles/introduction-spring- blazeds?page=0,2这篇文章,这里我们使用Spring Blazeds Integration包来替代SpringFactory的解决方案来实现Spring和BlazeDS的集成.

1.首先修改Flex Builder3默认创建的web.xml文件。

1.1删除默认的MessageBroker Servlet

    <!-- 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>

换成Spring的DispatcherServlet
    <!-- MessageBroker Servlet -->
    <servlet>
        <servlet-name>MessageBrokerServlet</servlet-name>
        <display-name>MessageBrokerServlet</display-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

注意,Spring加载MessageBrokerServlet的时候,会同时查找WEB-INF\MessageBrokerServlet- servlet.xml文件,添加WEB-INF\MessageBrokerServlet-servlet.xml文件,内容是加载spring的 xsd

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

</beans>

删除默认的Flex Listener和上下文配置

    <context-param>
        <param-name>flex.class.path</param-name>
        <param-value>/WEB-INF/flex/hotfixes,/WEB-INF/flex/jars</param-value>
    </context-param>

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

换成Spring的上下文和Spring用Filter

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/config/web-application-config.xml
            /WEB-INF/config/web-application-security.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>
   
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

1.2集成Spring的安全认证

可以从http://coenraets.org/blog/2009/05/new-test-drive-for-spring- blazeds-integration-rc1/下载Spring Blazeds TestDrive集成包,查考里面的WEB-INF\config\web-application-security.xml文件
 

1.3开放Spring Bean提供给Flex Remoting使用,修改testdrive的WEB-INF\config\web-application-config.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:security="http://www.springframework.org/schema/security"
    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/flex
        http://www.springframework.org/schema/flex/spring-flex-1.0.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-2.0.4.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-2.5.xsd">

 
    <flex:message-broker/>

    <bean id="UserService" class="com.sharpplus.UserService" >
    </bean>

    <!-- Expose the productDAO bean for BlazeDS remoting -->
    <flex:remoting-destination ref="UserService" />
</beans>
 

UserService Bean只有一个GetUser方法,返回一个Hello Blazeds的字符串

package com.sharpplus;

public class UserService {
    public String getUser(){
        return "Hello Blazeds";
    }
}

创建Flex客户端界面,调用我们的UserService,显示字符串信息

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            import mx.rpc.events.ResultEvent;
            import mx.controls.Alert;
           
            private function onClick():void{
                ro.getUser.addEventListener(ResultEvent.RESULT, onResult);
                ro.getUser();
            }
           
            private function onResult(event:ResultEvent):void{
                var s:String=event.result as String;
                Alert.show(s);
            }
        ]]>
    </mx:Script>
    <mx:Button x="257" y="193" label="Hello BlazeDS"  click="onClick()"/>
    <mx:RemoteObject id="ro" destination="UserService">
       
    </mx:RemoteObject>
   
</mx:Application>
 

JDBC for Google appengine

http://www.jiql.org/



posted on 2011-02-25 15:56 SIMONE 阅读(658) 评论(0)  编辑  收藏 所属分类: flash

只有注册用户登录后才能发表评论。


网站导航: