【问题标题】:How this Flex front end application is connected to my back end application? Where the mx:RemoteObject URL endpoint URL are defined?这个 Flex 前端应用程序如何连接到我的后端应用程序? mx:RemoteObject URL 端点 URL 是在哪里定义的?
【发布时间】:2024-05-02 22:40:06
【问题描述】:

我是 Flex 的新手。

我正在开发一个旧的(由其他人制作的)应用程序,该应用程序具有以下架构:从 Java 后端应用程序接收数据的 Flex 前端。

我拼命想了解前端是如何连接到前端的(我必须部署这个应用程序,所以我需要将后端指针更改为 Flex 前端应用程序)。

在我的 FLEX 前端中,我发现这个 MyAppServices.mxml 文件包含一些应该代表 MXML 文件中的 HTTPService 对象的 标记。

阅读官方文档:

此标记使您可以使用 Action 访问 Java 对象的方法 消息格式 (AMF) 编码。

所以它应该是指向我的后端服务的指针:

<?xml version="1.0" encoding="utf-8"?>
<rds:ServiceLocator 
    xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:rds="com.adobe.cairngorm.business.*">
    <mx:Script>
        <![CDATA[
            import org.myOrganization.myApp.util.ConfigServer;
        ]]>
    </mx:Script>


    <mx:RemoteObject 
        id="genericService"     
        destination="genericService"  
        endpoint= "messagebroker/amf" 
        showBusyCursor="true" 
        requestTimeout="100"
        />

    <mx:RemoteObject 
        id="themeService"       
        destination="themeService"  
        endpoint= "messagebroker/amf" 
        showBusyCursor="true" 
        requestTimeout="100"
        />

    <mx:RemoteObject 
        id="dataService"        
        destination="dataService"  
        endpoint= "messagebroker/amf" 
        showBusyCursor="true" 
        requestTimeout="100"
        />

    <mx:RemoteObject 
        id="userService"        
        destination="userService"  
        endpoint= "messagebroker/amf" 
        showBusyCursor="true" 
        requestTimeout="100"
        />

</rds:ServiceLocator>

所以,好吧...我想我已经找到了 Java 后端服务端点的定义位置。

但是...Java 后端 URL 是在哪里定义的?!?!

检查之前的 MyAppServices.mxml 文件的代码,我可以看到包含此​​部分:

<mx:Script>
    <![CDATA[
        import org.myOrganization.myApp.util.ConfigServer;
    ]]>
</mx:Script>

这应该将 ActionScript 代码导入到 org.myOrganization.myApp.util.ConfigServer 文件中。

所以,在我的项目中,我找到了这个文件:org.myOrganization.myApp.util.ConfigServer.as

如您所见,路径相同,但项目中的文件具有 .as 扩展名。是自动添加的吗?

所以这个文件的代码是:

