vendredi 20 janvier 2017

How this Flex front end application is connected to my back end application? Where the mx:RemoteObject URL endpoint URL are defined?

I am absolutly new in Flex.

I am working on an old (made by someone else) application that have the following architecture: a Flex front end that receive data from a Java back end application.

I am desperately trying to understand how the front end is connected to the front end (I have to deploy this application so I need to change the back end pointer into the Flex front end application).

Into my FLEX front ent I have found this MyAppServices.mxml file containing some tag that should represent HTTPService object in an MXML file.

Reading the official doccumentation:

This tag gives you access to the methods of Java objects using Action Message Format (AMF) encoding.

So it should be the pointer to my back end services:

<?xml version="1.0" encoding="utf-8"?>
<rds:ServiceLocator 
    xmlns:mx="http://ift.tt/1aBfKeP" 
    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>

So, ok...I think that I have found where the Java back end service endpoint are defined.

But...where are defined the Java back end URL ?!?!

Examining the code of the previous MyAppServices.mxml file I can see that contains this section:

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

That should import the ActionScript code contained into the org.myOrganization.myApp.util.ConfigServer file.

So, in my project I have found this file: org.myOrganization.myApp.util.ConfigServer.as

As you can see the path is the same but the file present in the project have the .as extension. Is it automatically added?

So the code of thi file is:

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"); 
//      }
    }       
}

But also here I can't find my server definition.

Into this code there is:

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

I thoungt that it export the content of a prop.properties file into a VARIABLES_URL variable (I am absolutly not sure about this behavior) but I have not a prop.properties file into my project.

Do you have some idea about where the back end endpoint URL are defined into this Flex project? Or at least some hints about how to search it?

Aucun commentaire:

Enregistrer un commentaire