Hello stackoverflow用户! 我有错误回复:
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Header/>
<env:Body>
<env:Fault xmlns:ns0="http://xmlns.telenet.be/oss/ninas/v001">
<faultcode>ns0:B-NONUNIQUE-WORKORDERID</faultcode>
<faultstring>Work order ID is not unique</faultstring>
<detail/>
</env:Fault>
</env:Body>
</env:Envelope>
故障代码有一个混合&#34; ns:0&#34;但我需要没有这样的故障代码:
<faultcode>B-NONUNIQUE-WORKORDERID</faultcode>
我的java自定义错误实现在spring ws异常解析器中:
public class OssNinasExceptionResolver extends SoapFaultMappingExceptionResolver implements InitializingBean {
private static final String SCHEMA_URL = "{http://xmlns.telenet.be/oss/ninas/v001}";
protected SoapFaultDefinition getFaultDefinition(Object endpoint, Exception ex) {
SoapFaultDefinition fault = new SoapFaultDefinition();
fault.setLocale(null);
final Throwable rootcause = rootCauseExtractor.extractRootCause(ex);
if (rootcause instanceof RequestValidationException) {
RequestValidationException requestValidationException = (RequestValidationException) rootcause;
fault.setFaultCode(QName.valueOf(SCHEMA_URL + requestValidationException.getCode()));
fault.setFaultStringOrReason(StringUtils.defaultIfBlank(requestValidationException.getDescription(), GENERAL_ERROR));
return fault;
} else {
return null;
}
}
@Override
protected void customizeFault(Object endpoint, Exception ex, SoapFault fault) {
Throwable rootCause = rootCauseExtractor.extractRootCause(ex);
if (rootCause instanceof RequestValidationException) {
String code = ((RequestValidationException) rootCause).getCode();
BaseErrorType errorDetails = createValidationErrorDetails(code, rootCause.getMessage());
final SoapFaultDetail faultDetail = fault.addFaultDetail();
final Result result = faultDetail.getResult();
try {
jaxbContext.createMarshaller().marshal(errorDetails, result);
} catch (JAXBException e) {
LOG.info(e.getMessage());
}
}
}
}
调试会话显示,在异常解析器中处理时,此mixin不会出现。 任何提示都表明这件事会消失吗?
答案 0 :(得分:0)
ns0
是名称空间前缀(在XML规范中的任何地方都没有“mixin”这样的概念)。在faultcode
元素的范围内,该名称空间前缀绑定到名称空间URI http://xmlns.telenet.be/oss/ninas/v001
。这意味着故障代码具有名称空间URI http://xmlns.telenet.be/oss/ninas/v001
和本地部分B-NONUNIQUE-WORKORDERID
,这正是您在代码中请求的内容:
fault.setFaultCode(QName.valueOf(SCHEMA_URL + requestValidationException.getCode()))