如何自定义soapUI库以生成请求& WSDL的回应?

时间:2013-02-06 14:27:26

标签: java soap wsdl soapui

我正在开发一个模块,它将采用wsdl&生成请求&回复文件。为此,我使用了此代码Post

中提到的soapui
package com.bbog.soap;
import com.eviware.soapui.impl.wsdl.WsdlInterface;
import com.eviware.soapui.impl.wsdl.WsdlOperation;
import com.eviware.soapui.impl.wsdl.WsdlProject;
import com.eviware.soapui.impl.wsdl.support.wsdl.WsdlImporter;
import com.eviware.soapui.model.iface.Operation;

public class WsdlAnalyzer {

public static void main(String[] args) throws Exception {
    WsdlProject project = new WsdlProject();
    WsdlInterface[] wsdls = WsdlImporter.importWsdl(project, "http://localhost:7000/Solicitud?wsdl");
    WsdlInterface wsdl = wsdls[0];
    for (Operation operation : wsdl.getOperationList()) {
        WsdlOperation op = (WsdlOperation) operation;
        System.out.println("OP:"+op.getName());
        System.out.println(op.createRequest(true));
        System.out.println("Response:");
        System.out.println(op.createResponse(true));
    }
}
}

所以,当我用它来生成肥皂请求&响应,某些东西在后台运行(我可以在网络豆中看到),即使它不在for循环中。请帮我定制soapUI库,调用相应的方法生成请求&响应&释放任何创建/初始化的资源。

1 个答案:

答案 0 :(得分:1)

这是我处理请求和响应的方式

   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);
   System.out.println("REQUEST: " + requestContent);
   // submit the request
   try {
        WsdlSubmit submit = (WsdlSubmit) request.submit(new WsdlSubmitContext(request), false);
        Status status = submit.getStatus(); //FINISHED OR ERROR
        System.out.println("STATUS: " + status); 
        Response response = submit.getResponse();
        System.out.println("RESPONSE: " + response.getContentAsString());
     } catch (SubmitException ex) {
    //Catch the exception
     }

希望有所帮助