• Java根据WSDL生成request的SOAP报文模板


    import groovy.xml.MarkupBuilder;
    import org.junit.Test;
    import com.predic8.wsdl.*;
    import com.predic8.wstool.creator.RequestTemplateCreator;
    import com.predic8.wstool.creator.SOARequestCreator;
    
        @Test
        public void testCreateSOAP() throws IOException {
            String wsdlUrl = "http://localhost:19092/financial-budget-ws/budgetHold?wsdl";
            WSDLParser parser = new WSDLParser();
            Definitions wsdl = parser.parse(wsdlUrl);
            StringWriter writer = new StringWriter();
            SOARequestCreator creator = new SOARequestCreator(wsdl, new RequestTemplateCreator(), new MarkupBuilder(writer));
    //        creator.setBuilder(new MarkupBuilder(writer));
    //        creator.setDefinitions(wsdl);
    //        creator.setCreator(new RequestTemplateCreator());
    
    /*        // 针对new RequestCreator()可以赋值参数
            creator.setCreator(new RequestCreator());
            HashMap<String, String> formParams = new HashMap<String, String>();
            formParams.put("xpath:/BudgetHold/BudgetHoldRequest/SEQ_NO", "202004260001");
            formParams.put("xpath:/BudgetHold/BudgetHoldRequest/INTF_BILL_NO", "20200001");
            creator.setFormParams(formParams);*/
    
            for (Service service : wsdl.getServices()) {
                for (Port port : service.getPorts()) {
                    Binding binding = port.getBinding();
                    PortType portType = binding.getPortType();
                    for (Operation op : portType.getOperations()) {
                        System.out.println(op.getName() + " -- " + op.getInput().getName() + " -- " + op.getOutput().getMessage().getName());
    
                        creator.createRequest(port.getName(), op.getName(), binding.getName());
                        System.out.println(writer);
                        writer.getBuffer().setLength(0);
                    }
                }
            }
    
    //        <dependency>
    //            <groupId>com.predic8</groupId>
    //            <artifactId>soa-model-core</artifactId>
    //        </dependency>
        }
  • 相关阅读:
    CSP第二轮比赛注意事项
    2021 CCF非专业级别软件能力认证第一轮 (CSP-S)提高级 C++答案及解析
    2021 CCF非专业级别软件能力认证第一轮 (CSP-J)入门级 C++答案及解析
    Python编程与实际运用
    CCF NOI大纲
    搭建自己的kms服务器激活windows和office
    腾讯云数据库连接navicat
    Java unicode编码转换
    git 强制更新版本
    oracle相关
  • 原文地址:https://www.cnblogs.com/ding0910/p/12780204.html
Copyright © 2020-2023  润新知