欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java調(diào)用webservice接口,并解析返回參數(shù)問題

 更新時(shí)間:2024年07月02日 11:41:17   作者:weixin_47056195  
這篇文章主要介紹了java調(diào)用webservice接口,并解析返回參數(shù)問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

java調(diào)用webservice接口,并解析返回參數(shù)

1. 設(shè)置傳參

例如以下格式:

// 確定傳參格式以及賦值
String reqXml = "<createAppParam>\n" +
                    "<serviceUserName>auth</serviceUserName>\n" +
                    "<servicePwd>auth</servicePwd>\n" +
                    "<rootTicket>"+rootTicket+"</rootTicket>\n" +
                    "<appAccount>"+userAccount+"</appAccount>\n" +
                    "<resNum>1000</resNum>\n" +
                    "<operationCode>"+operationCode+"</operationCode>\n" +
                    "<functionCode>668801</functionCode>\n" +
                    "<authMode>"+mode+"</authMode>\n" +
                    "<applyReason>"+sendApplyParam.getCerReason()+"</applyReason>\n" +
                    "<userTimes>9999</userTimes>\n" +
                    "<duration>"+sendApplyParam.getExpire()+"</duration>\n" +
                    "<userIP>"+ip+"</userIP>\n" +
                    "<selectedApprover>"+sendApplyParam.getApproverId()+"</selectedApprover>\n" +
                    "<workOrderID>999999</workOrderID>\n" +
                    "<workOrderType>9999</workOrderType>\n" +
                    "</createAppParam>\n";

2. 調(diào)用對端接口

//方法調(diào)用   
//reqXml 傳入的參數(shù)信息
//applyInfoUrl 對端接口的請求地址
//type 對端接口的方法名,如果只是調(diào)用一個(gè)方法名可以寫死
String result = DocumentTrans.send(reqXml,applyInfoUrl,type);

調(diào)用實(shí)現(xiàn)代碼

 //調(diào)用接口
    public static String send(String params,String url,String type) {
        log.info("===傳遞的參數(shù)==="+params);
        log.info("===請求路徑==="+url);
        String result="";
        org.apache.axis.client.Service service = new org.apache.axis.client.Service();
        Call call = null;
        try {
            call = service.createCall();
        } catch (ServiceException e) {
            e.printStackTrace();
        }
        //10.174.242.24:7001
        call.setTargetEndpointAddress(url);
        //3、設(shè)置參數(shù)   in0(對端的方法中的參數(shù)名)
        call.addParameter("in0",
                org.apache.axis.encoding.XMLType.XSD_STRING, //參數(shù)類型
                javax.xml.rpc.ParameterMode.IN);// 接口的參數(shù)
        // 設(shè)置返回類型
        call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);
        try {
            result = (String) call.invoke(QName.valueOf(type), new Object[]{params});
        } catch (Exception e) {
            e.printStackTrace();
            throw new NrmsYnException("接口異常");
        }
        return result;
    }

2.解析返回的參數(shù)

