使用java(springboot)調(diào)用webservice接口

前言

為什么這個年頭還有使用webservice接口的項目??!而且給的接口文檔缺斤少兩!webservice接口用起來真的又臭又長!

背景介紹

項目要和另外一個系統(tǒng)對接,但系統(tǒng)提供的接口只有webservice形式的,對于開發(fā)人員的要求就是使用webservice接口進行對接。

開發(fā)過程

使用idea創(chuàng)建/拉取webservice客戶端

一般情況下,webservice會提供一個wsdl文件或地址,在其中能找到所有方法的相關(guān)配置,使用idea可以直接生成相關(guān)的類。
在setting-->plugins中,安裝相關(guān)的webservice插件。


servicePlugind

在項目架構(gòu)中,選擇下載下來的wsdl文件,或直接選擇一個空文件夾。在tools中,找到webservice相關(guān)的generate功能。根據(jù)idea版本的區(qū)別,這個功能出現(xiàn)的形式也有所區(qū)別,大家仔細(xì)找一下。


生成代碼

在頁面中,輸入wsdl文件的地址,選擇代碼要生成的位置,勾選generate testCase按鈕,如果查看wsdl需要登錄,輸入對應(yīng)的用戶名和密碼。
generate

此時,控制臺該報錯了[doge]

不要急,把下面這些包的引用復(fù)制進pom中,再嘗試上述步驟。如果控制臺輸出的只有warning沒有error,那么,代碼生成成功。

        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-discovery</groupId>
            <artifactId>commons-discovery</artifactId>
            <version>0.5</version>
        </dependency>
        <dependency>
            <groupId>org.apache.axis</groupId>
            <artifactId>axis-jaxrpc</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>jakarta.xml.soap</groupId>
            <artifactId>jakarta.xml.soap-api</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.messaging.saaj</groupId>
            <artifactId>saaj-impl</artifactId>
            <version>1.5.1</version>
        </dependency>
        <dependency>
            <groupId>javax.activation</groupId>
            <artifactId>activation</artifactId>
            <version>1.1.1</version>
        </dependency>
        <!-- 郵件start -->
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>1.4.7</version>
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13</version>
            <scope>compile</scope>
        </dependency>

如果找不到生成的代碼,試試右鍵文件-->reload from disk


reload

生成的代碼結(jié)構(gòu)如下


生成的代碼

找到系統(tǒng)自動生成的測試類,調(diào)用相關(guān)方法,就可以看到接口調(diào)用情況了。按照測試類給的方法,進行cv工作,相信大家都會的,對吧。


部分測試代碼
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容