X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fprocess%2FWebServiceSlcExecutionNotifier.java;h=2c6c8883b16164661306a2dbe0ab77a4629edb5b;hb=c2107fa018f358d94865227bc19a5691403178cc;hp=619336e868924b66194f5dd0d961ffe88d62ec91;hpb=07315a82eb7fa5b84db60209dbf03bd94568321c;p=gpl%2Fargeo-slc.git diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/process/WebServiceSlcExecutionNotifier.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/process/WebServiceSlcExecutionNotifier.java index 619336e86..2c6c8883b 100644 --- a/org.argeo.slc.core/src/main/java/org/argeo/slc/core/process/WebServiceSlcExecutionNotifier.java +++ b/org.argeo.slc.core/src/main/java/org/argeo/slc/core/process/WebServiceSlcExecutionNotifier.java @@ -1,9 +1,24 @@ package org.argeo.slc.core.process; +import java.io.IOException; +import java.util.Iterator; import java.util.List; +import javax.xml.transform.Source; +import javax.xml.transform.dom.DOMSource; + +import org.springframework.oxm.XmlMappingException; import org.springframework.ws.client.core.WebServiceTemplate; +import org.springframework.ws.soap.SoapFaultDetail; +import org.springframework.ws.soap.SoapFaultDetailElement; import org.springframework.ws.soap.client.SoapFaultClientException; +import org.springframework.xml.transform.StringResult; +import org.w3c.dom.Node; + +import com.ibm.wsdl.util.IOUtils; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.argeo.slc.msg.process.SlcExecutionRequest; import org.argeo.slc.msg.process.SlcExecutionStepsRequest; @@ -11,28 +26,95 @@ import org.argeo.slc.msg.process.SlcExecutionStepsRequest; public class WebServiceSlcExecutionNotifier implements SlcExecutionNotifier { private WebServiceTemplate template; + private Log log = LogFactory.getLog(getClass()); + public void addSteps(SlcExecution slcExecution, List additionalSteps) { SlcExecutionStepsRequest req = new SlcExecutionStepsRequest(); req.setSlcExecutionUuid(slcExecution.getUuid()); req.setSteps(additionalSteps); - template.marshalSendAndReceive(req); + if (log.isTraceEnabled()) { + for (SlcExecutionStep step : additionalSteps) { + log.trace("Step " + step.getUuid() + ": " + step.logAsString()); + } + } + + try { + marshalSendAndReceive(req); + if (log.isDebugEnabled()) + log.debug("Added steps to slc execution " + + slcExecution.getUuid()); + } catch (SoapFaultClientException e) { + manageSoapException(e); + } } public void newExecution(SlcExecution slcExecution) { SlcExecutionRequest req = new SlcExecutionRequest(); req.setSlcExecution(slcExecution); - template.marshalSendAndReceive(req); + try { + marshalSendAndReceive(req); + if (log.isDebugEnabled()) + log.debug("Notified creation of slc execution " + + slcExecution.getUuid()); + } catch (SoapFaultClientException e) { + manageSoapException(e); + } } public void updateExecution(SlcExecution slcExecution) { SlcExecutionRequest req = new SlcExecutionRequest(); req.setSlcExecution(slcExecution); - template.marshalSendAndReceive(req); + try { + marshalSendAndReceive(req); + if (log.isDebugEnabled()) + log.debug("Notified update of slc execution " + + slcExecution.getUuid()); + } catch (SoapFaultClientException e) { + manageSoapException(e); + } } public void setTemplate(WebServiceTemplate template) { this.template = template; } + protected void manageSoapException(SoapFaultClientException e) { + log + .error("WS root cause: " + + e.getSoapFault().getFaultStringOrReason()); + StringBuffer stack = new StringBuffer(""); + SoapFaultDetail detail = e.getSoapFault().getFaultDetail(); + if (detail != null) { + Iterator it = (Iterator) detail + .getDetailEntries(); + while (it.hasNext()) { + SoapFaultDetailElement elem = it.next(); + if (elem.getName().getLocalPart().equals("StackElement")) { + Source source = elem.getSource(); + if (source instanceof DOMSource) { + Node node = ((DOMSource) source).getNode(); + stack.append(node.getTextContent()).append('\n'); + } + } + } + + if (stack.length() > 0 && log.isTraceEnabled()) + log.error("WS root cause stack: " + stack); + } + } + + protected Object marshalSendAndReceive(Object req) { + if (log.isTraceEnabled()) { + try { + StringResult result = new StringResult(); + template.getMarshaller().marshal(req, result); + log.trace("About to send " + result); + } catch (Exception e) { + log.error("Cannot marshall " + req + " for logging", e); + } + } + Object resp = template.marshalSendAndReceive(req); + return resp; + } }