利用axis测试接口(通过ESB推送数据给其他的系统)

xiaoxiao2021-03-01  37

public class GetItemJFTest {     public static void main(String[] args) {         axis();     }

    // 通过axis方式调用webservice接口     public static void axis() {         String result = "";         String methodName = "uniformInterface";//esb系统里面写的固定的方法名         Map<String, Object> paramsMap = new HashMap<String, Object>();//paramsMap为存放参数的集合,这里放的参数要和                                                                                                                          //对接系统暴露接口的参数名相同         paramsMap.put("projectCode", "scxx444");         paramsMap.put("password", "p@ssw0rd");         paramsMap.put("type", "1111");         paramsMap.put("stringJSON", "dasda");         Object[] params = new Object[]{"webTest_getItemJF", JSON.toJSONString(paramsMap), null};//该数组存放了三个对象,                                                                                                                                                                //第一个是主调接口的接口编                                                                                                                                                         //码,第二个是参数集,第三个                                                                                                                                               //是返回结果,因为未知,所以先设为null         try {             Service service = new Service();             Call call = (Call) service.createCall();             URL url = new URL("http://192.168.129.236:61618/uniformInterface-ws");//esb系统搭建在哪,该地址就写哪的的地址,是wsdl服务里面的地址             call.setTargetEndpointAddress(url);             call.setOperationName(new QName("http://service.ws.esb.huatek.com/",methodName));//http://service.ws.esb.huatek.com  是wsdl里面的命名空间             //call.setOperationName(authMethodName);             call.addParameter("arg0", XMLType.XSD_STRING, ParameterMode.IN);// 操作的参数               call.addParameter("arg1", XMLType.XSD_STRING, ParameterMode.IN);// 操作的参数               call.addParameter("arg2", XMLType.XSD_ANYTYPE, ParameterMode.IN);// 操作的参数               call.setReturnType(XMLType.XSD_STRING);// 设置返回类型               call.setUseSOAPAction(true);             result = (String) call.invoke(params);         } catch (Exception e1) {             e1.printStackTrace();         }          System.out.println(result);     } }

转载请注明原文地址: https://www.6miu.com/read-4550066.html

最新回复(0)