Spr*_*ing 12 java spring spring-ws
我使用SpringWS作为我的soap服务并像这样验证它;
<sws:interceptors>
<bean id="payloadValidatingInterceptor" class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
<property name="schema" value="/schemas/my.xsd"/>
<property name="validateRequest" value="false"/>
<property name="validateResponse" value="true"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
@PayloadRoot(namespace = NAMESPACE, localPart = "ServiceProvider")
@ResponsePayload
public ServiceProviderTxn getAccountDetails(@RequestPayload ServiceProviderrequest)
{ ...}
Run Code Online (Sandbox Code Playgroud)
这样可以正常工作,但是当出现错误时,它会在到达端点之前返回弹簧生成的错误响应,因此我从来没有机会处理它们.但我希望能够将完整的错误消息记录并保存到数据库.我发现的一种方法是在我的另一个问题中做这样的事情;
但它不能按我的意愿工作.
您可以扩展PayloadValidationInterceptor和重新定义该方法
protected boolean handleRequestValidationErrors(MessageContext messageContext, SAXParseException[] errors)
Run Code Online (Sandbox Code Playgroud)
如果你看一下标准的实现(这里有)你可以看到它如何转储所有的解析错误; 您也可以转储传入的消息,因为您可以访问messageContext及其getRequest()方法.你的班级应该是这样的
public class PayloadValidationgInterceptorCustom extends
PayloadValidatingInterceptor {
@Override
protected boolean handleRequestValidationErrors(MessageContext messageContext, SAXParseException[] errors)
throws TransformerException {
messageContext.getRequest().writeTo(/*place your Outputstream here something like a ByteArrayOutputStream*/); //use this if you want to dump the message
for (SAXParseException error : errors) {
//dump the each error on the db o collect the stack traces in a single string and dump only one or to the database
/*you can use something like this
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
error.printStackTrace(pw);
sw.toString();
to get the stack trace
*/
}
return super.handleRequestValidationErrors(messageContext,errors);
}
Run Code Online (Sandbox Code Playgroud)