我将 SpringWS 用于我的肥皂服务并像这样验证它;
<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>
@PayloadRoot(namespace = NAMESPACE, localPart = "ServiceProvider")
@ResponsePayload
public ServiceProviderTxn getAccountDetails(@RequestPayload ServiceProviderrequest)
{ ...}
这工作正常,但是当出现错误时,它会在到达端点之前返回 spring 生成的错误响应,因此我永远没有机会处理它们。但我希望能够记录完整的错误消息并将其保存到数据库。我发现的一种方法是在我的另一个问题中做类似的事情;
Spring WS 如何在验证失败时获取所有错误消息
但它并没有按照我想要的方式工作。
你可以延长PayloadValidationInterceptor
并重新定义方法
protected boolean handleRequestValidationErrors(MessageContext messageContext, SAXParseException[] errors)
如果您查看标准实现(可用here)您可以看到它如何转储所有解析错误;您还可以转储传入的消息,因为您可以访问 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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)