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-sap\target\generated-sources\cxf\com\sap\document\sap\rfc\functions 目录

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

其中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 <generatePackage> specified in pom.xml
        marshaller.setContextPath("com.sap.sales.wsdl.fund");
        JAXBElement<com.sap.sales.wsdl.fund.ZFMSDCRMFUNDResponse> dtRetMsgJAXBElement = (JAXBElement<com.tcl.sales.wsdl.fund.ZFMSDCRMFUNDResponse>)callClient.callWebService(url, requestDTO, marshaller);
        com.sap.sales.wsdl.fund.ZFMSDCRMFUNDResponse dtRetMsg =  dtRetMsgJAXBElement.getValue();
        log.info(dtRetMsg.toString());

http basic认证的设置代码为

    @Bean
    HttpClient createHttpClient() {
        List<Header> 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

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值