Friday, August 28, 2009

Configure Flex To Use Either AMF or AMF-SECURE

How To Configure Flex To Use Either AMF or AMF-SECURE

I needed to develop a Flex application on my desktop and test using Tomcat 6 out of the box, without a certificate installed for HTTPS. However I need to deploy that application to a test and production server that force the use of HTTPS.

There is no good documentation on the web explaining how you can do this. It's not difficult. I'm writing this to save you the trial and error process I went through.

#1. In your services-config.xml file you need the following entries to define your amf and amf-secure channels. The trick here is that we make these polling so that the system will be able to switch to the other channel if the first one it tries fails, given that you follow the instructions in Step 2:


<channel-definition id=\"my-secure-amf\" class=\"mx.messaging.channels.SecureAMFChannel\">
<endpoint url=\"https://{server.name}:{server.port}/{context.root}/messagebroker/amfsecure\" class=\"flex.messaging.endpoints.SecureAMFEndpoint\"/>
<properties>
<add-no-cache-headers>false</add-no-cache-headers>
<polling-enabled>true</polling-enabled>
<polling-interval-millis>0</polling-interval-millis>
<wait-interval-millis>-1</wait-interval-millis>
<max-waiting-poll-requests>0</max-waiting-poll-requests>
</properties>
</channel-definition>

<channel-definition id=\"my-amf\" class=\"mx.messaging.channels.AMFChannel\">
<endpoint url=\"http://{server.name}:{server.port}/{context.root}/messagebroker/amf\" class=\"flex.messaging.endpoints.AMFEndpoint\"/>
<properties>
<add-no-cache-headers>false</add-no-cache-headers>
<polling-enabled>true</polling-enabled>
<polling-interval-millis>0</polling-interval-millis>
<wait-interval-millis>-1</wait-interval-millis>
<max-waiting-poll-requests>0</max-waiting-poll-requests>
</properties>
</channel-definition>


#2. In your remoting-config.xml and your proxy-config.xml files define the following. The trick here is that you are defining two channels for use. If one fails the system will try the next.





That's it! As soon as I made the above changes I was able to build and deploy my Flex application to EITHER an https configured server OR and http configured server.

2 comments:

J said...

Hi!

Thanks for the info, I did exactly as you put on the example but I keep receiving:


faultCode = "Client.Error.MessageSend"
faultDetail = "Channel.Security.Error error Error #2048: Security sandbox violation: https://myserver.com/Leaps.swf cannot load data from http://localhost:8081//messagebroker/amf. url: 'http://localhost:8081//messagebroker/amf'"
faultString = "Send failed"
message = "faultCode:Client.Error.MessageSend faultString:'Send failed' faultDetail:'Channel.Security.Error error Error #2048: Security sandbox violation: https://myserver.com/Leaps.swf cannot load data from http://localhost:8081//messagebroker/amf. url: 'http://localhost:8081//messagebroker/amf''"
name = "Error"

Any ideas ?

Thanks!

Mark Bykerk Kauffman said...

Hi J - Looks like you have a mix of https and http urls. https://myserver.com/Leaps.swf is trying to talk to http://localhost:8081//messagebroker/amf it needs to talk to https:. Drop the default-channels portion of your remoting-config.xml and the channel-definitions portion of your services-config.xml here and I'll take a look at them. Sorry for the delay in a reply.