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> }