web services - Java - How to show Soap Fault -
i have kind of response when having soap fault calling java web service
<soap:envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:body> <soap:fault> <faultcode>soap:server</faultcode> <faultstring>fault occurred while processing.</faultstring> <detail> <ns1:waybillregistrationfault xmlns:ns1="http://pod.waybillmanagement.ws.industrysystem.com.ar/"> <errors xmlns:ns2="http://pod.waybillmanagement.ws.industrysystem.com.ar/"> <code>80000</code> <description>el número de ctg 20140904 ya existe</description> </errors> <errors xmlns:ns2="http://pod.waybillmanagement.ws.industrysystem.com.ar/"> <code>1000</code> <description>la carta de porte ya se encuentra registrada.</description> </errors> </ns1:waybillregistrationfault> </detail> </soap:fault> </soap:body> </soap:envelope>
i did soap handler handlefault method this: public boolean handlefault(soapmessagecontext context) {
try { system.err.println("handler handlefault"); if (context.getmessage().getsoapbody().hasfault()) { soapfault fa = context.getmessage().getsoapbody().getfault(); system.err.println(fa.getfaultstring()); system.err.println("faultcode: " + fa.getfaultcode() + " - detail: " + fa.getdetail()); } return true; } catch (soapexception ex) { system.err.println("soapex " + ex.getmessage()); return true; } }
but in output have :
handler handlefault fault occurred while processing. faultcode: soap:server - detail: [detail: null]
how process errors node?
update:
with fa.getdetail().getfirstchild().gettextcontent()
text within xml. how object. waybillregistrationfault think.
if want print fault content xml string , must convert dom instance returned fa.getdetail() string , fa.getdetail().tostring() return ["+getnodename()+": "+getnodevalue()+"]" not content of xml.
try following;
string detailstr=dom2string(fa.getdetail()) system.err.println("faultcode: " + fa.getfaultcode() + " - detail: " + detailstr); public static final string dom2string(node node) { try { if (node == null) { return null; } transformer tf = transformerthreadlocal.get(); // create writer stringwriter sw = new stringwriter(buffer, integer.max_value); streamresult result = new streamresult(sw); // transform tf.transform(new domsource(node), result); return sw.getbuffer(); } catch (exception e) { throw new runtimeexception("could not convert node string", e); } }
Comments
Post a Comment