Java 拨号SOAPUI API日志记录
我正在使用为soapweb服务编写集成测试 我的代码与下面的示例代码非常相似:Java 拨号SOAPUI API日志记录,java,log4j,soapui,Java,Log4j,Soapui,我正在使用为soapweb服务编写集成测试 我的代码与下面的示例代码非常相似: // create new project WsdlProject project = new WsdlProject(); // import amazon wsdl WsdlInterface iface = WsdlInterfaceFactory.importWsdl( "http://www.mycorp.com/somewsdl.wsdl", true )[0]; // get desired ope
// create new project
WsdlProject project = new WsdlProject();
// import amazon wsdl
WsdlInterface iface = WsdlInterfaceFactory.importWsdl( "http://www.mycorp.com/somewsdl.wsdl", true )[0];
// get desired operation
WsdlOperation operation = (WsdlOperation) iface.getOperationByName( "MyOperation" );
// create a new empty request for that operation
WsdlRequest request = operation.addNewRequest( "My request" );
// generate the request content from the schema
request.setRequestContent( operation.createRequest( true ) );
// submit the request
WsdlSubmit submit = (WsdlSubmit) request.submit( new WsdlSubmitContext(), false );
// wait for the response
Response response = submit.getResponse();
// print the response
String content = response.getContentAsString();
System.out.println( content );
assertNotNull( content );
assertTrue( content.indexOf( "404 Not Found" ) > 0 );
在我运行这个测试之后,它会向控制台输出大量日志。有没有一种方法可以下载SOAPUI日志
我在jar文件中有相关的SOAPUI代码和它的各种依赖项。如果这个项目使用的是通用的日志框架(我在依赖项中看到了Log4JJAR),有没有办法通过编程设置日志级别
比如
project.setLoggingLevel("INFO");
我已经做到了。您必须创建两个log4j配置文件,因为soapUI使用apachehttpclient,而apachehttpclient也使用log4j。httpclient使用默认的log4j.xml作为类路径资源加载 soapUI将尝试加载名为“soapUI-log4j.xml”的log4j配置文件作为类路径资源(发生在DefaultSoapUICore类中) 您在消息中说您不能更改jar中的log4j.xml,因此您必须通过将新的log4j.xml放在类路径的第一位来覆盖它,以便首先找到它们 下面是我的log4j.xml,用于保持httpclient日志记录的低位:
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console-apache" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyMMdd-HHmmss.SSS} [%t][%-5p] [%c] %m%n" />
</layout>
</appender>
<logger name="org.apache">
<level value="ERROR" />
</logger>
<root>
<level value="ERROR" />
<appender-ref ref="console-apache" />
</root>
</log4j:configuration>
我相信您已经看到了这一点,但是您是否尝试过修改
%SOAPUI\u HOME%\bin\SOAPUI-log4j.xml
?正如我所说,我将SOAPUI代码保存在jar文件中。我没有访问log4j.xml的权限。我想知道API是否允许我这样做。在WsdlProject java文档中,定义了一个记录器,但它是一个受保护的成员。这样如何:
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="console-soapui" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyMMdd-HHmmss.SSS} [%t][%-5p] [%c] %m%n" />
</layout>
</appender>
<logger name="com.eviware">
<level value="INFO" />
</logger>
<root>
<level value="ERROR" />
<appender-ref ref="console-soapui" />
</root>
</log4j:configuration>
-Dsoapui.log4j.config=${yourpath}/log4j-soapui.xml
-Dlog4j.xml=${yourpath}/log4j.xml