Java 如何在SpringWeb服务中将复杂的XML添加到SOAP错误细节中?
}Java 如何在SpringWeb服务中将复杂的XML添加到SOAP错误细节中?,java,spring,soap,soapfault,Java,Spring,Soap,Soapfault,} 但我不知道如何将子元素添加到QName。有人能帮助我如何生成如上所示的故障详细信息吗?这是解决方案 protected void customizeFault(Object endpoint, Exception ex, SoapFault fault) { if (ex instanceof BusinessException) { SoapFaultDetail detail = fault.addFaultDetail(); try
但我不知道如何将子元素添加到QName。有人能帮助我如何生成如上所示的故障详细信息吗?这是解决方案
protected void customizeFault(Object endpoint, Exception ex, SoapFault fault) {
if (ex instanceof BusinessException) {
SoapFaultDetail detail = fault.addFaultDetail();
try
{
QName entryName = new QName("namespace", "confirmIdentityErrorInfo", "NS1");
detail.addFaultDetailElement(entryName);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
更详细的信息如下:
下面是详细的说明
上面的链接不再有效,但下面有一篇文章正是对该解决方案的描述:
public class WebServiceConfig extends WsConfigurerAdapter {
@Bean
public SoapFaultMappingExceptionResolver exceptionResolver(){
SoapFaultMappingExceptionResolver exceptionResolver = new DetailSoapFaultDefinitionExceptionResolver();
SoapFaultDefinition faultDefinition = new SoapFaultDefinition();
faultDefinition.setFaultCode(SoapFaultDefinition.SERVER);
exceptionResolver.setDefaultFault(faultDefinition);
Properties errorMappings = new Properties();
errorMappings.setProperty(Exception.class.getName(), SoapFaultDefinition.SERVER.toString());
errorMappings.setProperty(BusinessException.class.getName(), SoapFaultDefinition.SERVER.toString());
exceptionResolver.setExceptionMappings(errorMappings);
exceptionResolver.setOrder(1);
return exceptionResolver;
}
protected void customizeFault(Object endpoint, Exception ex, SoapFault fault) {
if (ex instanceof BusinessException) {
SoapFaultDetail detail = fault.addFaultDetail();
try
{
QName entryName = new QName("namespace", "confirmIdentityErrorInfo", "NS1");
detail.addFaultDetailElement(entryName);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
fault.addFaultDetail();
this.marshaller.marshal(((AJAXB2MarshalledBusinessException)ex).getMyJAXB2MarshallableComplexMessage(), fault.getFaultDetail().getResult());
public class DetailSoapFaultDefinitionExceptionResolver extends SoapFaultMappingExceptionResolver {
private static final ObjectFactory FACTORY = new ObjectFactory();
private final Marshaller marshaller;
public DetailSoapFaultDefinitionExceptionResolver() throws JAXBException {
JAXBContext jaxbContext = JAXBContext.newInstance("your.schema");
this.marshaller = jaxbContext.createMarshaller();
}
@Override
protected void customizeFault(Object endpoint, Exception e, SoapFault fault) {
YourFault xsdFault = new YourFault();
xsdFault.setCode("UNKNOWN_FAILURE");
xsdFault.setDescription(e.getMessage());
SoapFaultDetail faultDetail = fault.addFaultDetail();
try {
marshaller.marshal(FACTORY.createSubscriptionManagementFault(xsdFault), faultDetail.getResult());
} catch (JAXBException e1) {
log.error("Could not marshall SubscriptionManagementFault", e);
}
}