0

我正在为 java 使用 SOAPUI API,这是我代码的一小部分

 for (Operation operation : wsdlInterface1.getOperationList()) {
        operationString = WSDL + ":" + wsdlInterface1.getName() + ":" + operation.getName();
        WsdlOperation wsdlOperation = (WsdlOperation) operation;
        // create a new empty request for that operation
        WsdlRequest request = wsdlOperation.addNewRequest("My request");
        request.setTimeout("2000");                 
        requestContent = wsdlOperation.createRequest(true);
        request.setRequestContent(requestContent);
        WsdlSubmit submit = (WsdlSubmit) request.submit(new WsdlSubmitContext(request), false);

现在我需要做与此类似的事情,但加载现有的外部请求文件,我在 SOAPUI api 文档中找不到帮助,欢迎任何帮助

4

1 回答 1

1

我能够自己找到解决方案

此代码加载由 soapUI api 生成的空白请求

WsdlOperation wsdlOperation=wsdlInterface1.getOperationByName(operationName);
WsdlRequest request = wsdlOperation.addNewRequest("My request");
request.setTimeout("2000");
String requestContent = wsdlOperation.createRequest(true); // Create a blank request
request.setRequestContent(requestContent);

要使用现有请求,您需要将该请求保存在这样的字符串中,在我的情况下,我从数据库中获取 xml

WsdlOperation wsdlOperation=wsdlInterface1.getOperationByName(operationName);
WsdlRequest request = wsdlOperation.addNewRequest("My request");
String requestContent;              
   if(rd.useXmlRequest(artifactId)!=null){ //Verify if exist an xml request for that service
requestContent=rd.useXmlRequest(artifactId); // uses the existing request
   }else{
requestContent = wsdlOperation.createRequest(true); // create a new blank request                       
 }
request.setRequestContent(requestContent); 
WsdlSubmit submit = (WsdlSubmit) request.submit(new WsdlSubmitContext(request), false);
于 2013-02-19T13:19:20.837 回答