2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org
.argeo
.slc
.ws
.client
;
19 import java
.util
.Iterator
;
21 import javax
.xml
.transform
.Source
;
22 import javax
.xml
.transform
.dom
.DOMSource
;
24 import org
.apache
.commons
.logging
.Log
;
25 import org
.apache
.commons
.logging
.LogFactory
;
26 import org
.springframework
.ws
.client
.core
.WebServiceTemplate
;
27 import org
.springframework
.ws
.soap
.SoapFaultDetail
;
28 import org
.springframework
.ws
.soap
.SoapFaultDetailElement
;
29 import org
.springframework
.ws
.soap
.client
.SoapFaultClientException
;
30 import org
.springframework
.xml
.transform
.StringResult
;
31 import org
.w3c
.dom
.Node
;
33 public abstract class WebServiceUtils
{
34 private final static Log log
= LogFactory
.getLog(WebServiceUtils
.class);
36 public static Object
marshalSendAndReceiveSafe(WebServiceTemplate template
,
39 Object resp
= marshalSendAndReceive(template
, req
);
41 } catch (Exception e
) {
42 log
.error("Cannot send web servicerequest: " + e
.getMessage());
43 if (log
.isDebugEnabled()) {
44 log
.debug("Webservice exception details: ", e
);
50 public static Object
marshalSendAndReceive(WebServiceTemplate template
,
52 if (log
.isTraceEnabled()) {
54 StringResult result
= new StringResult();
55 template
.getMarshaller().marshal(req
, result
);
56 log
.trace("About to send " + result
);
57 } catch (Exception e
) {
58 log
.error("Cannot marshall " + req
+ " for logging", e
);
61 Object resp
= template
.marshalSendAndReceive(req
);
65 public static void manageSoapException(SoapFaultClientException e
) {
67 .error("WS root cause: "
68 + e
.getSoapFault().getFaultStringOrReason());
69 if (log
.isTraceEnabled()) {
70 StringBuffer stack
= new StringBuffer("");
71 SoapFaultDetail detail
= e
.getSoapFault().getFaultDetail();
73 Iterator
<SoapFaultDetailElement
> it
= (Iterator
<SoapFaultDetailElement
>) detail
75 while (it
.hasNext()) {
76 SoapFaultDetailElement elem
= it
.next();
77 if (elem
.getName().getLocalPart().equals("StackElement")) {
78 Source source
= elem
.getSource();
79 if (source
instanceof DOMSource
) {
80 Node node
= ((DOMSource
) source
).getNode();
81 // stack.append(node.getTextContent()).append('\n');
84 node
.getChildNodes().item(0)
85 .getNodeValue()).append(
91 if (stack
.length() > 0)
92 log
.error("WS root cause stack: " + stack
);
97 private WebServiceUtils() {