Java调用Axis2用SAP WSDL生成的Stub文件

1、SAP发布WebService

2、SAP配置WebService产生的WSDL通过Axis2生成对应的Stub文件

3、Java调用Axis2用SAP WSDL生成的Stub文件

①建立JavaWeb工程,将axis的相关jar导入至lib文件

②将第2步生成的Stub类文件放入项目包里,再新建1个TEST测试类

③TEST测试类代码:

package com;

import org.apache.axis2.client.Options;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.axis2.transport.http.impl.httpclient4.HttpTransportPropertiesImpl;

import com.ZRFC_MM_PLM_STOCKStub.Char4;
import com.ZRFC_MM_PLM_STOCKStub.Char40;
import com.ZRFC_MM_PLM_STOCKStub.TABLE_OF_ZRFCT007;
import com.ZRFC_MM_PLM_STOCKStub.ZRFCT007;
import com.ZRFC_MM_PLM_STOCKStub.ZRFC_MM_PLM_STOCK;
import com.ZRFC_MM_PLM_STOCKStub.ZRFC_MM_PLM_STOCKResponse;


public class TEST {
    public static void main(String[] args) {
        try {
            ZRFC_MM_PLM_STOCKStub service = new ZRFC_MM_PLM_STOCKStub();
            
            Options options = service._getServiceClient().getOptions();
            
            //设置超时时间
            options.setTimeOutInMilliSeconds(120000);
            
            //SAP的认证
            HttpTransportPropertiesImpl.Authenticator auth = new HttpTransportPropertiesImpl.Authenticator();
            auth.setUsername("XXX");
            auth.setPassword("XXX");
            service._getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE, auth);
            
            ZRFC_MM_PLM_STOCK zrfc = new ZRFC_MM_PLM_STOCK();
            
            //Import参数
            Char4 werks = new Char4();
            werks.setChar4("2000");
            zrfc.setP_WERKS(werks);
            
            Char40 matnr = new Char40();
            matnr.setChar40("ATBA0151-XX");
            zrfc.setP_MATNR(matnr);
            
            TABLE_OF_ZRFCT007 tb_data = new TABLE_OF_ZRFCT007();

            zrfc.setIT_DATA(tb_data);
            
            ZRFC_MM_PLM_STOCKResponse response = service.zRFC_MM_PLM_STOCK(zrfc);
            
            for(ZRFCT007 zrfct007 : response.getIT_DATA().getItem()) {
                System.out.print("工厂:"+zrfct007.getWERKS());
                System.out.print("物料:"+zrfct007.getMATNR());
                System.out.print("仓库:"+zrfct007.getLGORT());
                System.out.print("库存:"+zrfct007.getLABST());
                System.out.println("");
            }
            
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

④运行效果(对比SAP函数直接执行的结果)

4、SAP函数:

5、注意事项:

①Transport error: 403 Error: Forbiddenm

SAP事务代码SICF-->输入层次结构类型SERVICE执行-->依照Stub文件里的地址找到对应webservice并启用服务

②com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog at [row,col {unknown-source}]: [1,0]

在SE37函数生成Webservice的时候选错Profile导致WSDL命名空间错误

原文地址:https://www.cnblogs.com/StephenAmell/p/14263266.html