Hi,
It looks like the transformer does not like the format of the xml message if they are not within a element. If I add a dummy test element it's working:
Code:
<detail>
<e:myfaultdetails xmlns:e="Some-URI">
<test>
<message>
My application didn't work
</message>
<text>
More information...
</text>
</test>
</e:myfaultdetails>
</detail>
Here is the code:
Code:
private static final QName SERVICE_EXCEPTION_QNAME = new QName("http://www.mycompagny.com/services/project/wsdl/holiday", "ServiceExceptionDetail", "holi");
@Override
protected void customizeFault(Object endpoint, Exception serviceException, SoapFault soapFault)
{
try
{
assert serviceException instanceof ProjectWebServiceException:"exception should be instanceof ProjectWebServiceException";
ProjectWebServiceException pwsException = (ProjectWebServiceException) serviceException;
SoapFaultDetail soapFaultDetail = soapFault.addFaultDetail();
ServiceExceptionDetail sed = pwsException.getDetails();
SoapFaultDetailElement el = soapFaultDetail.addFaultDetailElement(SERVICE_EXCEPTION_QNAME);
Source elSource = new StringSource(createXmlServiceExceptionDetails(sed));
Transformer transformer;
transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(elSource, el.getResult());
}
catch(TransformerConfigurationException e)
{
e.printStackTrace();
}
catch(TransformerFactoryConfigurationError e)
{
e.printStackTrace();
}
catch(TransformerException e)
{
e.printStackTrace();
}
}
private static String createXmlServiceExceptionDetails(ServiceExceptionDetail exDetail)
{
StringBuilder sb = new StringBuilder();
//sb.append("<test>"); //Its working if I use that dummy element level.
sb.append("<messageId>\n\t").append(exDetail.getMessageId()).append("\n</messageId>");
sb.append("<text>\n\t").append(exDetail.getText()).append("\n</text>");
//sb.append("</test>");
return sb.toString();
}
I try to modify the xml message by using "\n\t" or spaces or nothing between element but its always the same result.
mapospring