`
zerozone
  • 浏览: 203796 次
  • 来自: 北京
社区版块
存档分类
最新评论

FlexPetStore--集成Flex和Spring (2)

阅读更多
Flex部署在Flex Builder帮助中有详细说明(如部署目录结构)。遗憾的是没有例子介绍Flex如何集成Spring。本文尝试解释这部分内容。由于机器重装,导致FlexPetStore的项目丢失,幸好是覆盖安装留下了可运行的WAR。

FlexPetStore通过RemoteObject技术访问JPetStoreFacade业务对象(引入一个FacadeAccessor对象),因此使用了Flex Data Service 2.0。

大致流程:

Flex (ActionScript )<--> AMF协议(AMF协议编码)<-->(解码)<-->FacadeAccessor (Java) <--> PetStoreFacade (Java)<--> ...

看了一下 FDS 2.0 提供的几个应用WAR,发现只要按照Flex的部署思路,在现有WAR基础上适当修改就可以集成Flex和Spring。首先需要把flex.war该名为flexpetstore.war,现在按照一下介绍逐步修改。

Spring集成

1. 加入Lib库。把spring.jar和jpetsotre.jar放到 flexpetstore\WEB-INF\lib下,这是运行Spring和JPetstore的必备包。
2. 修改flexpetstore.war的web.xml,经过一番对比和试验找到两个段落需要修改。
   a. 添加web应用根目录和Spring应用上下文以及数据访问资源配置。
   b. 添加Remoting、web service。struts部分极有可能多余,因为没有action来Request。有待测试。
   c. 修改welcome-file-list,FlexPetStore.html是FlexPetStore项目名称
  

到此为止,集成Spring配置基本完成。还有一部分服务端的Java代码作为RemoteObject供Flex访问,下一部分再讲解。

附件是两份web.xml。

FacadeAccessor首先获取
应用context,然后从context得到PetStoreFacade业务对象。
java 代码
 
  1. // Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov  Date: 2007-05-22 22:12:45  
  2. // Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!  
  3. // Decompiler options: packimports(3)   
  4. // Source File Name:   FacadeAccessor.java  
  5.   
  6. package org.springframework.samples.jpetstore.domain.logic.flex;  
  7.   
  8. import java.io.*;  
  9. import java.util.List;  
  10. import org.springframework.context.support.ClassPathXmlApplicationContext;  
  11. import org.springframework.samples.jpetstore.domain.*;  
  12. import org.springframework.samples.jpetstore.domain.logic.PetStoreFacade;  
  13. import org.springframework.samples.jpetstore.domain.logic.flex.exception.NotFoundBeanDifinitionException;  
  14. import org.springframework.samples.jpetstore.domain.logic.flex.exception.OutputBeanDifinitionException;  
  15.   
  16. public class FacadeAccessor {  
  17.   
  18.     public FacadeAccessor() {  
  19.         petStoreFacade = null;  
  20.         init();  
  21.     }  
  22.   
  23.     private void init() {  
  24.         try {  
  25.             getPetStoreFacade();  
  26.         } catch (Exception exception) {  
  27.         }  
  28.     }  
  29.   
  30.     private PetStoreFacade getPetStoreFacade()  
  31.             throws NotFoundBeanDifinitionException,  
  32.             OutputBeanDifinitionException {  
  33.         if (petStoreFacade == null) {  
  34.             ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(  
  35.                     "/applicationContext*.xml");  
  36.             String beanDefinitionNames[] = ctx.getBeanDefinitionNames();  
  37.             if (beanDefinitionNames == null || beanDefinitionNames.length < 1)  
  38.                 throw new NotFoundBeanDifinitionException(  
  39.                         "Not found bean difinitions.");  
  40.             petStoreFacade = (PetStoreFacade) ctx.getBean("petStore");  
  41.         }  
  42.         return petStoreFacade;  
  43.     }  
  44.   
  45.     private void outputBeanDefinitionNames(String beanDefinitionNames[])  
  46.             throws OutputBeanDifinitionException {  
  47.         if (beanDefinitionNames != null && beanDefinitionNames.length > 0) {  
  48.             DataOutputStream out = null;  
  49.             try {  
  50.                 out = new DataOutputStream(new BufferedOutputStream(  
  51.                         new FileOutputStream("c:\\beandifinitions.txt")));  
  52.                 for (int i = 0; i < beanDefinitionNames.length; i++)  
  53.                     out.writeBytes((new StringBuilder(String  
  54.                             .valueOf(beanDefinitionNames[i]))).append("\r\n")  
  55.                             .toString());  
  56.   
  57.                 out.close();  
  58.             } catch (IOException e) {  
  59.                 throw new OutputBeanDifinitionException((new StringBuilder(  
  60.                         "error occurs when output bean difinitions to file,"))  
  61.                         .append(e.getMessage()).toString());  
  62.             }  
  63.         }  
  64.     }  
  65.   
  66.     public Account getAccount(String username) {  
  67.         return petStoreFacade.getAccount(username);  
  68.     }  
  69.   
  70.     public Account getAccount(String username, String password) {  
  71.         return petStoreFacade.getAccount(username, password);  
  72.     }  
  73.   
  74.     public void insertAccount(Account account) {  
  75.         petStoreFacade.insertAccount(account);  
  76.     }  
  77.   
  78.     public void updateAccount(Account account) {  
  79.         petStoreFacade.updateAccount(account);  
  80.     }  
  81.   
  82.     public List getUsernameList() {  
  83.         return petStoreFacade.getUsernameList();  
  84.     }  
  85.   
  86.     public List getCategoryList() {  
  87.         return petStoreFacade.getCategoryList();  
  88.     }  
  89.   
  90.     public Category getCategory(String categoryId) {  
  91.         return petStoreFacade.getCategory(categoryId);  
  92.     }  
  93.   
  94.     public List getProductListByCategory(String categoryId) {  
  95.         return petStoreFacade.getProductListByCategory(categoryId);  
  96.     }  
  97.   
  98.     public List searchProductList(String keywords) {  
  99.         return petStoreFacade.searchProductList(keywords);  
  100.     }  
  101.   
  102.     public Product getProduct(String productId) {  
  103.         return petStoreFacade.getProduct(productId);  
  104.     }  
  105.   
  106.     public List getItemListByProduct(String productId) {  
  107.         return petStoreFacade.getItemListByProduct(productId);  
  108.     }  
  109.   
  110.     public Item getItem(String itemId) {  
  111.         return petStoreFacade.getItem(itemId);  
  112.     }  
  113.   
  114.     public boolean isItemInStock(String itemId) {  
  115.         return petStoreFacade.isItemInStock(itemId);  
  116.     }  
  117.   
  118.     public void insertOrder(Order order) {  
  119.         petStoreFacade.insertOrder(order);  
  120.     }  
  121.   
  122.     public Order getOrder(int orderId) {  
  123.         return petStoreFacade.getOrder(orderId);  
  124.     }  
  125.   
  126.     public List getOrdersByUsername(String username) {  
  127.         return petStoreFacade.getOrdersByUsername(username);  
  128.     }  
  129.   
  130.     private static final boolean output = false;  
  131.   
  132.     private static final String OUTPUT_BEANDIFINITIONS_PATHFILE = "c:\\beandifinitions.txt";  
  133.   
  134.     private static final String APPLICATION_CONTEXT_XML = "/applicationContext*.xml";  
  135.   
  136.     private PetStoreFacade petStoreFacade;  
  137. }  
  • web.zip (1.2 KB)
  • 下载次数: 195
  • web.zip (2.7 KB)
  • 下载次数: 229
分享到:
评论

相关推荐

    spring-flex-1.5.0.M2-dist.zip

    在Spring Flex 1.5.0.M2中,核心组件`spring-flex-1.5.0.M2.jar`扮演了关键角色,它是Spring和Flex集成的核心库,提供了诸如消息代理、配置支持和Spring服务代理等功能。这个库使得Flex客户端可以轻松地调用Spring...

    spring-flex集成-demo

    7. **测试驱动开发**:在"spring-flex-testdrive"中,可能包含了测试用例,展示了如何为Spring Flex应用编写单元测试和集成测试,以确保代码质量。 通过这个示例,你可以学习如何配置Spring Flex项目,如何在Flex中...

    Flex blazeds-spring

    Flex blazeds-spring Flex blazeds-spring Flex blazeds-spring Flex blazeds-spring Flex blazeds-spring Flex blazeds-spring

    spring-flex-1.5.0.RELEASE

    spring-flex-1.5.0.RELEASE spring-flex-1.5.0.RELEASE spring-flex-1.5.0.RELEASE spring-flex-1.5.0.RELEASE

    spring-flex-1.0.1.RELEASE

    2. `spring-flex-core`:这个模块包含了处理 Flex 与 Spring 之间消息传递的类,如 `MessageBrokerServlet` 和 `RemotingDestination`。 3. `spring-flex-rpc`:该模块提供了基于 Spring AOP 的远程代理服务,允许...

    org.springframework.flex-1.0.3.RELEASE.jar.zip

    org.springframework.flex-1.0.3.RELEASE.jar.zip用于JAR包,org.springframework.flex-1.0.3.RELEASE.jar.zip用于JAR包org.springframework.flex-1.0.3.RELEASE.jar.zip用于JAR包org.springframework.flex-1.0.3....

    跟我StepByStep学FLEX教程-王一松.pdf

    1 27 跟我StepByStep学FLEX教程------Demo12之FLEX和Spring整合 1 28 跟我StepByStep学FLEX教程------访问数据库之JDBCTemplate 1 29 跟我StepByStep学FLEX教程------访问数据库之hsqldb 1 30 跟我StepByStep学...

    flex-spring-blazeds demo

    这个demo项目为开发者提供了一个起点,以便进一步研究和应用Flex、Spring和BlazeDS的集成技术,创建出高性能、高交互性的RIA应用。无论是新手还是经验丰富的开发者,都可以从中受益,提升自己的技能水平。

    Spring整合flex-Spring BlazeDS Integration-带项目demo

    - **WEB-INF**:Web应用的标准目录,可能包含`web.xml`部署描述符,配置Spring和BlazeDS的入口。 - **flex_src**:Flex源代码目录,包含了Flex项目的MXML和ActionScript文件。 - **java_src**:Java源代码目录,...

    Flex-Spring拦截器

    Flex-Spring 拦截器是 Spring 框架与 Adobe Flex 之间的集成关键部分,它允许在服务调用之间添加拦截逻辑,从而实现如事务管理、权限验证、日志记录等功能。这篇博客(https://rogerhunt.iteye.com/blog/608778)...

    spring-flex-1.5.2

    5. **配置文件**:Spring Flex 使用 `flex-servlet.xml` 和 `flex-config.xml` 文件来配置 Flex 和 Spring 之间的交互。`flex-servlet.xml` 配置了 Flex 服务端的Servlet,而 `flex-config.xml` 用于定义消息代理和...

    spring-flex-reference

    spring-flex-reference.pdf spring与flex的集成

    spring-flex-core-1.5.0.M1.jar

    Spring BlazeDS Integration

    spring整合flex所需jar包

    - Spring-BlazeDS Integration:这是一个Spring项目,它提供了与BlazeDS的集成,使得配置Spring服务为Flex客户端可用变得更加简单。 - Proxy服务:在Spring中定义Proxy服务,这些服务会被BlazeDS暴露,供Flex...

    flex-messaging-4.7.3最新版本的jar

    flex-messaging-4.7.3最新版本的jar

    flex-messaging-core-4.7.3.jar

    flex-messaging-core-4.7.3.jar 最新版,下载了好长时间才下载下来,亲测可用!

    S2Flex2-1.1.0

    S2Flex2-1.1.0是一个专为Flash播放器设计的软件库,它使得开发者能够利用Adobe Flex这一强大的客户端开发工具与Seasar2服务器端框架进行无缝集成。本文将深入探讨S2Flex2的核心功能、工作原理以及在实际项目中的应用...

    Flex-Spring-JAVA-BLAZEDS.rar_Flex spring_flex_flex java

    Flex Spring JAVA BLAZEDS整合,永固整合将flex与Spring整合

    Flex SVN--1.5.5版本

    Flex SVN--1.5.5版本Flex SVN--1.5.5版本Flex SVN--1.5.5版本Flex SVN--1.5.5版本Flex SVN--1.5.5版本Flex SVN--1.5.5版本Flex SVN--1.5.5版本

    flex-messaging系列jar包

    3. **flex-messaging-common.jar**:包含了Flex Messaging框架的一些通用类和接口,如消息代理、消息头和消息体的定义,以及错误处理和安全相关类。这些组件构成了Flex与服务器间消息交换的基础结构。 4. **flex-...

Global site tag (gtag.js) - Google Analytics