| | |
| | | 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> |
| | |
| | | */ |
| | | public abstract class IceProxyUtility { |
| | | |
| | | private static final String locatorKey = "--Ice.Default.Locator"; |
| | | |
| | | private com.zeroc.Ice.Communicator _communicator = null; |
| | | |
| | | protected IceProxyUtility() { |
| | |
| | | { |
| | | 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; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取服务对象代理 |
| | |
| | | * @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 |