栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

sap系统webservice接口开发

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

sap系统webservice接口开发

 此文章是sap系统提供WebService服务端,使用Maven工程,自动生成WebService客户端代码,并设置http basic认证,进行调用,得到服务端的返回。

GET /index.html HTTP/1.1
Host: server001.sap.com
Authorization: Basic aGFyYm9yOmhhcmJvcg==

其中aGFyYm9yOmhhcmJvcg==为 用户名:密码 进行base64加密后,utf-8编码的数据

在线base64加密:base64在线编码解码 UTF-8http://tools.jb51.net/tools/base64_decode-utf8.php

根据导出WSDL文件,或者在线的WSDL地址,通过maven的cxf-codegen-plugin插件,生成WebService客户端的代码。

允许mvn命令,指定使用cxf-codegen-plugin插件,指定goal为wsdl2java

mvn  org.apache.cxf:cxf-codegen-plugin:3.2.13:wsdl2java

生成代码输出至interface-ws-saptargetgenerated-sourcescxfcomsapdocumentsaprfcfunctions 目录

然后将代码拷贝至工程的正确代码位置

其中ZFMSDCRMFUND为持有ZSSDCRMFUND的item元素的ArrayList对象。

最终调用的代码为

com.sap.sales.wsdl.fund.ObjectFactory objectFactory = new com.sap.sales.wsdl.fund.ObjectFactory();
        String url = sapWsAddress+"/XISOAPAdapter/MessageServlet?senderParty=&senderService=BS_CRM&receiverParty=&receiverService=&interface=SI_FUND_OB_SYNC&interfaceNamespace=http://crm.sap.com/interfaces/FUND";
        com.sap.sales.wsdl.fund.ZFMSDCRMFUND requestDTO = sapFundService.getData();
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        // this is the package name specified in the  specified in pom.xml
        marshaller.setContextPath("com.sap.sales.wsdl.fund");
        JAXBElement dtRetMsgJAXBElement = (JAXBElement)callClient.callWebService(url, requestDTO, marshaller);
        com.sap.sales.wsdl.fund.ZFMSDCRMFUNDResponse dtRetMsg =  dtRetMsgJAXBElement.getValue();
        log.info(dtRetMsg.toString());

http basic认证的设置代码为

    @Bean
    HttpClient createHttpClient() {
        List
headers = new ArrayList<>(); BasicHeader authHeader = new BasicHeader("Authorization", "Basic " + authStr); headers.add(authHeader); // add more header as more as needed RequestDefaultHeaders reqHeader = new RequestDefaultHeaders(headers); CloseableHttpClient httpClient = HttpClients.custom() .addInterceptorFirst(new HttpComponentsMessageSender.RemoveSoapHeadersInterceptor()) .addInterceptorLast(reqHeader) // .setProxy( new HttpHost("127.0.0.1", 8080, "http")) .build(); return httpClient; }

若调用出现问题,我通常的解决方案是设置http代理,使用burpsuit工具,查看http的请求和返回数据(因为ieda无法看到原始的http请求和响应数据)

参考:(69条消息) maven 生成webservice客户端代码_灰色轨迹-CSDN博客https://blog.csdn.net/lorry2010/article/details/84830202

(69条消息) 使用Apache CXF cxf-codegen-plugin生成webservice客户端jar包_吖沈-CSDN博客https://blog.csdn.net/weixin_42020557/article/details/106323453

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/591199.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号