Announcement Announcement Module
Collapse
No announcement yet.
Externalizing a channel URL Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Externalizing a channel URL

    I'm currently writing a tutorial series about how to integrate Grails and Flex. First episodes are here and there.

    In the second episode, I have to configure the channelSet of my RemoteObject inside MXML in order to reference it for authentication purposes:

    Code:
    <services:TodoListService id="todoListService" 
    			fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" 
    			showBusyCursor="true">
    			<services:channelSet>
    				<s:ChannelSet id="channelSet">
    					<s:AMFChannel url="http://localhost:8080/todolist/messagebroker/amf"/>
    				</s:ChannelSet>
    			</services:channelSet>
    		</services:TodoListService>
    But of course, the problem with that approach is that I'm hardcoding the URL of my AMFChannel, which makes it hard to have several build configurations with different URL's for each target environment.

    I figured Spring Actionscript could help me with that by allowing me to configure this URL in an XML or properties file so that I can choose which configuration to choose depending on the environment.

    Is my assumption right? How should I proceed?

  • #2
    correct

    Hey Sebastien,

    you are indeed correct in your assumptions

    Check this doc section out for channel configurations:

    http://www.springactionscript.org/do..._configuration

    And here is some information on externalizing properties:

    http://www.springactionscript.org/do...property_files

    Good luck with your article and if you need any more help or advice, please feel free to ask us at any time.

    cheers,

    Roland

    Comment


    • #3
      I'm trying to figure out how to make this work. Here is what I did so far:
      - I created an application-context.xml file with the following content:

      Code:
      <objects>
          <object id="amfChannel" class="mx.messaging.channels.AMFChannel" scope="singleton">
              <constructor-arg value="my-amf"/>
              <constructor-arg value="http://{server.name}:{server.port}/todolist/"/>
              <property name="id" value="amfChannel"/>
              <property name="pollingEnabled" value="false"/>
          </object>
      
          <object id="channelset" class="mx.messaging.ChannelSet" scope="singleton">
              <method-invocation name="addChannel">
                  <arg>
                      <ref>amfChannel</ref>
                  </arg>
              </method-invocation>
          </object>
      </objects>
      - I added a ContextURL flashvar in my html template:

      Code:
      <script type="text/javascript">
                  <!-- For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. -->
                  var swfVersionStr = "10.0.0";
                  <!-- To use express install, set to playerProductInstall.swf, otherwise the empty string. -->
                  var xiSwfUrlStr = "playerProductInstall.swf";
                  var flashvars = {ContextURL:"application-context.xml"};
                  var params = {};
                  params.quality = "high";
                  params.bgcolor = "#ffffff";
                  params.allowscriptaccess = "sameDomain";
                  params.allowfullscreen = "true";
                  var attributes = {};
                  attributes.id = "Main";
                  attributes.name = "Main";
                  attributes.align = "middle";
                  swfobject.embedSWF(
                      "Main.swf", "flashContent",
                      "100%", "100%",
                      swfVersionStr, xiSwfUrlStr,
                      flashvars, params, attributes);
      			<!-- JavaScript enabled so display the flashContent div in case it is not replaced with a swf object. -->
      			swfobject.createCSS("#flashContent", "display:block;text-align:left;");
              </script>
      - Then in my MXML application, I added a couple of event handlers:

      Code:
      protected function preinitializeHandler(event:FlexEvent):void
      			{
      				_contextURL = parameters['ContextURL'];
      			}
      
      
      			protected function applicationCompleteHandler(event:FlexEvent):void
      			{
      				var applicationContext:XMLApplicationContext = new XMLApplicationContext();
      				applicationContext.addConfigLocation(_contextURL);
      				applicationContext.addEventListener(Event.COMPLETE, contextLoadedHandler);
      				applicationContext.load();
      			}
      			
      			protected function contextLoadedHandler(event:Event):void{
      				todoListService.channelSet = (event.target as XMLApplicationContext).getObject("channelset");
      				reloadTasks();
      			}
      So basically, my application-context.xml is correctly located thanks to the flashvar. Then my application context is correctly loaded and 2 beans are initialized. Then my todoListService is successfully assigned a channelSet (or at least I don't get any error message telling me otherwise). But then when reloadTasks() runs, which calls my data service to load data for the first time, I get an error saying:

      Code:
      Send failed
      Channel.Connect.Failed error NetConnection.Call.BadVersion: : url: 'http://localhost:8080/todolist/'
      Any idea what the problem might be?

      Comment


      • #4
        I found my mistake. The URL of my AMF endpoint was wrong.

        Comment

        Working...
        X