Nat*_*eed 41 java spring soap web-services spring-mvc
我需要记录所有SOAP请求CommonLogFormat
(请参阅http://en.wikipedia.org/wiki/Common_Log_Format),加上持续时间(处理请求所需的时间).
最好的方法是什么?看起来可以为Spring WebServices配置log4j,但它会记录我感兴趣的所有值吗? http://pijava.wordpress.com/2009/12/04/spring-webservice-soap-requestresponse-logging-with-log4j/
编辑:我们实际上是在使用SLF4J
,而不是Log4j
.此外,看起来可以通过配置PayloadLoggingInterceptor来实现这一点:http://static.springsource.org/spring-ws/site/reference/html/server.html#server-endpoint-interceptor
但我不确定日志消息的去向.我向拦截器添加了拦截器,但没有看到任何日志消息.
Arp*_*wal 52
对于Spring Boot项目,下面添加application.properties
为我工作:
logging.level.org.springframework.web=DEBUG
logging.level.org.springframework.ws.client.MessageTracing.sent=DEBUG
logging.level.org.springframework.ws.server.MessageTracing.sent=DEBUG
logging.level.org.springframework.ws.client.MessageTracing.received=TRACE
logging.level.org.springframework.ws.server.MessageTracing.received=TRACE
Run Code Online (Sandbox Code Playgroud)
Jus*_*KSU 41
您可以使用它来记录传入和传出Web服务调用的原始支付.我不知道如何记录Web服务通信所花费的时间.
<!-- Spring Web Service Payload Logging-->
<logger name="org.springframework.ws.client.MessageTracing">
<level value="TRACE"/>
</logger>
<logger name="org.springframework.ws.server.MessageTracing">
<level value="TRACE"/>
</logger>
Run Code Online (Sandbox Code Playgroud)
有关其他详细信息,请访问http://static.springsource.org/spring-ws/site/reference/html/common.html#logging
Abh*_*pal 21
这对我有用.它记录发送的请求消息和收到的响应.您可以计算从日志中获取的总时间.
log4j.logger.org.springframework.ws.client.MessageTracing.sent=TRACE
log4j.logger.org.springframework.ws.client.MessageTracing.received=TRACE
Run Code Online (Sandbox Code Playgroud)
Rma*_*man 12
如果您有自己的Logging系统,则以下拦截器可以作为记录SOAP消息的替代方法.
setInterceptors(new ClientInterceptor[]{new ClientInterceptor() {
@Override
public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException {
System.out.println("### SOAP RESPONSE ###");
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
messageContext.getResponse().writeTo(buffer);
String payload = buffer.toString(java.nio.charset.StandardCharsets.UTF_8.name());
System.out.println(payload);
} catch (IOException e) {
throw new WebServiceClientException("Can not write the SOAP response into the out stream", e) {
private static final long serialVersionUID = -7118480620416458069L;
};
}
return true;
}
@Override
public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
System.out.println("### SOAP REQUEST ###");
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
messageContext.getRequest().writeTo(buffer);
String payload = buffer.toString(java.nio.charset.StandardCharsets.UTF_8.name());
System.out.println(payload);
} catch (IOException e) {
throw new WebServiceClientException("Can not write the SOAP request into the out stream", e) {
private static final long serialVersionUID = -7118480620416458069L;
};
}
return true;
}
@Override
public boolean handleFault(MessageContext messageContext) throws WebServiceClientException {
System.out.println("### SOAP FAULT ###");
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
messageContext.getResponse().writeTo(buffer);
String payload = buffer.toString(java.nio.charset.StandardCharsets.UTF_8.name());
System.out.println(payload);
} catch (IOException e) {
throw new WebServiceClientException("Can not write the SOAP fault into the out stream", e) {
private static final long serialVersionUID = 3538336091916808141L;
};
}
return true;
}
}});
Run Code Online (Sandbox Code Playgroud)
在每个句柄方法中,您可以轻松地使用payload
获取原始肥皂消息.
首先,SLF4J只是一个简单的外观.这意味着您仍然需要一个日志框架(例如java.util.logging,logback,log4j).
其次,Spring-ws使用Commons Logging接口,这是另一个简单的外观,如SLF4J.
最后,您可以使用以下设置启用Spring-ws消息记录功能.
log4j.logger.org.springframework.ws.client.MessageTracing.sent=DEBUG
log4j.logger.org.springframework.ws.client.MessageTracing.received=TRACE
log4j.logger.org.springframework.ws.server.MessageTracing.sent=DEBUG
log4j.logger.org.springframework.ws.server.MessageTracing.received=TRACE
Run Code Online (Sandbox Code Playgroud)
小智 5
在log4j.properties
文件中包含以下内容......
log4j.logger.org.springframework.ws.server.MessageTracing=DEBUG
log4j.logger.org.springframework.ws.client.MessageTracing=TRACE
在DEBUG
级别上 - 仅记录有效负载根元素
在TRACE
级别上 - 记录整个邮件内容
最后,仅记录已发送或已接收的消息,使用配置.sent
或.received
结尾.
ex:log4j.logger.org.springframework.ws.server.MessageTracing.received=DEBUG
记录客户端接收的按摩有效负载根元素返回:
DEBUG WebServiceMessageReceiverHandlerAdapter:114 - Accepting incoming [org.springframework.ws.transport.http.HttpServletConnection@51ad62d9] to [http://localhost:8080/mock-platform/services]
Run Code Online (Sandbox Code Playgroud)
有关更多信息
归档时间: |
|
查看次数: |
76966 次 |
最近记录: |