Quick solution for Flex deployment with SSL Accelerators / Proxies

Once you developed and tested Flex application locally you need to move it to the secured hosting environment to share it with the world. Usually, for simplicity/performance enterprises deploy J2EE servers behind standalone SSL accelerators/load balancers/proxies. It means that client sends data via SSL channel to SSL appliance, which in turn calls your server on the  intranet via unsecured HTTP to minimize the processing cost.
You can configure the channel/endpoint in services-config.xml, but it would mean separate build for deployment. Here is an alternative “runtime” approcah:

 

  1. import mx.messaging.config.ServerConfig;
  2. private function preinitializeApplication() : void {
  3. const reUrl:RegExp = /(http|https):(([^:]+)(:([^@]+))?@)?([^://]+)(:([0-9]{2,5}))?(//([/w#!:.?+=&%@!/-//]+))?/;
  4. const appUrl:String = Application.application.url;
  5. const parts:Array = reUrl.exec(appUrl);
  6. if (!parts)
  7. throw new Error(”Invalid URL: ” + appUrl);
  8. /*
  9. (”Protocol:” + parts[1]);
  10. (”User: ” + parts[3]);
  11. (”Pass: ” + parts[5]);
  12. (”Host: ” + parts[6]);
  13. (”Port: ” + parts[8]);
  14. (”Path: ” + parts[10]);
  15. */
  16. if (parts[1] == “https” ) {
  17. const channels:XMLList = ServerConfig.xml..channels.channel;
  18. for (var channel:String in channels) {
  19. if (channels[channel].@type==”mx.messaging.channels.AMFChannel”) {
  20. channels[channel].@type=”mx.messaging.channels.SecureAMFChannel”
  21. var endpoint : XML = channels[channel].endpoint[0];
  22. var uri:String = endpoint.@uri
  23. uri = uri.replace( /^http:/, “https:” );
  24. uri = uri.replace( //{server.port/}/, “443″ );
  25. endpoint.@uri = uri;
  26. }
  27. }
  28. }
  29. }

 

As you can see, we check if the application is deployed over https and redirect regular remoting requests to https thus modifying deployment descriptors in the runtime.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值