3 Replies Latest reply on Dec 17, 2009 2:04 AM by jjanakiraman

    Runtime configuation of services

    agorman_co

      I have two interdependat applications that I have inherited froma developer that has since left the company.

       

      appA can launch appB as either an enbedded app using a SWFLoader or as a seperate app using navigateToURL.

       

      These applications have been working fine when thay are compiled usig a services-config-xml file. I am trying to get away from compile-time endpoints. I now specify my service configuration at run-time and have mixed results:

       

      1) appA works fine

      2) appB works when launched via SWFLoader

      3) appB DOES NOT work when launched as a seperate app via navigateToURL

       

      As a seperate app appB gets an error when sending a request:

      [MessagingError message='The channel class 'mx.messaging.channels.AMFChannel' specified was not found.']

       

      I generated link reports for both applications with and without services-config-xml specified at compile-time. I see this reference to AMFChannel

       

          <script name="/Users/gorman/Documents/EclipseWorkspace/lib/FlexBuilder/sdks/3.1.0/frameworks/libs /DAI-search.swc(mx/messaging/channels/AMFChannel)" mod="1214927763274" size="6724" optimizedsize="4093">
            <def id="mx.messaging.channels:AMFChannel" />
            <pre id="mx.messaging:MessageResponder" />
            <pre id="mx.messaging.channels:NetConnectionChannel" />
            <dep id="mx.resources:IResourceManager" />
            <dep id="mx.messaging.events:ChannelFaultEvent" />
            <dep id="mx.core:mx_internal" />
            <dep id="mx.messaging.messages:CommandMessage" />
            <dep id="mx.utils:ObjectUtil" />
            <dep id="mx.logging:Log" />
            <dep id="mx.resources:ResourceManager" />
            <dep id="mx.messaging.config:ConfigMap" />
            <dep id="AS3" />
            <dep id="mx.messaging:FlexClient" />
            <dep id="flash.events:IOErrorEvent" />
            <dep id="flash.net:Responder" />
            <dep id="flash.events:SecurityErrorEvent" />
            <dep id="mx.messaging.messages:AbstractMessage" />
            <dep id="en_US$messaging_properties" />
            <dep id="XML" />
            <dep id="mx.messaging.messages:IMessage" />
            <dep id="mx.messaging.config:ServerConfig" />
            <dep id="flash.events:NetStatusEvent" />
            <dep id="mx.messaging.messages:ErrorMessage" />
          </script>

       

      I see this in the link report for appA whether or not services-config-xml is specified during compile. However, I only see this for appB  when services-config-xml is specified.

       

      Does anyone have any theories about why mx.messaging.channels.AMFChannel is available in one app, but not the other. I have combed through all my code and configuration files. I can't  identify any noticible significant difference between the apps.

       

      The approach I use to configure services at run time is simplistic. When I have the application compiled with the services-config-xml file, I trace the ServerConfig.xml property, which shows this:

       

      <services>
        <service id="remoting-service">
          <destination id="dai-groupingList">
            <channels>
              <channel ref="my-amf"/>
            </channels>
          </destination>
          <destination id="dai-popups-network">
            <channels>
              <channel ref="my-amf"/>
            </channels>
          </destination>
          <destination id="dai-monumentation">
            <channels>
              <channel ref="my-amf"/>
            </channels>
          </destination>
          <destination id="dai-archivedfiles">
            <channels>
              <channel ref="my-amf"/>
            </channels>
          </destination>
          <destination id="dai-popups-operational">
            <channels>
              <channel ref="my-amf"/>
            </channels>
          </destination>
          <destination id="dai-popupsname">
            <channels>
              <channel ref="my-amf"/>
            </channels>
          </destination>
          <destination id="dai-campaigns">
            <channels>
              <channel ref="my-amf"/>
            </channels>
          </destination>
          <destination id="dai-monuments">
            <channels>
              <channel ref="my-amf"/>
            </channels>
          </destination>
          <destination id="dai-popups-monumentstyle">
            <channels>
              <channel ref="my-amf"/>
            </channels>
          </destination>
          <destination id="dai-timecodes">
            <channels>
              <channel ref="my-amf"/>
            </channels>
          </destination>
          <destination id="dai-funding">
            <channels>
              <channel ref="my-amf"/>
            </channels>
          </destination>
          <destination id="dai-contact">
            <channels>
              <channel ref="my-amf"/>
            </channels>
          </destination>
          <destination id="dai-qc">
            <channels>
              <channel ref="my-amf"/>
            </channels>
          </destination>
        </service>
        <channels>
          <channel id="my-amf" type="mx.messaging.channels.AMFChannel">
            <endpoint uri="http://facility.unavco.org:9090/blazeds/messagebroker/amf"/>
            <properties/>
          </channel>
          <channel id="my-polling-amf" type="mx.messaging.channels.AMFChannel">
            <endpoint uri="http://facility.unavco.org:9090/blazeds/messagebroker/amfpolling"/>
            <properties>
              <polling-enabled>true</polling-enabled>
              <polling-interval-seconds>4</polling-interval-seconds>
            </properties>
          </channel>
          <channel id="my-secure-amf" type="mx.messaging.channels.SecureAMFChannel">
            <endpoint uri="https://facility.unavco.org:9090/blazeds/messagebroker/amfsecure"/>
            <properties/>
          </channel>
        </channels>
      </services>

       

      Now I simply compile without services-config-xml, read the above xml structure into the app at startup and assign it to the ServerConfig.xml property. As I said above. This works in one app, but not the other becuse for some reason mx.messaging.channels.AMFChannel is available in one and not the other. Furthermore, I find not explicit reference to mx.messaging.channels.AMFChannel in either application, but there is a reference to it in the link reports (for appA in all cases and in appB only when I specify services-config-xml).

       

      Any thought??? This has bee driving me crazy!

        • 1. Re: Runtime configuation of services
          jjanakiraman

          I am also running into the same issue.  Did you find any workaround for this issue?

          • 2. Re: Runtime configuation of services
            agorman_co Level 1

            I have not understood why it did not work, but I did develop a work around. Really what I was going for was a way to override the default production endpoints by reading in a config file at runtime. To overcome the problem I posted I continue to compile my apps with the services-config-xml specified. In addition, I read a config file at runtime and if there is a services entry in the xml file, I assign it to the ServerConfig.xml property.

             

            This works, but there is one caveat: you need to make the assignment to alter the ServerConfig object in both the parent and child app. It is a singleton and while my custom singleton classes are shared between parent and child, the ServerConfig object is not. I read the service xml structure in when the app starts up, store it in a singleton resouce class that I created and then  assign it ti the xml property of the ServerConfig object in both parent and child app.

             

            Hope this helps. If you come across anything else, let me know.

             

            Andy

            • 3. Re: Runtime configuation of services
              jjanakiraman Level 1

              Thanks Andy.

               

              I tried this work-around today and it seems to work.  Not sure if this is the best solution.

               

              In this case, both parent and child apps are NOT compiled using services-config.xml.

               

              Instead, the remote object is initialized within the application itself by specifying channel sets as below:

               

              <mx:ChannelSet id="my_channels">
                  <mx:AMFChannel id="my_amf_channel" uri="http://my-remote-object-url/"/>
              </mx:ChannelSet>

               

              <mx:RemoteObject id="amfService"
                  destination="pojo"
                  channelSet="{my_channels}">
              </mx:RemoteObject>

               

              In this way, I don't get this error (The channel class mx.messaging.channels.AMFChannel specified was not found) while loading child from parent:

               

              Remote calls go through fine, both as stand-alone and embedded applications.


              I am yet to resolve the hard-coding that this work-around introduces.

               

              Probably, I should try your approach along with this work-around.

               

              Thanks and Regards,

              Jagath