<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    badqiu

    XPer
    隨筆 - 46, 文章 - 3, 評論 - 195, 引用 - 0
    數據加載中……

    與Spring BlazeDS Integration相比,更簡單的實現來調用spring bean

    注:后面使用SBI替代Spring BlazeDS Integration

     

    1.介紹:

    為了使flex客戶端能夠直接調用服務端的spring bean,SBI提供的此種功能,SBI使用DispatchServlet代理轉發MessageBrokerServlet的請求,增加了一些無用的類及相關配置,

    而其實完成相同的功能,最簡只需兩個類即可.

     

    2.擴展實現

     

    BlazeDS本身提供一個AbstractBootstrapService的類用于擴展,該類主要是在BlazeDS初始化時用于動態創建 services, destinations, and adapters. rapid擴展了該類,用于將spring applicationContext的bean自動導出為destination,以供flex客戶端調用. SpringRemotingDestinationBootstrapService 自動導出包含"@RemoteObject標注及以FlexService結尾"的Spring Bean為RemotingDestination


    Java代碼 
    1. public class SpringRemotingDestinationBootstrapService extends AbstractBootstrapService {  
    2.   
    3.     public static final String DEFAULT_INCLUDE_END_WITH_BEANS = "FlexService";  
    4.       
    5.         private String destChannel;  
    6.         private String destSecurityConstraint;  
    7.         private String destScope;  
    8.         private String destAdapter;  
    9.         private String destFactory;  
    10.           
    11.         private String serviceId;  
    12.           
    13.         private String includeEndsWithBeans;  
    14.   
    15.     public void initialize(String id, ConfigMap properties)  
    16.     {  
    17.         serviceId = properties.getPropertyAsString("service-id""remoting-service");  
    18.           
    19.                 destFactory = properties.getPropertyAsString("dest-factory""spring");  
    20.                 destAdapter = properties.getProperty("dest-adapter");  
    21.                 destScope = properties.getProperty("dest-scope");  
    22.                 destSecurityConstraint = properties.getProperty("dest-security-constraint");  
    23.                 destChannel = properties.getPropertyAsString("dest-channel","my-amf");  
    24.                   
    25.                 includeEndsWithBeans = properties.getPropertyAsString("includeEndsWithBeans",DEFAULT_INCLUDE_END_WITH_BEANS);  
    26.                   
    27.                 Service remotingService = broker.getService(serviceId);  
    28.                 if(remotingService == null) {  
    29.                         throw createServiceException("not found Service with serviceId:"+serviceId);  
    30.                 }  
    31.           
    32.         createSpringDestinations(remotingService);  
    33.     }  
    34.   
    35.         private ServiceException createServiceException(String message) {  
    36.                 ServiceException ex = new ServiceException();  
    37.                 ex.setMessage(message);  
    38.                 return ex;  
    39.         }  
    40.   
    41.         private void createSpringDestinations(Service remotingService) {  
    42.                 WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(broker.getInitServletContext());  
    43.                 List<String> addedBeanNames = new ArrayList();  
    44.                 for(String beanName : wac.getBeanDefinitionNames()) {  
    45.                         Class type = wac.getType(beanName);  
    46.                           
    47.                         boolean isCreateSpringDestination = type.isAnnotationPresent(RemotingObject.class)   
    48.                                                                                 || beanName.endsWith(includeEndsWithBeans)   
    49.                                                                                 || isCreateDestination(beanName,type);  
    50.                           
    51.                         if(isCreateSpringDestination) {  
    52.                                 createSpringDestination(remotingService, beanName);  
    53.                                 addedBeanNames.add(beanName);  
    54.                         }  
    55.                 }  
    56.                 System.out.println("[Auto Export Spring to RemotingDestination],beanNames="+addedBeanNames);  
    57.         }  
    58.   
    59.         protected boolean isCreateDestination(String beanName,Class type) {  
    60.                 return false;  
    61.         }  
    62.   
    63.     /* 
    64.     <!-- 
    65.         動態生成的配置內容 
    66.     --> 
    67.     <destination id="sampleVerbose"> 
    68.         <channels> 
    69.             <channel ref="my-secure-amf" /> 
    70.         </channels> 
    71.         <adapter ref="java-object" /> 
    72.         <security> 
    73.             <security-constraint ref="sample-users" /> 
    74.         </security> 
    75.         <properties> 
    76.             <source>my.company.SampleService</source> 
    77.             <scope>session</scope> 
    78.             <factory>myJavaFactory</factory> 
    79.         </properties> 
    80.     </destination>      
    81.      */  
    82.         protected void createSpringDestination(Service service, String destinationId) {  
    83.                 flex.messaging.services.remoting.RemotingDestination destination = (flex.messaging.services.remoting.RemotingDestination)service.createDestination(destinationId);  
    84.           
    85.         destination.setSource(destinationId);  
    86.         destination.setFactory(destFactory);  
    87.           
    88.         if(destAdapter != null)   
    89.                 destination.createAdapter(destAdapter);  
    90.         if(destScope != null)   
    91.                 destination.setScope(destScope);  
    92.         if(destSecurityConstraint != null)  
    93.                 destination.setSecurityConstraint(destSecurityConstraint);  
    94.         if(destChannel != null)  
    95.                 destination.addChannel(destChannel);  
    96.           
    97.         service.addDestination(destination);  
    98.         }  
    99.   
    100. }  
     

    3.配置

    將該類與網上的SpringFactory結合,即可使用. 以下為service-config.xml中關于自動導出的配置.

     

     

    Xml代碼 
    1.     <!-- 創建Spring RemotingDestination使用,與spring-remoting-service配合使用 -->  
    2.     <factories>  
    3.             <factory id="spring" class="cn.org.rapid_framework.flex.messaging.factories.SpringFactory"/>  
    4.     </factories>  
    5.       
    6. <services>  
    7.     <service-include file-path="remoting-config.xml" />  
    8.     <service-include file-path="proxy-config.xml" />  
    9.     <service-include file-path="messaging-config.xml" />  
    10.       
    11.     <!--   
    12.             自動導出包含"@RemoteObject標注及以FlexService結尾"的Spring Bean為RemotingDestination  
    13.             FlexService結尾可以通過includeEndsWithBeans變量指定  
    14.     -->  
    15.     <service id="spring-remoting-service" class="cn.org.rapid_framework.flex.messaging.services.SpringRemotingDestinationBootstrapService">  
    16.             <!-- 其它生成的RemotingDestination默認屬性 -->  
    17.             <properties>  
    18.                     <!--   
    19.                     <service-id></service-id>  
    20.                     <dest-factory></dest-factory>  
    21.                     <dest-adapter></dest-adapter>  
    22.                     <dest-scope></dest-scope>  
    23.                     <dest-channel></dest-channel>  
    24.                     <dest-security-constraint></dest-security-constraint>  
    25.                     <includeEndsWithBeans></includeEndsWithBeans>  
    26.                      -->  
    27.             </properties>  
    28.     </service>  
    29.               
    30. </services>  

     

    4.flex客戶端調用

     

    Java代碼 
    1. //簡單示例調用  
    2. this.blogFlexService = new RemoteObject("blogFlexService");  
    3.   
    4. //這里需要指定endpoint,因為是動態的RemotingDestination,而靜態的RemotingDestination ,flex編譯器會將endpoint編譯進源代碼.  
    5. //這個也是flex編譯器需要指定配置文件而導致使用flex經常會犯的錯誤之一.  
    6. this.blogFlexService.endpoint = '../messagebroker/amf';  

     

    5.結論

     

     

    與SBI相比,更加簡單即可完成相同功能。并且通過AbstractBootstrapService,你可以很容易的完成將Java Bean, Or EJB3的session bean導出為destinations以供flex客戶端直接調用.

    具體使用請下載rapidframework并查看flex插件



    posted on 2009-10-14 22:04 badqiu 閱讀(3023) 評論(2)  編輯  收藏

    評論

    # re: 與Spring BlazeDS Integration相比,更簡單的實現來調用spring bean  回復  更多評論   

    blogFlexService 這個是在哪里配置的? 是在Spring 里配置 還是在remoting-config.xml 里面配置???
    2009-12-22 14:45 | QQ:345728984

    # re: 與Spring BlazeDS Integration相比,更簡單的實現來調用spring bean[未登錄]  回復  更多評論   

    不需要配置,只要是spring容器里面的bean.

    然后滿足如下其中一個條件即可:

    . SpringRemotingDestinationBootstrapService 自動導出包含"@RemoteObject標注及以FlexService結尾"的Spring Bean為RemotingDestination
    2009-12-22 15:29 | badqiu

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲av一综合av一区| 九九九精品视频免费| 亚洲熟妇无码八AV在线播放| 日韩国产免费一区二区三区| 国产成人无码免费看片软件| 亚洲色最新高清av网站| 亚洲欧洲日韩不卡| 亚洲综合色自拍一区| 成人永久免费福利视频网站| 8090在线观看免费观看| 中国极品美軳免费观看| 美女视频黄频a免费大全视频| 国产在线一区二区综合免费视频| 色噜噜噜噜亚洲第一| 精品久久久久久久免费人妻| 亚洲最新中文字幕| 国产在线a不卡免费视频| 色se01短视频永久免费| 日本片免费观看一区二区| 久久久久国产免费| 香蕉成人免费看片视频app下载| 久久精品免费网站网| 免费无毒a网站在线观看| 久久久久久亚洲精品无码| 亚洲熟女综合色一区二区三区| 亚洲毛片无码专区亚洲乱| 亚洲午夜久久影院| 亚洲网址在线观看你懂的| 日韩亚洲Av人人夜夜澡人人爽| 亚洲精品成人av在线| 久久精品国产亚洲77777| 久久久亚洲AV波多野结衣| 亚洲美女中文字幕| 亚洲国产精品白丝在线观看| 亚洲成电影在线观看青青 | 亚洲欧洲免费无码| 亚洲熟女精品中文字幕| 亚洲AV日韩AV无码污污网站| 亚洲av日韩专区在线观看| 亚洲丶国产丶欧美一区二区三区| 亚洲av日韩av永久无码电影|