6 Replies Latest reply on Sep 15, 2010 10:12 AM by hdave123

    How to configure channels with Spring-Flex?


      Newbie here trying to get my first Flex/BlazeDS app up and running.   I'm using the Spring-Flex integration and believe I have properly configured my servet and remoting destinations.  My only remaining questions relate to how to configure the channels.


      The use of the Spring/BlazeDS integration means that I do not have to have a remoting-config.xml file anymore.  But it the documentation is unclear as to whether I need to configure my channels within a services-config.xml file still.


      If I do need a services-config.xml file (and I think I do), how does one get away without hard coding the server URL?  I've seen samples on the web like:



      But I don't get when/where/what does the dynamic substituion?  They almost look like Maven or Spring properties, but they can't be.  Is this just something that has to be manually changed after installation?



      Finally, I really don't like the idea of compiling the Flex client against a server-side configuration file as I have seen suggested on the web.  How would one go about have the Flex client discover - or otherwise figure out what it needs to do dynamically?


      Sorry for the multi-question post....thanks for any help!

        • 1. Re: How to configure channels with Spring-Flex?
          Mike Peterson Level 1

          You do need to configure a channel set, but you have the option of doing that in your Flex client code rather than in the services-config.xml file. Here's some information on some ways to do that:


          http://help.adobe.com/en_US/LiveCycleDataServicesES/3.1/Developing/WSc3ff6d0ea77859461172e 0811f00f6e876-7fecUpdate.html#WSc3ff6d0ea77859461172e0811f00f6e876-7fdbUpdate


          Look at the section called "Configuring channels on the client".


          Regarding the tokens in the channel definitions in services-config.xml:

          {server.name} and {server.port} get resolved at runtime to the server and port used to load the SWF file.

          • 2. Re: How to configure channels with Spring-Flex?
            hdave123 Level 1

            Thanks for the help!  Are you saying that the service-config.xml file in the WEB-INF/flex directory was only ever for the client to compile with?  How does the server "know" what channels to "listen" on?


            Perhaps I am missing something important here about how all this works.  I thought that AMF binary worked over an AMF channel and that it had to be "set up" on the server and the client both.

            • 3. Re: How to configure channels with Spring-Flex?
              Mike Peterson Level 1

              Good question. You do still need to have an endpoint configured on the server in the services-config.xml file:


              "When you create and assign a channel set on the client, the client requires the correct channel type and endpoint URL to contact the server. The client does not specify the endpoint class that handles that request, but there must be a channel definition in the services-config.xml file that specifies the endpoint class to use with the specified endpoint URL."

              1 person found this helpful
              • 4. Re: How to configure channels with Spring-Flex?
                hdave123 Level 1

                OK - to summarize:


                1) you must have a service-config.xml in the WEB-INF/flex directory


                2) you can create your channel set and channels on the client in mxml and actionscript and not compile against the server's service-config.xml


                3) they need to line up correctly


                This is all cool and I found sample code in the documentation to make the channels in actionscript.  I guess the remaining question is how best to leave the URL specific stuff (server name, server port, and context) out of the source code of the flex client.   I guess I could load an XML file that my clients could edit....

                • 5. Re: How to configure channels with Spring-Flex?
                  Mike Peterson Level 1

                  You could load that info from an XML file as described below. I took this from the doc.


                  To further externalize configuration, you can pass the endpoint URL value to the client at runtime. One way to do this is by reading a configuration file with an HTTPService component at application startup. The configuration file includes the information to programmatically create a channel set at runtime. You can use E4X syntax to get information from the configuration file.

                  The following MXML application shows this configuration file technique:



                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                      import mx.controls.Alert;
                      import mx.messaging.channels.AMFChannel;
                      import mx.messaging.ChannelSet;
                      import mx.rpc.events.ResultEvent;
                      private var channelSet:ChannelSet;
                      private function configResultHandler(event:ResultEvent):void
                          var xml:XML = event.result as XML;
                          var amfEndpoint:String = "" + xml..channel.(@id=="amf").@endpoint;
                          if (amfEndpoint == "")
                              Alert.show("amf channel not configured", "Error");
                              channelSet = new ChannelSet();
                              var channel:AMFChannel = new AMFChannel("my-amf", amfEndpoint);
                              ro.channelSet = channelSet;
                      <mx:HTTPService id="configSrv" url="config.xml" resultFormat="e4x" result="configResultHandler(event)"/>
                      <mx:RemoteObject id="ro" destination="product"/>
                      <mx:DataGrid dataProvider="{ro.getProducts.lastResult}" width="100%" height="100%"/>



                  The MXML application reads the following configuration file:


                  <?xml version="1.0" encoding="utf-8"?>
                          <channel id="amf" endpoint="http://localhost:8400/lcds-samples/messagebroker/amf"/>

                  1 person found this helpful
                  • 6. Re: How to configure channels with Spring-Flex?
                    hdave123 Level 1

                    I like the idea of loading in config properties from an XML file, but I am still looking for a while to externalize the server information without

                    requiring any changes to config files.  That is, I am trying to keep it such that clients, etc. can just drop in the WAR file and go.


                    I found this snippet of code which returns the name of the server from which the SWF file was served:




                    There are always way to get the port number and determine if it was SSL or not.  With this I feel I can hard-code the port 80 (443) and the context and voila -- I have a completely solution for run-time configuration of channel sets without compiling against services-config.xml or hard coding the server URL anywhere.


                    I'll report back if I doesn't work....