1 package org
.argeo
.slc
.core
.process
;
3 import java
.io
.IOException
;
4 import java
.util
.Iterator
;
7 import javax
.xml
.transform
.Source
;
8 import javax
.xml
.transform
.dom
.DOMSource
;
10 import org
.springframework
.oxm
.XmlMappingException
;
11 import org
.springframework
.ws
.client
.core
.WebServiceTemplate
;
12 import org
.springframework
.ws
.soap
.SoapFaultDetail
;
13 import org
.springframework
.ws
.soap
.SoapFaultDetailElement
;
14 import org
.springframework
.ws
.soap
.client
.SoapFaultClientException
;
15 import org
.springframework
.xml
.transform
.StringResult
;
16 import org
.w3c
.dom
.Node
;
18 import com
.ibm
.wsdl
.util
.IOUtils
;
20 import org
.apache
.commons
.logging
.Log
;
21 import org
.apache
.commons
.logging
.LogFactory
;
23 import org
.argeo
.slc
.msg
.process
.SlcExecutionRequest
;
24 import org
.argeo
.slc
.msg
.process
.SlcExecutionStepsRequest
;
26 public class WebServiceSlcExecutionNotifier
implements SlcExecutionNotifier
{
27 private WebServiceTemplate template
;
29 private Log log
= LogFactory
.getLog(getClass());
31 public void addSteps(SlcExecution slcExecution
,
32 List
<SlcExecutionStep
> additionalSteps
) {
33 SlcExecutionStepsRequest req
= new SlcExecutionStepsRequest();
34 req
.setSlcExecutionUuid(slcExecution
.getUuid());
35 req
.setSteps(additionalSteps
);
36 if (log
.isTraceEnabled()) {
37 for (SlcExecutionStep step
: additionalSteps
) {
38 log
.trace("Step " + step
.getUuid() + ": " + step
.logAsString());
43 marshalSendAndReceive(req
);
44 if (log
.isDebugEnabled())
45 log
.debug("Added steps to slc execution "
46 + slcExecution
.getUuid());
47 } catch (SoapFaultClientException e
) {
48 manageSoapException(e
);
52 public void newExecution(SlcExecution slcExecution
) {
53 SlcExecutionRequest req
= new SlcExecutionRequest();
54 req
.setSlcExecution(slcExecution
);
56 marshalSendAndReceive(req
);
57 if (log
.isDebugEnabled())
58 log
.debug("Notified creation of slc execution "
59 + slcExecution
.getUuid());
60 } catch (SoapFaultClientException e
) {
61 manageSoapException(e
);
65 public void updateExecution(SlcExecution slcExecution
) {
66 SlcExecutionRequest req
= new SlcExecutionRequest();
67 req
.setSlcExecution(slcExecution
);
69 marshalSendAndReceive(req
);
70 if (log
.isDebugEnabled())
71 log
.debug("Notified update of slc execution "
72 + slcExecution
.getUuid());
73 } catch (SoapFaultClientException e
) {
74 manageSoapException(e
);
78 public void setTemplate(WebServiceTemplate template
) {
79 this.template
= template
;
82 protected void manageSoapException(SoapFaultClientException e
) {
84 .error("WS root cause: "
85 + e
.getSoapFault().getFaultStringOrReason());
86 StringBuffer stack
= new StringBuffer("");
87 SoapFaultDetail detail
= e
.getSoapFault().getFaultDetail();
89 Iterator
<SoapFaultDetailElement
> it
= (Iterator
<SoapFaultDetailElement
>) detail
91 while (it
.hasNext()) {
92 SoapFaultDetailElement elem
= it
.next();
93 if (elem
.getName().getLocalPart().equals("StackElement")) {
94 Source source
= elem
.getSource();
95 if (source
instanceof DOMSource
) {
96 Node node
= ((DOMSource
) source
).getNode();
97 stack
.append(node
.getTextContent()).append('\n');
102 if (stack
.length() > 0 && log
.isTraceEnabled())
103 log
.error("WS root cause stack: " + stack
);
107 protected Object
marshalSendAndReceive(Object req
) {
108 if (log
.isTraceEnabled()) {
110 StringResult result
= new StringResult();
111 template
.getMarshaller().marshal(req
, result
);
112 log
.trace("About to send " + result
);
113 } catch (Exception e
) {
114 log
.error("Cannot marshall " + req
+ " for logging", e
);
117 Object resp
= template
.marshalSendAndReceive(req
);