Using the CustomExtensionInterfaceFinder Object

The CustomExtensionInterfaceFinder object allows you to find registered CustomExtensionInterfaceBinding objects. The methods in CustomExtensionInterfaceBinding objects are called by the Policy Manager and then executed on the gateway. To avoid serialization, class loader, and security manager problems with third-party classes, only Primitives, Strings, Primitive Arrays, and String Arrays can be passed and returned from methods. HashMap<String, String> can also be returned from methods, which can be useful for returning display text to the UI.
gateway92
The
CustomExtensionInterfaceFinder
object allows you to find registered
CustomExtensionInterfaceBinding
objects. The methods in
CustomExtensionInterfaceBinding
objects are called by the Policy Manager and then executed on the
Layer7 API Gateway
. To avoid serialization, class loader, and security manager problems with third-party classes, only Primitives, Strings, Primitive Arrays, and String Arrays can be passed and returned from methods.
HashMap<String, String>
can also be returned from methods, which can be useful for returning display text to the UI.
The following sample codes illustrate how the
CustomExtensionInterfaceBinding
and
CustomExtensionInterfaceFinder
features might be used to execute code on the Gateway from the Policy Manager:
  1. Create an interface with methods that are executed in the Gateway.
    public interface SalesForceCustomExtensionInterface { @Transactional(readOnly=true) String[] describeGlobal(String connectionKey) throws Exception; @Transactional(readOnly=true) boolean testConnection(String userName, String passwordId, String securityTokenId) throws Exception; }
  2. Create a class that extends
    CustomExtensionInterfaceBinding
    class with remote invocation method code:
    public class SalesForceCustomExtensionInterfaceBinding extends CustomExtensionInterfaceBinding { private static final Logger logger = Logger.getLogger(SalesForceCustomExtensionInterfaceBinding.class.getName()); public SalesForceCustomExtensionInterfaceBinding() { super(SalesForceCustomExtensionInterface.class, new SalesForceCustomExtensionInterface() { @Override public String[] describeGlobal(String connectionKey) throws Exception { logger.log(Level.INFO, "Invoking method on server side, this log entry will appear in the Gateway log."); KeyValueStoreServices keyValueStoreServices = getServiceFinder().lookupService(KeyValueStoreServices.class); KeyValueStore keyValueStore = keyValueStoreServices.getKeyValueStore(); byte[] value = keyValueStore.get(connectionKey); if (value == null) { throw new Exception("Cannot find SalesForce Connection with the specified key: " + connectionKey); } SalesForceConnection connection = SalesForceConnectionUtils.fromBytes(value); String username = connection.getUsername(); String passwordId = connection.getPasswordId(); String securityTokenId = connection.getSecurityTokenId(); SecurePasswordServices securePasswordServices = getServiceFinder().lookupService(SecurePasswordServices.class); String password = securePasswordServices.decryptPassword(passwordId); String securityToken = securePasswordServices.decryptPassword(securityTokenId); SalesForceClient salesforceClient = new SalesForceClient(); salesforceClient.login(username, password, securityToken); List<String> describeGlobalResults = salesforceClient.describeGlobal(); return describeGlobalResults == null ? null : describeGlobalResults.toArray(new String[describeGlobalResults.size()]); } @Override public boolean testConnection(String userName, String passwordId, String securityTokenId) throws Exception { logger.log(Level.INFO, "Invoking method on server side, this log entry will appear in the Gateway log."); SecurePasswordServices securePasswordServices = getServiceFinder().lookupService(SecurePasswordServices.class); String password = securePasswordServices.decryptPassword(passwordId); String securityToken = securePasswordServices.decryptPassword(securityTokenId); SalesForceClient salesforceClient = new SalesForceClient(); try { salesforceClient.login(userName, password, securityToken); return true; } catch (Exception e) { return false; } } }); } }
  3. Specify this class in the “.extension.interface” property in the
    custom_assertion.properties
    file:
    Salesforce.Assertion.extension.interface=com.l7tech.custom.salesforce.partner.v26.assertion.SalesForceCustomExtensionInterfaceBinding
  4. Class that implements the
    CustomAssertionUI
    interface must also implement the
    UsesConsoleContext
    interface:
    public class SalesForceConnectorUI implements CustomAssertionUI, UsesConsoleContext, Serializable { ... }
  5. In the
    SalesForceConnectorDialog,
    get the
    CustomExtensionInterfaceFinder
    object from the console context map:
    private SalesForceCustomExtensionInterface getExtensionInterface() throws ServiceException { SalesForceCustomExtensionInterface salesForceCustomExtensionInterface = null; CustomExtensionInterfaceFinder extensionInterfaceFinder = (CustomExtensionInterfaceFinder) consoleContext.get(CustomExtensionInterfaceFinder.CONSOLE_CONTEXT_KEY); if (extensionInterfaceFinder != null) { salesForceCustomExtensionInterface = extensionInterfaceFinder.getExtensionInterface(SalesForceCustomExtensionInterface.class); return salesForceCustomExtensionInterface; }
  6. In the
    SalesForceConnectorDialog,
    invoke the method on the server:
    logger.log(Level.INFO, "Invoke method on server side, this log entry will appear in the Policy Manager log."); describeGlobal = getExtensionInterface().describeGlobal(connectionKey);