wuxw
2019-04-01 fa74ecf22c36853d9097beda3dbb99482cfcb430
java110-common/src/main/java/com/java110/common/util/WebServiceAxisClient.java
@@ -7,26 +7,16 @@
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
import com.java110.common.constant.ResponseConstant;
import com.java110.common.exception.BusinessException;
import com.java110.common.log.LoggerEngine;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
//import org.apache.axis.client.Call;
//import org.apache.axis.client.Service;
public class WebServiceAxisClient extends LoggerEngine {
    public static void main(String[] args) {
        String url = "http://135.192.100.2:9001/QH10000Web/WebTelecom10000";
        String function = "getBalance";
        String areaCode = "0971";
        String accNbr = "18997240042";
        String type = "2";
        Object[] obj = new Object[]{areaCode, accNbr, type};
        try {
            Object retObj = WebServiceAxisClient.callWebService(url, function, obj);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    /**
@@ -52,28 +42,28 @@
     * @return
     * @throws Exception
     */
    public static Object callWebService(String url, String function, Object[] obj,Integer timeOut) throws Exception{
    public static Object callWebService(String url, String function, Object[] obj,Integer timeOut) throws BusinessException {
        Object retObj = null;
        try {
            logger.debug("-----------开始调用Web Service-----------");
            // 创建Service对象,Service对用用于创建Call对象
            Service service = new Service();
            // 创建Call对象,Call对象用于调用服务
            Call call = (Call) service.createCall();
            // 为Call对象设置WebService的url
            call.setTargetEndpointAddress(new java.net.URL(url));
            // 为Call对象设置调用的方法名
            call.setOperationName(function);
            // 设置等待时间
            call.setTimeout(timeOut);
            // 调用WebService的方法,并获得返回值
            retObj = call.invoke(obj);
//            Service service = new Service();
//            // 创建Call对象,Call对象用于调用服务
//            Call call = (Call) service.createCall();
//            // 为Call对象设置WebService的url
//            call.setTargetEndpointAddress(new java.net.URL(url));
//            // 为Call对象设置调用的方法名
//            call.setOperationName(function);
//            // 设置等待时间
//            call.setTimeout(timeOut);
//            // 调用WebService的方法,并获得返回值
//            retObj = call.invoke(obj);
            logger.debug("-----------调用Web Service正常结束-----------");
        } catch (Exception e) {
            logger.error("-----------调用Web Service异常,原因:{}", e);
            e.printStackTrace();
            retObj = e.getMessage();
            throw new Exception("WebServiceAxisClient.callWebService throws Exception : " + e.getMessage(), e);
            throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"WebServiceAxisClient.callWebService throws Exception : " + e.getMessage());
        }
        return retObj;
    }