| « Solved: change username in IntelliJ IDEA on Mac | Flash GAMM Ukraine » |
Dynamically loaded BlazeDS configuration in Flex applications
For people who wants to use server configuration (I mean channels, endpoints and remoting destinations from BlazeDs/LCDS services-config.xml and remoting-config.xml) loaded in runtime instead of common practice with reading configs in compile time Cristophe Coenraets wrote a dedicated post. As for me it is very annoying to configure every single RemoteObject that way ![]()
Today I’ve discussed that problem with my college Benjamin Dobler and finally we’ve found a solution how to apply dynamically loaded config on a global level within Flex client.
The solution is pretty simple and rely on mx.messaging.config.ServerConfig class. The key part of documentation is:
This class provides access to the server messaging configuration information. This class encapsulates information from the services-config.xml file on the client and is used by the messaging system to provide configured ChannelSets and Channels to the messaging framework.
The XML source is provided during the compilation process. However, there is currently no internal restriction preventing the acquisition of this XML data by other means, such as network, local file system, or shared object at runtime.
So it is very convenient and legal way to solve our problem. But the main difficulty is the format of XML. Further investigations gave us the format:
XML:
<services> | |
<service id="remoting-service"> | |
<destination id="serviceOne"> | |
<channels> | |
<channel ref="channel-amf"/> | |
</channels> | |
</destination> | |
<destination id="serviceTwo"> | |
<channels> | |
<channel ref="channel-amf"/> | |
</channels> | |
</destination> | |
</service> | |
<channels> | |
<channel id="channel-amf" type="mx.messaging.channels.AMFChannel"> | |
<endpoint uri="http://example.com/foo/messagebroker/amf"/> | |
<properties> | |
<polling-enabled> | |
false | |
</polling-enabled> | |
</properties> | |
</channel> | |
</channels> | |
</services> |
That’s all! Finally all you need is to assign your loaded XML to the appropriate property:
- ServerConfig.xml = myXML
Now you can use your services without any problem. They will be configured on a client globally as if were injected on compile time.
Trackback address for this post
Trackback URL (right click and copy shortcut/link location)
3 comments, 1 trackback
Nice. For further reference, here is how mxmlc turns the services-config.xml into the ServerConfig.xml format. The problem
It is very often if we need to parametrize some options in services-config.xml of our Flex project to insert values depending on build process target. Let me explain it by example.
Imagine we have an application which use both secured a...
Oh cool! Thank you Maciek!
Thanks for posting this! Works great!