package org.myOrganization.myApp.util {
    import flash.events.HTTPStatusEvent;
    import flash.events.IOErrorEvent;
    import flash.events.ProgressEvent;
    import flash.events.SecurityErrorEvent;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLVariables;

    import mx.collections.ArrayCollection;
    import mx.core.Application;
    import mx.managers.BrowserManager;
    import mx.managers.IBrowserManager;
    import mx.utils.URLUtil;

    import org.osmf.utils.URL;

    public class ConfigServer {

        // settings
        public static var BIRT_URL:String;
        public static var GEOSERVER_URL:String;
        public static var GEOSERVER_BASELAYER_URL:String;
        public static var APP_CONTEXT:String;
        public static var CAF_SERVER_URL:String;
        public static var CAF_REGISTER_URL:String;

        public static var CAF_FACEBOOK_LOGIN_URL:String;
        public static var CAF_GOOGLE_LOGIN_URL:String;
        public static var CAF_TWITTER_LOGIN_URL:String;

        public static var CAF_FACEBOOK_REGISTER_URL:String;
        public static var CAF_GOOGLE_REGISTER_URL:String;
        public static var CAF_TWITTER_REGISTER_URL:String;

        public static var CAF_FACEBOOK_LOGIN_ENABLED:Boolean;
        public static var CAF_GOOGLE_LOGIN_ENABLED:Boolean;
        public static var CAF_TWITTER_LOGIN_ENABLED:Boolean;

        public static var CAF_FACEBOOK_REGISTER_ENABLED:Boolean;
        public static var CAF_GOOGLE_REGISTER_ENABLED:Boolean;
        public static var CAF_TWITTER_REGISTER_ENABLED:Boolean;

        //operations
        public static var LIST_BYID:String = "listById";
        public static var RESOURCES_NUMBER = "resourceNumber";
        public static var LIST_OPERATION:String = "list";
        public static var GET_OBJECT:String = "getObject";
        public static var ADD_OPERATION:String = "add";
        public static var DELETE_OPERATION:String = "delete";
        public static var UPDATE_OPERATION:String = "update";
        public static var REPORT_OPERATION = "report";
        public static var GET_BYID:String = "getById";
        public static var LIST_UPDATE_OPERATION:String = "listUpdate";  
        public static var APP_SETTINGS = "appSettings";     


        [Bindable]
        public static var VARIABLES_URL:String = "prop.properties";

        [Bindable]
        public static var arrColl:ArrayCollection;

        [Bindable]
        public static var paramColl:ArrayCollection;

        public static var urlReq:URLRequest;
        public static var urlLdr:URLLoader;

        public static function init():void {
            /* Initialize the two ArrayCollections objects with empty arrays. */
            arrColl = new ArrayCollection();
            paramColl = new ArrayCollection();

            /* Initialize the URLRequest object with the URL to the file of name/value pairs. */
            urlReq = new URLRequest(VARIABLES_URL);

            /* Initialize the URLLoader object, assign the various event listeners, and load the specified URLRequest object. */
            urlLdr = new URLLoader();
            urlLdr.addEventListener(Event.COMPLETE, doEvent);
            urlLdr.addEventListener(Event.OPEN, doEvent);
            urlLdr.addEventListener(HTTPStatusEvent.HTTP_STATUS, doEvent);
            urlLdr.addEventListener(IOErrorEvent.IO_ERROR, doEvent);
            urlLdr.addEventListener(ProgressEvent.PROGRESS, doEvent);
            urlLdr.addEventListener(SecurityErrorEvent.SECURITY_ERROR, doEvent);
            urlLdr.load(urlReq);
        }

        public static function doEvent(evt:Event):void {
            arrColl.addItem({type:evt.type, idx:arrColl.length+1, eventString:evt.toString()});

            switch (evt.type) {
                case Event.COMPLETE:
                    /* If the load was successful, create a URLVariables object from the URLLoader.data property and populate the paramColl ArrayCollection object. */
                    var ldr:URLLoader = evt.currentTarget as URLLoader;
                    var vars:URLVariables = new URLVariables(ldr.data);
                    var key:String;

                    for (key in vars) {
                        paramColl.addItem({key:key, value:vars[key]});
                    }

                    //params.visible = true;
                    break;
            }
        }



//      public static function getCurrentUrl():String {
//          var browserManager:IBrowserManager = BrowserManager.getInstance();
//          
//          var url:String = browserManager.url;
//          var result : String = url;       
//          if ( url && ( url.indexOf("file:/") == -1 ) )       
//          {          
//              //result = mx.utils.URLUtil.getFullURL(url, url);
//              result = mx.utils.URLUtil.getProtocol(url)+ "://" +mx.utils.URLUtil.getServerNameWithPort(url);
//
//          }       
//          return result;
//      }
//      
//      [Bindable] 
//      public static var properties:Object = new Object(); 
//      private static var loadedProps:Properties = new Properties();   
//      private function init():void {    
//          loadedProps.addEventListener(Event.COMPLETE, onLoaderComplete);     
//          loadedProps.addEventListener(IOErrorEvent.IO_ERROR, onIOError);     
//          loadedProps.load("prop.properties");
//          loadedProps.s
//      }   
//      
//      private function onLoaderComplete(event:Event):void {     
//          properties.host = loadedProps.getProperty("host");     
//          properties.port = loadedProps.getProperty("port");     
//          properties.webcontext = loadedProps.getProperty("context-root"); 
//      }
    }       
}

但在这里我也找不到我的服务器定义。

在这段代码中有:

[Bindable]
public static var VARIABLES_URL:String = "prop.properties";

我认为它会将 prop.properties 文件的内容导出到 VARIABLES_URL 变量中(我完全不确定这种行为),但我没有 prop.properties strong>prop.properties 文件到我的项目中。

您是否知道在此 Flex 项目中定义后端端点 URL 的位置?或者至少有一些关于如何搜索的提示?

【问题讨论】:

    标签: actionscript-3 apache-flex flex4 flex4.5 mxml


    【解决方案1】:

    它可能包含在您的 services-config.xml 文件中。检查你的编译器选项,看看是否有 -services=path/to/your/services-config.xml。

    这里有更多信息。 http://www.adobe.com/devnet/livecycle/articles/externalize_serviceconfig.html

    【讨论】: