wangting
2024-04-08 8be3182372eb774dce8f9c97a0b51c03bda165c7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package com.vci.common.util;
 
import java.util.HashMap;
import java.util.Map;
 
import com.vci.common.log.ServerWithLog4j;
import com.vci.common.resource.IceClientProperties;
import com.zeroc.Ice.ObjectPrx;
 
/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2009</p>
 * <p>Company: VCI</p>
 * @author eddie
 * @time 2009-4-14
 * @version 1.0
 */
public abstract class IceProxyUtility {
 
    private com.zeroc.Ice.Communicator _communicator = null;
    
    protected IceProxyUtility() {
    }
    
 
    public void InitIceEnv()
    {
 
    }
    
     public void InitCommunicator(String[] args)
    {
        try
        {
             _communicator = com.zeroc.Ice.Util.initialize(args);
             _communicator.getDefaultRouter();
        } catch (Exception e) {
            ServerWithLog4j.logger.error("InitCommunicator Error", e);
            throw e;
        }
    }
 
     /**
      * 获取服务对象代理
      * @param name
      * @return
      * @throws Exception
      */
    public ObjectPrx getObjectByName(String name) throws Exception
    {
        try 
        {
            String proxyLocator = name + ":" + IceClientProperties.Endpoints();
            
            ObjectPrx prx = _communicator.stringToProxy(proxyLocator);
            Map<String, String> context = getCurUserContext();
            if (context != null) {
                return prx.ice_context(context);
            } else {
                return prx;
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
    
    /**
     * 获取服务对象代理,并设置context信息
     * @param name
     * @param context
     * @return
     * @throws Exception
     */
    public ObjectPrx getObjectByName(String name, Map<String, String> context) throws Exception
    {
        try 
        {
            String proxyLocator = name + ":" + IceClientProperties.Endpoints();
            
            ObjectPrx prx = _communicator.stringToProxy(proxyLocator);
            
            if (context != null) {
                return prx.ice_context(context);
            }
            
            return prx;
            
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
    
    
 
    /**
     * 获取当前用户信息构建服务代理对象上下文
     * @return
     */
    private Map<String, String> getCurUserContext() {
        Map<String, String> context = new HashMap<String, String>();
        
        String token = getInvocationInfo();
        if (token == null)
            return null;
        
        context.put("token", getInvocationInfo());
        return context;
    }
 
    
    protected abstract String getInvocationInfo();
//    {
//        VCIInvocationInfo vcii = null;
//        if (ServerContextVariable.getInvocationInfo() != null) {
//            
//            vcii = ServerContextVariable.getInvocationInfo();
//            
//        }
//        else {
//            if (ClientContextVariable.getClientLanuchMode().equals(LaunchModeEnum.Normal)) {
//                vcii = ClientContextVariable.getInvocationInfo();
//            } else {
//                vcii = InvocationUtility.getInvocation();
//            }
//        }
//        if (vcii == null || StringUtils.isBlank(vcii.userID)) {
//            return null;
//        } else {
//            if (vcii.extAttribs == null)
//                vcii.extAttribs = new String[0];
//            if (vcii.groupIDs == null)
//                vcii.groupIDs = new String[0];
//            if (vcii.groupNames == null)
//                vcii.groupNames = new String[0];
//            if (vcii.roleIDs == null)
//                vcii.roleIDs = new String[0];
//            if (vcii.roleNames == null)
//                vcii.roleNames = new String[0];
//        }
//        
//        return JSONObject.toJSONString(vcii);
//    }
 
}