轉(zhuǎn)為List<Map<String, String>>

  //2.1 先調(diào)用解析
    public static Document DocumentHelperreadStringXml(String xmlContent) {
        // DocumentHelper 解析xml字符串
        Document document = null;
        try {
            document = DocumentHelper.parseText(xmlContent);
        } catch (DocumentException e1) {
            e1.printStackTrace();
        }
        return document;
    }

    //2.2 轉(zhuǎn)換 將解析出來的數(shù)據(jù)document 傳入轉(zhuǎn)換接口Documentanalysis1  
    public static List<Map<String, String>> Documentanalysis1(Document doc) {
        List<Map<String, String>> uploadList = new ArrayList<Map<String, String>>();
        Element html = doc.getRootElement();// 獲取根結(jié)點(diǎn)
        List<Element> head = html.elements();
        Set<String> set = new HashSet<>();
        head.forEach(a -> {
            set.add(a.getName());
        });

        set.forEach(a -> {
            List<Element> elements = html.elements(a);// 獲取子結(jié)點(diǎn)
            elements.forEach(b -> {
                Map<String, String> uploadMap = new HashMap<>();
                uploadMap.put(b.getName(), b.getText());
                uploadList.add(uploadMap);
            });
        });
        //返回List<Map<String, String>>
        return uploadList;
    }

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Javassist如何操作Java 字節(jié)碼

    Javassist如何操作Java 字節(jié)碼

    這篇文章主要介紹了Javassist如何操作Java 字節(jié)碼,幫助大家更好的理解和學(xué)習(xí)Java,感興趣的朋友可以了解下
    2020-09-09
  • Myeclipse鏈接Oracle等數(shù)據(jù)庫時(shí)lo exception: The Network Adapter could not establish the connection

    Myeclipse鏈接Oracle等數(shù)據(jù)庫時(shí)lo exception: The Network Adapter coul

    今天小編就為大家分享一篇關(guān)于Myeclipse鏈接Oracle等數(shù)據(jù)庫時(shí)lo exception: The Network Adapter could not establish the connection,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • 深入了解Java中的static關(guān)鍵字

    深入了解Java中的static關(guān)鍵字

    這篇文章主要為大家詳細(xì)介紹了Java中的static關(guān)鍵字的用法的相關(guān)資料,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以學(xué)習(xí)一下
    2022-11-11
  • SpringBoot如何打包自定義生成的包名

    SpringBoot如何打包自定義生成的包名

    這篇文章主要介紹了SpringBoot如何打包自定義生成的包名問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-06-06
  • Java中Jar包反編譯解壓和壓縮操作方法

    Java中Jar包反編譯解壓和壓縮操作方法

    JAR文件就是Java 檔案文件Java Archive,它是 Java 的一種文檔格式,這篇文章主要介紹了Java中Jar包反編譯解壓和壓縮,需要的朋友可以參考下
    2023-09-09
  • Java利用字符流輕松處理文本數(shù)據(jù)

    Java利用字符流輕松處理文本數(shù)據(jù)

    在Java中,文本數(shù)據(jù)是經(jīng)常處理的一種數(shù)據(jù)類型,而字符流就是用來處理文本數(shù)據(jù)的一種流,下面就為大家介紹一下Java字符流的基本概念、常用類和方法,以及如何使用字符流來讀寫文件吧
    2023-09-09
  • Java?通過手寫分布式雪花SnowFlake生成ID方法詳解

    Java?通過手寫分布式雪花SnowFlake生成ID方法詳解

    SnowFlake是twitter公司內(nèi)部分布式項(xiàng)目采用的ID生成算法,開源后廣受國內(nèi)大廠的好評。由這種算法生成的ID,我們就叫做SnowFlakeID,下面我們來詳細(xì)看看
    2022-04-04
  • SpringCloud?Ribbon負(fù)載均衡原理

    SpringCloud?Ribbon負(fù)載均衡原理

    這篇文章主要介紹了SpringCloud?Ribbon負(fù)載均衡原理,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,感興趣的朋友可以參考一下
    2022-09-09
  • 通過Maven進(jìn)行jedis連接redis的實(shí)現(xiàn)

    通過Maven進(jìn)行jedis連接redis的實(shí)現(xiàn)

    這篇文章主要介紹了通過Maven進(jìn)行jedis連接redis的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • Java基礎(chǔ)之教你怎么用代碼一鍵生成POJO

    Java基礎(chǔ)之教你怎么用代碼一鍵生成POJO

    這篇文章主要介紹了Java基礎(chǔ)之教你怎么用代碼一鍵生成POJO,文中有非常詳細(xì)的代碼示例,對正在學(xué)習(xí)Java的小伙伴們有非常好的幫助,需要的朋友可以參考下
    2021-04-04

最新評論