|  | @ -1,209 +0,0 @@
 | 
	
		
			
				|  |  | package com.yihu.ehr.framework.util.wsgateway;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import org.apache.axis.client.Call;
 | 
	
		
			
				|  |  | import org.apache.axis.client.Service;
 | 
	
		
			
				|  |  | import org.apache.axis.encoding.XMLType;
 | 
	
		
			
				|  |  | import org.apache.axis2.addressing.EndpointReference;
 | 
	
		
			
				|  |  | import org.apache.axis2.client.Options;
 | 
	
		
			
				|  |  | import org.apache.axis2.rpc.client.RPCServiceClient;
 | 
	
		
			
				|  |  | import org.json.JSONObject;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import javax.xml.namespace.QName;
 | 
	
		
			
				|  |  | import javax.xml.rpc.ParameterMode;
 | 
	
		
			
				|  |  | import java.net.URL;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * Created by szx on 2015/12/14.
 | 
	
		
			
				|  |  |  */
 | 
	
		
			
				|  |  | public class GatewayUtil {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public GatewayUtil() {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 使用Axis Call Client动态调用WebService地址.
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param webServiceAddr WebService地址
 | 
	
		
			
				|  |  |      * @param webServiceMethod WebService方法
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |      * @param inputValues 输入参数值
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |      * @return 成功返回<code>Object</code>, 失败或异常返回null.
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public static String getObjectByAxisCallClient(String webServiceAddr, String webServiceMethod,
 | 
	
		
			
				|  |  |                                                    Object[] inputValues) {
 | 
	
		
			
				|  |  |         Call call = null;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             Service service = new Service();
 | 
	
		
			
				|  |  |             call = (Call) service.createCall();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             // 设置wsdl
 | 
	
		
			
				|  |  |             call.setTargetEndpointAddress(new URL(webServiceAddr));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //            List pramerList = new ArrayList();
 | 
	
		
			
				|  |  | //            WebServicePramer myWebServicePramer = new WebServicePramer();
 | 
	
		
			
				|  |  | //            myWebServicePramer = new WebServicePramer();
 | 
	
		
			
				|  |  | //            myWebServicePramer.setPramerName("authInfo");
 | 
	
		
			
				|  |  | //            myWebServicePramer.setPramerType(XMLType.XSD_STRING);
 | 
	
		
			
				|  |  | //            myWebServicePramer.setPramerValue(dataXml);
 | 
	
		
			
				|  |  | //            pramerList.add(myWebServicePramer);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             // 设置访问的方法名
 | 
	
		
			
				|  |  |             call.setOperationName("service");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             call.addParameter("authInfo", //参数名
 | 
	
		
			
				|  |  |                     XMLType.XSD_STRING,//参数类型:String
 | 
	
		
			
				|  |  |                     ParameterMode.IN);//参数模式:'IN' or 'OUT'
 | 
	
		
			
				|  |  |             call.addParameter("sequenceNo", //参数名
 | 
	
		
			
				|  |  |                     XMLType.XSD_STRING,//参数类型:String
 | 
	
		
			
				|  |  |                     ParameterMode.IN);//参数模式:'IN' or 'OUT'
 | 
	
		
			
				|  |  |             call.addParameter("api", //参数名
 | 
	
		
			
				|  |  |                     XMLType.XSD_STRING,//参数类型:String
 | 
	
		
			
				|  |  |                     ParameterMode.IN);//参数模式:'IN' or 'OUT'
 | 
	
		
			
				|  |  |             call.addParameter("param", //参数名
 | 
	
		
			
				|  |  |                     XMLType.XSD_STRING,//参数类型:String
 | 
	
		
			
				|  |  |                     ParameterMode.IN);//参数模式:'IN' or 'OUT'
 | 
	
		
			
				|  |  |             call.addParameter("paramType", //参数名
 | 
	
		
			
				|  |  |                     XMLType.XSD_INT,//参数类型:String
 | 
	
		
			
				|  |  |                     ParameterMode.IN);//参数模式:'IN' or 'OUT'
 | 
	
		
			
				|  |  |             call.addParameter("outType", //参数名
 | 
	
		
			
				|  |  |                     XMLType.XSD_INT,//参数类型:String
 | 
	
		
			
				|  |  |                     ParameterMode.IN);//参数模式:'IN' or 'OUT'
 | 
	
		
			
				|  |  |             call.addParameter("v", //参数名
 | 
	
		
			
				|  |  |                     XMLType.XSD_STRING,//参数类型:String
 | 
	
		
			
				|  |  |                     ParameterMode.IN);//参数模式:'IN' or 'OUT'
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             call.addParameter("out", XMLType.XSD_STRING,//参数类型:String
 | 
	
		
			
				|  |  |                     ParameterMode.OUT);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             call.setReturnType((QName) XMLType.XSD_STRING);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             String result=(String)call.invoke(inputValues);
 | 
	
		
			
				|  |  |             return result;
 | 
	
		
			
				|  |  |             // 定义参数对象
 | 
	
		
			
				|  |  |             //call.setUseSOAPAction(true);
 | 
	
		
			
				|  |  |             //call.setSOAPActionURI(soapActionURI + webServiceMethod);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //            OperationDesc oper = new OperationDesc();
 | 
	
		
			
				|  |  | //            if (!ArrayUtils.isEmpty(inputNames)) {
 | 
	
		
			
				|  |  | //                for (int i = 0; i < inputNames.length; i++) {
 | 
	
		
			
				|  |  | //                    // String类型
 | 
	
		
			
				|  |  | //                    oper.addParameter(new QName(targetNamespace, inputNames[i]), new QName(targetNamespace, inputXmlTypes[i]),
 | 
	
		
			
				|  |  | //                            inputJavaTypes[i], ParameterDesc.IN, false, false);
 | 
	
		
			
				|  |  | //                }
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  | //            oper.setReturnType(XMLType.XSD_ANYTYPE);
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //            call.setTimeout(30000);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //            resObj = call.invoke(inputValues);
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return "";
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //    private void test(){
 | 
	
		
			
				|  |  | //        try {
 | 
	
		
			
				|  |  | //            final String SERVER_URL = "http://172.19.103.55:8080/WSGW/services/ServiceGateWay";
 | 
	
		
			
				|  |  | //            HttpPost request = new HttpPost(SERVER_URL);
 | 
	
		
			
				|  |  | //            List<BasicNameValuePair> params = new ArrayList();
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //            String reqXml =
 | 
	
		
			
				|  |  | //                    "<Req>" +
 | 
	
		
			
				|  |  | //                            "<TransactionCode>1</TransactionCode>" +
 | 
	
		
			
				|  |  | //                            "<Service>" +
 | 
	
		
			
				|  |  | //                            "<SessionID>0a4ad1eaf2584825b21bb783778f374e</SessionID>" +
 | 
	
		
			
				|  |  | //                            "<UserID>EA1DF016ECCF4BBF8DBB35E5A3D3F436</UserID>" +
 | 
	
		
			
				|  |  | //                            "</Service></Req>";
 | 
	
		
			
				|  |  | //            params.add(new BasicNameValuePair("param", reqXml));
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //            JSONObject authInfo = new JSONObject();
 | 
	
		
			
				|  |  | //            authInfo.put("ClientId","aaa");
 | 
	
		
			
				|  |  | //            authInfo.put("ClientVersion","aaa");
 | 
	
		
			
				|  |  | //            authInfo.put("Sign","aaa");
 | 
	
		
			
				|  |  | //            authInfo.put("SessionKey","aaa");
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //            params.add(new BasicNameValuePair("authInfo", "aa"));
 | 
	
		
			
				|  |  | //            params.add(new BasicNameValuePair("sequenceNo", "aaaaaaa"));
 | 
	
		
			
				|  |  | //            params.add(new BasicNameValuePair("api", "session.SessionApi.getSession"));
 | 
	
		
			
				|  |  | //            params.add(new BasicNameValuePair("paramType", "0"));
 | 
	
		
			
				|  |  | //            params.add(new BasicNameValuePair("outType", "0"));
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //            //params.add(new BasicNameValuePair("mobileCode", "136370628"));  //(注意这里的号码必须大于6位)
 | 
	
		
			
				|  |  | //            //params.add(new BasicNameValuePair("userId", ""));
 | 
	
		
			
				|  |  | //            request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
 | 
	
		
			
				|  |  | //            HttpResponse httpResponse = new DefaultHttpClient().execute(request);
 | 
	
		
			
				|  |  | //            if (httpResponse.getStatusLine().getStatusCode() != 404) {
 | 
	
		
			
				|  |  | //                String result = EntityUtils.toString(httpResponse.getEntity());
 | 
	
		
			
				|  |  | //                System.out.println(result);
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  | //        }catch (Exception e){
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | //    }
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 使用Axis Call Client动态调用WebService地址.
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param webServiceAddr   WebService地址
 | 
	
		
			
				|  |  |      * @param webserviceNamespace WebService的namespace
 | 
	
		
			
				|  |  |      * @param webServiceMethod WebService方法
 | 
	
		
			
				|  |  |      * @param inputValues      输入参数值
 | 
	
		
			
				|  |  |      * @param inputValuetype      输入参数值类型
 | 
	
		
			
				|  |  |      * @return 成功返回<code>Object</code>, 失败或异常返回null.
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public static String getObjectByAxis2CallClient(String webServiceAddr, String webserviceNamespace, String webServiceMethod,
 | 
	
		
			
				|  |  |                                                     Object[] inputValues, Class[] inputValuetype) {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             //新建RPC服务客户端
 | 
	
		
			
				|  |  |             RPCServiceClient serviceClient = new RPCServiceClient();
 | 
	
		
			
				|  |  |             Options options = serviceClient.getOptions();
 | 
	
		
			
				|  |  |             //设置URL
 | 
	
		
			
				|  |  |             EndpointReference targetEPR = new EndpointReference(webServiceAddr);
 | 
	
		
			
				|  |  |             options.setTo(targetEPR);
 | 
	
		
			
				|  |  |             //设置参数的类型
 | 
	
		
			
				|  |  |             //设置namespace和方法名
 | 
	
		
			
				|  |  |             QName opAddEntry = new QName(webserviceNamespace, webServiceMethod);
 | 
	
		
			
				|  |  |             //数组的第一个值为返回值
 | 
	
		
			
				|  |  |             return (String) (serviceClient.invokeBlocking(opAddEntry, inputValues, inputValuetype))[0];
 | 
	
		
			
				|  |  |         } catch (Exception e) {
 | 
	
		
			
				|  |  |             e.printStackTrace();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return "";
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * @param args
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public static void main(String[] args) throws Exception {
 | 
	
		
			
				|  |  |         // TODO Auto-generated method stub
 | 
	
		
			
				|  |  |         String SERVER_URL = "http://172.19.103.55:8080/WSGW/services/ServiceGateWay";
 | 
	
		
			
				|  |  |         String namespace = "http://com.yihu.wsgw/ServiceGateWay";
 | 
	
		
			
				|  |  |         String methos = "service";
 | 
	
		
			
				|  |  |         Class[] classes = new Class[]{String.class, String.class, String.class, String.class, Integer.class, Integer.class, Integer.class};
 | 
	
		
			
				|  |  |         Object[] v = new Object[7];
 | 
	
		
			
				|  |  |         JSONObject authInfo = new JSONObject();
 | 
	
		
			
				|  |  |         authInfo.put("ClientId", "aaa");
 | 
	
		
			
				|  |  |         authInfo.put("ClientVersion", "1.0");
 | 
	
		
			
				|  |  |         authInfo.put("Sign", "");
 | 
	
		
			
				|  |  |         authInfo.put("SessionKey", "");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         v[0] = authInfo.toString();//authInfo
 | 
	
		
			
				|  |  |         v[1] = "201601080838000000";//sequenceNo
 | 
	
		
			
				|  |  |         v[2] = "resource.resource.getAuthorizedResource";//api
 | 
	
		
			
				|  |  |         v[3] = "Param={sys_id:asdasd,start:1,pageSize:10}";
 | 
	
		
			
				|  |  |         v[4] = 0;//paramType
 | 
	
		
			
				|  |  |         v[5] = 0;//outType
 | 
	
		
			
				|  |  |         v[6] = 1;
 | 
	
		
			
				|  |  |         System.out.println(getObjectByAxis2CallClient(SERVER_URL, namespace, methos, v, classes));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |