• 利用apache-cxf生成webservice本地客户端代码接口及接口的大概调用


    第一步:下载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);*/
            }
    }

    大概就是这样

  • 相关阅读:
    面向对象课程设计-FlappyCharacter(个人)
    学生成绩管理系统——个人博客
    学生成绩管理系统(个人)
    JAVA课程设计个人博客----FlappyBird
    Java课程设计——彩票购买抽奖系统
    彩票抽奖程序—个人博客
    彩票购买抽奖程序——个人博客
    面对对象综合设计-贪吃蛇个人博客
    面向对象综合设计-贪吃蛇
    面向对象程序综合设计—课程设计
  • 原文地址:https://www.cnblogs.com/dsh2018/p/9486718.html
Copyright © 2020-2023  润新知