sap系统webservice接口开发

本文介绍了如何在SAP系统环境下,利用Maven的cxf-codegen-plugin插件自动生成WebService客户端代码,并详细展示了设置HTTP basic认证的过程。通过Base64编码处理用户名和密码,结合HttpClient调用服务并解析响应。同时,当遇到问题时,推荐使用Burp Suite等工具来检查HTTP请求和响应数据。

 此文章是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客户端代码_灰色轨迹-优快云博客https://blog.youkuaiyun.com/lorry2010/article/details/84830202

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

开发 SAP Web Service 接口,可以按照以下步骤进行操作: 1. 创建一个 Function Module 首先,需要在 SAP 中创建一个 Function Module。这个 Function Module 负责完成后续 Web Service 的数据处理功能。在创建 Function Module 的过程中,需要确定输入参数和输出参数,这些参数将在后续 Web Service 的调用中起到重要的作用。 2. 创建一个 Enterprise Services Repository 在 SAP 中,需要创建一个 Enterprise Services Repository。这个 Repository 负责管理所有的 Web Service,其中包括已经创建的和将来要创建的。在创建 Repository 的过程中,需要确定 Web Service 的名称、命名空间、端口类型等信息。 3. 创建一个 Service Definition 在 Enterprise Services Repository 中,需要创建一个 Service Definition。这个 Service Definition 包括 Web Service 的基本信息和调用方式。在创建 Service Definition 的过程中,需要指定 Web Service 的名称、命名空间、端口类型、输入参数、输出参数等信息。 4. 创建一个 Service Implementation 在 Service Definition 中,需要创建一个 Service Implementation。这个 Service Implementation 负责实现 Function Module 中定义的功能,并将其封装成 Web Service 的形式。在创建 Service Implementation 的过程中,需要选择已经创建的 Function Module,并指定输入参数和输出参数。 5. 定义一个 Service Binding 在 Service Implementation 中,需要创建一个 Service Binding。这个 Service Binding 负责将 Service Implementation 与 Service Definition 绑定在一起,并指定 Web Service 的访问地址和访问方式。 6. 发布和测试 Web Service 完成以上步骤后,就可以发布 Web Service 并进行测试了。可以使用浏览器或 Web Service 客户端工具来调用 Web Service,并验证其功能是否正确。 以上是开发 SAP Web Service 接口的基本步骤,具体的实现过程还需要根据具体需求进行调整。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值