简体   繁体   English

如何在 Java 中获取 SoapUI 请求和响应 XML

[英]How to get SoapUI request and response XML in java

I'm using the SoapUI API as part of an existing java project.我正在使用 SoapUI API 作为现有 Java 项目的一部分。 The application should save the request and response XML in an specific report file.应用程序应将请求和响应 XML 保存在特定的报告文件中。 I wonder if it's possible to get those requests and responses via the API.我想知道是否可以通过 API 获取这些请求和响应。 The method invoking the TestCaseRunner looks like this调用 TestCaseRunner 的方法如下所示

protected void checkTestCase(TestCase testCase) {
    TestCaseRunner tr = testCase.run(null, false);
    for (TestStepResult tcr : tr.getResults()) {
         String status = tcr.getStatus();
         String time = tcr.getTimeTaken() + "ms";
        /* How to get XML messages?
         * String request = 
         * String response = 
         */
    }
}

Depending on exactly what kind of test steps you have they might be an instance of a MessageExchange.具体取决于您拥有的测试步骤类型,它们可能是 MessageExchange 的实例。 Casting the TestStepResult to a MessageExchange and calling getRequestContent / getResponseContent might do the trick.将 TestStepResult 转换为 MessageExchange 并调用 getRequestContent / getResponseContent 可能会成功。

String request = ((MessageExchange)tcr).getRequestContent();
String response = ((MessageExchange)tcr).getResponseContent();

I'm using the SoapUI API as part of an existing java project.我使用 SoapUI API 作为现有 Java 项目的一部分。 The application should save the request and response XML in an specific report file.应用程序应将请求和响应 XML 保存在特定报告文件中。 I wonder if it's possible to get those requests and responses via the API.我想知道是否可以通过 API 获取这些请求和响应。 The method invoking the TestCaseRunner looks like this调用 TestCaseRunner 的方法如下所示

protected void checkTestCase(TestCase testCase) {
    TestCaseRunner tr = testCase.run(null, false);
    for (TestStepResult tcr : tr.getResults()) {
         String status = tcr.getStatus();
         String time = tcr.getTimeTaken() + "ms";
        /* How to get XML messages?
         * String request = 
         * String response = 
         */
    }
}

I have used the following way to get the response from the API CAll performed:我使用以下方式从执行的 API CAll 中获取响应:

runner = testRunner.runTestStepByName("Your Test Case name");
// Here we take the response in ms of the API call
timeTaken = runner.response.timeTaken;
// here we get the HTTP response code.
responseCode = runner.getResponseHeaders()."#status#";
// here we get the response content
String response = runner.getResponseContent();
// here we get the API call endpoint -> in case you need to print it out.
String endPoint = runner.getEndpoint();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM