axis2客户端

package com.yq.test;

/**
 * Created by yangqing on 2016/12/6.
 */


        import java.util.Date;
        import java.util.UUID;

        import javax.xml.namespace.QName;

        import org.apache.axis2.AxisFault;
        import org.apache.axis2.addressing.EndpointReference;
        import org.apache.axis2.client.Options;
        import org.apache.axis2.rpc.client.RPCServiceClient;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONArray;



public class TestWs {

    public static void main(String args[]) throws AxisFault,
            InterruptedException {
        yewujiantuisongM();
    }

    public static void yewujiantuisongM()  {
        try{
            // 使用RPC方式调用WebService
            RPCServiceClient serviceClient = new RPCServiceClient();
            Options options = serviceClient.getOptions();
            // 指定调用WebService的URL
            EndpointReference targetEPR = new EndpointReference(
                    "http://127.0.0.1:8090/datai/services/pubWebService");
            options.setTo(targetEPR);


            //String strJson = JSONArray.fromObject(list).toString();

            //JsonObjecj  jsonObject = new JsonObjecj();

            //JSONArray.


            JSONObject jsonObj = new JSONObject();

            jsonObj.put("INCOME_CODE", "0019");
            jsonObj.put("INCOME_NAME", "小明_test");
            jsonObj.put("IS_STOP", "0");
            jsonObj.put("INCOME_PROPERTY", "I");
            jsonObj.put("INCOME_TYPE", "2");


            JSONObject jsonObj2 = new JSONObject();
            jsonObj2.put("INCOME_CODE", "0018");
            jsonObj2.put("INCOME_NAME", "张三_test");
            jsonObj2.put("IS_STOP", "0");
            jsonObj2.put("INCOME_PROPERTY", "O");
            jsonObj2.put("INCOME_TYPE", "1");


            JSONArray jsonArray = new JSONArray();
            jsonArray.add(jsonObj);
            jsonArray.add(jsonObj2);


            jsonArray.toString();


            JSONObject jsonObj_row= new JSONObject();
            jsonObj_row.put("ROW", jsonArray);


            JSONObject jsonObj_data= new JSONObject();
            jsonObj_data.put("DATA", jsonObj_row);

            JSONObject jsonObj_root= new JSONObject();
            jsonObj_root.put("ROOT", jsonObj_data);

            //{"ROOT":{"DATA":{"ROW":[{"INCOME_CODE":"XXX","INCOME_NAME":"XXX","IS_STOP":"XXX","INCOME_PROPERTY":"XXX","INCOME_TYPE":"XXX"}]}}}


            // 对xml进行拼接
            StringBuffer sb = new StringBuffer();

            sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

            sb.append("<ROOT>");
            sb.append("<HEAD>");
            sb.append("</HEAD>");

            sb.append("<DATA>");
            sb.append("<ROW>");
            sb.append("<INCOME_CODE>1050</INCOME_CODE>");
            sb.append("<INCOME_NAME>胡歌</INCOME_NAME>");
            sb.append("<IS_STOP>0</IS_STOP>");
            sb.append("<INCOME_PROPERTY>30</INCOME_PROPERTY>");
            sb.append("<INCOME_TYPE>30</INCOME_TYPE>");
            sb.append("</ROW>");

            sb.append("<ROW>");
            sb.append("<INCOME_CODE>1060</INCOME_CODE>");
            sb.append("<INCOME_NAME>胡歌1111</INCOME_NAME>");
            sb.append("<IS_STOP>0</IS_STOP>");
            sb.append("<INCOME_PROPERTY>60</INCOME_PROPERTY>");
            sb.append("<INCOME_TYPE>5</INCOME_TYPE>");
            sb.append("</ROW>");
            sb.append("</DATA>");
            sb.append("</ROOT>");
            // 设定参数值:xml,访问标识名
            Object[] opAddEntryArgs = new Object[] { jsonObj_root.toString(), "ts_int_test" };

            //System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
            //System.out.println(jsonObj_root.toString());

            //Object[] opAddEntryArgs = new Object[] { sb.toString(), "ts_int_test" };


            // 指定方法返回值的数据类型的Class对象
            Class[] classes = new Class[] { String.class };
            // 指定要调用的sayHelloToPerson方法及WSDL文件的命名空间
            QName opAddEntry = new QName("http://ws.dc.viewhigh.com",
                    "dc_ws_command");
            // 调用方法并输出该方法的返回值

            System.out.println("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv-------------------------------->");
            System.out.println( serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs,
                    classes)[0]);
            System.out.println("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv222-------------------------------->");


           /* System.out.println(DateUtil.convertDateToString(new Date(),
                    "yyyy-MM-dd HH:mm:ss")
                    + "成功!!!!:"
                    + serviceClient.invokeBlocking(opAddEntry, opAddEntryArgs,
                    classes)[0]);*/
        }catch(Exception e){

            e.printStackTrace();
        }
    }
}

 

posted @ 2017-01-13 16:24  8899man  阅读(258)  评论(0编辑  收藏  举报