1 package org
.argeo
.slc
.ws
.client
;
3 import java
.util
.Iterator
;
5 import javax
.xml
.transform
.Source
;
6 import javax
.xml
.transform
.dom
.DOMSource
;
8 import org
.springframework
.ws
.client
.core
.WebServiceTemplate
;
9 import org
.springframework
.ws
.soap
.SoapFaultDetail
;
10 import org
.springframework
.ws
.soap
.SoapFaultDetailElement
;
11 import org
.springframework
.ws
.soap
.client
.SoapFaultClientException
;
12 import org
.springframework
.xml
.transform
.StringResult
;
13 import org
.w3c
.dom
.Node
;
15 import org
.apache
.commons
.logging
.Log
;
16 import org
.apache
.commons
.logging
.LogFactory
;
18 public abstract class WebServiceUtils
{
19 private final static Log log
= LogFactory
.getLog(WebServiceUtils
.class);
21 public static Object
marshalSendAndReceive(WebServiceTemplate template
,
23 if (log
.isTraceEnabled()) {
25 StringResult result
= new StringResult();
26 template
.getMarshaller().marshal(req
, result
);
27 log
.trace("About to send " + result
);
28 } catch (Exception e
) {
29 log
.error("Cannot marshall " + req
+ " for logging", e
);
32 Object resp
= template
.marshalSendAndReceive(req
);
36 public static void manageSoapException(SoapFaultClientException e
) {
38 .error("WS root cause: "
39 + e
.getSoapFault().getFaultStringOrReason());
40 StringBuffer stack
= new StringBuffer("");
41 SoapFaultDetail detail
= e
.getSoapFault().getFaultDetail();
43 Iterator
<SoapFaultDetailElement
> it
= (Iterator
<SoapFaultDetailElement
>) detail
45 while (it
.hasNext()) {
46 SoapFaultDetailElement elem
= it
.next();
47 if (elem
.getName().getLocalPart().equals("StackElement")) {
48 Source source
= elem
.getSource();
49 if (source
instanceof DOMSource
) {
50 Node node
= ((DOMSource
) source
).getNode();
51 stack
.append(node
.getTextContent()).append('\n');
56 if (stack
.length() > 0 && log
.isTraceEnabled())
57 log
.error("WS root cause stack: " + stack
);
61 private WebServiceUtils() {