第一步:下载apache-cxf进行环境变量配置
1、下载apache-cxf-2.6.2在环境变量中配置
新建CXF_HOME C:ProgramFiles(my)apache-cxf-2.7.2
在CLASSPATH %CXF_HOME%lib
在PATH中添加 %CXF_HOME%in
2、输入cmd 进入控制窗口,输入wsdl2java看是否配置成功
第二步:生成本地第三方接口本地客户端接口代码
wsdl2java -encoding utf-8 -d F:\src -client http://hac.haier.net:1033/com.haier.openplatform.hac.resource.service.HacResourceServiceClient?wsdl
加黑是指定接口代码生成的目录位置,将代码整合到自己项目里。类似这样的代码:
第三步:调用接口
package com.haier.openplatform.hac.resource.service; import java.util.List; import org.json.JSONObject; import net.sf.json.JSONArray; import com.haier.openplatform.hac.service.HacDataPrivilegeDTO; import com.haier.openplatform.hac.service.HacPrivilegeServiceClient; import com.haier.openplatform.hac.service.HacPrivilegeServiceClientPortType; public final class Test { private Test() { } public static void main(String[] args) { HacResourceServiceClient ss = new HacResourceServiceClient(); HacResourceServiceClientPortType port = ss.getHacResourceServiceClientPort(); UserSourceAndScode s=new UserSourceAndScode(); s.setSCode("1.0"); s.setUserSource("portal"); List<HacResourceDTO> resourcesByAppAndUser = port.getResourcesByAppAndUser("S00870", "1", "zh_CN", "1.0", s); JSONArray json = JSONArray.fromObject(resourcesByAppAndUser); System.out.println(json); /* { System.out.println("Invoking getResourcesByAppAndUser..."); for(HacResourceDTO hac:resourcesByAppAndUser){ JSONObject json = JSONObject.fromObject(hac);//将java对象转换为json对象 String str = json.toString();//将json对象转换为字符串 System.out.println(str); }*/ /*HacPrivilegeServiceClient ss=new HacPrivilegeServiceClient(); HacPrivilegeServiceClientPortType hacPrivilegeServiceClientPort = ss.getHacPrivilegeServiceClientPort(); List<HacDataPrivilegeDTO> privilegeData = hacPrivilegeServiceClientPort.getPrivilegeData("", "", null); System.out.println("Invoking privilegeData..."); System.out.println(privilegeData);*/ } }
大概就是这样