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

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

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

    badqiu

    XPer
    隨筆 - 46, 文章 - 3, 評(píng)論 - 195, 引用 - 0
    數(shù)據(jù)加載中……

    與Spring BlazeDS Integration相比,更簡(jiǎn)單的實(shí)現(xiàn)來(lái)調(diào)用spring bean

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

     

    1.介紹:

    為了使flex客戶(hù)端能夠直接調(diào)用服務(wù)端的spring bean,SBI提供的此種功能,SBI使用DispatchServlet代理轉(zhuǎn)發(fā)MessageBrokerServlet的請(qǐng)求,增加了一些無(wú)用的類(lèi)及相關(guān)配置,

    而其實(shí)完成相同的功能,最簡(jiǎn)只需兩個(gè)類(lèi)即可.

     

    2.擴(kuò)展實(shí)現(xiàn)

     

    BlazeDS本身提供一個(gè)AbstractBootstrapService的類(lèi)用于擴(kuò)展,該類(lèi)主要是在BlazeDS初始化時(shí)用于動(dòng)態(tài)創(chuàng)建 services, destinations, and adapters. rapid擴(kuò)展了該類(lèi),用于將spring applicationContext的bean自動(dòng)導(dǎo)出為destination,以供flex客戶(hù)端調(diào)用. SpringRemotingDestinationBootstrapService 自動(dòng)導(dǎo)出包含"@RemoteObject標(biāo)注及以FlexService結(jié)尾"的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.         動(dòng)態(tài)生成的配置內(nèi)容 
    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.配置

    將該類(lèi)與網(wǎng)上的SpringFactory結(jié)合,即可使用. 以下為service-config.xml中關(guān)于自動(dòng)導(dǎo)出的配置.

     

     

    Xml代碼 
    1.     <!-- 創(chuàng)建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.             自動(dòng)導(dǎo)出包含"@RemoteObject標(biāo)注及以FlexService結(jié)尾"的Spring Bean為RemotingDestination  
    13.             FlexService結(jié)尾可以通過(guò)includeEndsWithBeans變量指定  
    14.     -->  
    15.     <service id="spring-remoting-service" class="cn.org.rapid_framework.flex.messaging.services.SpringRemotingDestinationBootstrapService">  
    16.             <!-- 其它生成的RemotingDestination默認(rèn)屬性 -->  
    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客戶(hù)端調(diào)用

     

    Java代碼 
    1. //簡(jiǎn)單示例調(diào)用  
    2. this.blogFlexService = new RemoteObject("blogFlexService");  
    3.   
    4. //這里需要指定endpoint,因?yàn)槭莿?dòng)態(tài)的RemotingDestination,而靜態(tài)的RemotingDestination ,flex編譯器會(huì)將endpoint編譯進(jìn)源代碼.  
    5. //這個(gè)也是flex編譯器需要指定配置文件而導(dǎo)致使用flex經(jīng)常會(huì)犯的錯(cuò)誤之一.  
    6. this.blogFlexService.endpoint = '../messagebroker/amf';  

     

    5.結(jié)論

     

     

    與SBI相比,更加簡(jiǎn)單即可完成相同功能。并且通過(guò)AbstractBootstrapService,你可以很容易的完成將Java Bean, Or EJB3的session bean導(dǎo)出為destinations以供flex客戶(hù)端直接調(diào)用.

    具體使用請(qǐng)下載rapidframework并查看flex插件



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

    評(píng)論

    # re: 與Spring BlazeDS Integration相比,更簡(jiǎn)單的實(shí)現(xiàn)來(lái)調(diào)用spring bean  回復(fù)  更多評(píng)論   

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

    # re: 與Spring BlazeDS Integration相比,更簡(jiǎn)單的實(shí)現(xiàn)來(lái)調(diào)用spring bean[未登錄](méi)  回復(fù)  更多評(píng)論   

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

    然后滿(mǎn)足如下其中一個(gè)條件即可:

    . SpringRemotingDestinationBootstrapService 自動(dòng)導(dǎo)出包含"@RemoteObject標(biāo)注及以FlexService結(jié)尾"的Spring Bean為RemotingDestination
    2009-12-22 15:29 | badqiu

    只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 日韩a级毛片免费观看| 亚洲日韩VA无码中文字幕| mm1313亚洲精品无码又大又粗 | 亚洲综合色在线观看亚洲| 久久久久亚洲精品日久生情| 亚洲AV永久无码精品一福利| 野花香高清视频在线观看免费| 大学生一级特黄的免费大片视频| 激情综合色五月丁香六月亚洲| 色在线亚洲视频www| 久久一区二区免费播放| 免费羞羞视频网站| 亚洲AV区无码字幕中文色| 校园亚洲春色另类小说合集| 99久久99久久免费精品小说| 免费人成在线观看视频播放 | 久久亚洲精品人成综合网| 女bbbbxxxx另类亚洲| 在线免费观看你懂的| 亚洲精品国产综合久久一线| 亚洲三级视频在线观看 | 亚洲五月午夜免费在线视频| 歪歪漫画在线观看官网免费阅读| 亚洲综合图色40p| 亚洲爆乳精品无码一区二区| 亚洲一区二区在线免费观看| 亚洲乱码中文字幕综合234| 亚洲av永久无码精品天堂久久| 成全视频高清免费观看电视剧| 国产在线a不卡免费视频| 91午夜精品亚洲一区二区三区| 三级黄色片免费看| 免费国产不卡午夜福在线| 亚洲成a人片在线不卡| 在线人成精品免费视频| 最新国产AV无码专区亚洲| 国产一区二区三区亚洲综合| 三年片在线观看免费大全 | 色欲国产麻豆一精品一AV一免费 | 精品乱子伦一区二区三区高清免费播放 | 久久久久亚洲精品影视|