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:
url="https://\{server.name\}:\{server.port\}/flex2gateway/cfamfsecure"
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!
Solved! Go to Solution.
Views
Replies
Total Likes
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:
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.
Views
Replies
Total Likes
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:
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.
Views
Replies
Total Likes
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.
Views
Replies
Total Likes
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."
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....
Views
Replies
Total Likes
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"
applicationComplete="configSrv.send()">
<mx:Script>
<![CDATA[
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");
}
else
{
channelSet = new ChannelSet();
var channel:AMFChannel = new AMFChannel("my-amf", amfEndpoint);
channelSet.addChannel(channel);
ro.channelSet = channelSet;
ro.getProducts();
}
}
]]>
</mx:Script>
<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%"/>
</mx:Application>
The MXML application reads the following configuration file:
<?xml version="1.0" encoding="utf-8"?>
<config>
<channels>
<channel id="amf" endpoint="http://localhost:8400/lcds-samples/messagebroker/amf"/>
</channels>
</config>
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:
URLUtil.getServerName(FlexGlobals.topLevelApplication.url)
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....
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies