ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
Source/Common/PLTCommon/src/com/vci/common/util/IceProxyUtility.java
@@ -3,9 +3,12 @@
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import com.vci.common.log.ServerWithLog4j;
import com.vci.common.resource.IceClientProperties;
import com.zeroc.Ice.ObjectPrx;
import com.zeroc.Ice.Util;
/**
 * <p>Title: </p>
@@ -18,6 +21,8 @@
 */
public abstract class IceProxyUtility {
    private static final String locatorKey = "--Ice.Default.Locator";
   private com.zeroc.Ice.Communicator _communicator = null;
   
   protected IceProxyUtility() {
@@ -33,13 +38,20 @@
   {
      try
      {
          _communicator = com.zeroc.Ice.Util.initialize(args);
          _communicator.getDefaultRouter();
         String[] initParams = new String[0];
         if (IceClientProperties.Endpoints().contains("/"))
            initParams = new String[]{locatorKey + "=" + IceClientProperties.Endpoints()};
         _communicator = Util.initialize(initParams);
          //_communicator = com.zeroc.Ice.Util.initialize(args);
          //_communicator.getDefaultRouter();
      } catch (Exception e) {
         ServerWithLog4j.logger.error("InitCommunicator Error", e);
         throw e;
      }
   }
    /**
     * 获取服务对象代理
@@ -47,25 +59,40 @@
     * @return
     * @throws Exception
     */
   public ObjectPrx getObjectByName(String name) throws Exception
   public ObjectPrx getObjectByName(String name, String adapterRep) throws Exception
   {
      ObjectPrx prx = null;
      try 
      {
         String proxyLocator = name + ":" + IceClientProperties.Endpoints();
         ObjectPrx prx = _communicator.stringToProxy(proxyLocator);
         Map<String, String> context = getCurUserContext();
         if (context != null) {
            return prx.ice_context(context);
         String proxyLocator = name;
         if (!IceClientProperties.Endpoints().contains("/")) {
            proxyLocator = name + ":" + IceClientProperties.Endpoints();
         } else {
            return prx;
            proxyLocator = name + "@" + adapterRep;
         }
         prx = _communicator.stringToProxy(proxyLocator);
      } catch (Exception e) {
         e.printStackTrace();
         throw e;
      }
      String[] ids = prx.ice_ids();
      if (prx == null)
         throw new Exception("Not Found ObjectPrx " + name);
      Map<String, String> context = getCurUserContext();
      if (context != null) {
         return prx.ice_context(context);
      } else {
         return prx;
      }
   }
   
   /**
    * 获取服务对象代理,并设置context信息
    * @param name