Quantcast
Channel: VMware Communities : Discussion List - vSphere Client SDK
Viewing all articles
Browse latest Browse all 2218

Important note for proxy class future compatibility

$
0
0

If your Flex plugin defines its own proxy class to call a java service you should avoid hardcoding the CHANNEL_URI with "amfsecure" the way it is done here:

 

// Globalview sample with CHANNEL_URI hard-coded to amfsecure

public class EchoServiceProxy extends BaseProxy {

  ...

  private static const CHANNEL_URI:String =

         "/" + GlobalviewModule.contextPath + "/messagebroker/amfsecure";

 

This works fine with WebClient 5.5.x but will break with the 2015 release because the web client will be behind a reverse proxy and use http for service calls.

To ensure binary compatibility of your plugin between 5.5.x and the 2015 release the solution is to use a new method ServiceUtil.getDefaultChannelUri defined below.

 

For example here is how EchoServiceProxy must be changed:

 

public class EchoServiceProxy extends BaseProxy {

   private static const SERVICE_NAME:String = "EchoService";

 

   public function EchoServiceProxy() {

      // channelUri uses the Web-ContextPath defined in MANIFEST.MF

      const channelUri:String = ServiceUtil.getDefaultChannelUri(GlobalviewModule.contextPath);

      super(SERVICE_NAME, channelUri);

   }

}

 

And here is the ServiceUtil code to add to your own plugin:

(another solution is to upgrade to SDK 5.5.2 which includes ServiceUtil in its API)

 

package com.vmware.samples.globalview {    <== change to your plugin package

 

import mx.core.FlexGlobals;

import mx.utils.URLUtil;

 

public class ServiceUtil {

 

   private static const DEFAULT_CHANNEL_URI:String = "messagebroker/amf";

   private static const DEFAULT_SECURE_CHANNEL_URI:String = "messagebroker/amfsecure";

 

   private static var _defaultSecure:Boolean =

            URLUtil.isHttpsURL(FlexGlobals.topLevelApplication.url);

 

   /**

    * Return the default channel uri to use for a given context path.

    * Use this method when extending BaseProxy instead of hard-coding the channel uri

    * in order to ensure binary compatibility with future Web Client versions.

    *

    * For example, given the context "vsphere-client/chassis-ui", this returns

    * "/vsphere-client/chassis-ui/messagebroker/amfsecure" or

    * "/vsphere-client/chassis-ui/messagebroker/amf" depending on whether a secure

    * channel is required.

    *

    * @param contextPath

    *    Application's web context path (defined in bundle MANIFEST.MF)

    */

   public static function getDefaultChannelUri(contextPath:String):String {

 

      // Disable the secure communication when the client is behind a proxy

      var isSecure:Boolean = URLUtil.getPort(FlexGlobals.topLevelApplication.url) ?

            _defaultSecure : false;

      var channelUri:String = (isSecure) ? DEFAULT_SECURE_CHANNEL_URI : DEFAULT_CHANNEL_URI;

 

      if (URLUtil.isHttpURL(contextPath)) {

         return URLUtil.getFullURL(contextPath, channelUri)

      } else {

         if (contextPath.charAt(0) != "/") {

            contextPath = "/" + contextPath;

         }

         if (contextPath.charAt(contextPath.length-1) != "/") {

            contextPath = contextPath + "/";

         }

         return (contextPath + channelUri);

      }

   }

}

}


Viewing all articles
Browse latest Browse all 2218

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>