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=9692344877fde1bdbecc46ce750bc858464acf53;hb=fb1f473a0fa4f3b11ebbf7a676983ea946fbdac0;hp=2af13bda8c442a134653235ac081b404634d4c8b;hpb=0b505bbb6ed9b6491dbd1f86f4ad53b4cc87a6f9;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 2af13bda8..969234487 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,68 +1,104 @@ package org.argeo.slc.core.process; -import java.util.Iterator; import java.util.List; -import javax.xml.transform.Source; -import javax.xml.transform.dom.DOMSource; - +import org.springframework.ws.client.WebServiceIOException; 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.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.SlcExecutionStatusRequest; import org.argeo.slc.msg.process.SlcExecutionStepsRequest; +import org.argeo.slc.ws.client.WebServiceUtils; 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); + private Boolean cannotConnect = false; + + public void newExecution(SlcExecution slcExecution) { + if (cannotConnect) + return; + + SlcExecutionRequest req = new SlcExecutionRequest(); + req.setSlcExecution(slcExecution); try { - template.marshalSendAndReceive(req); - if (log.isDebugEnabled()) - log.debug("Added steps to slc execution " + WebServiceUtils.marshalSendAndReceive(template, req); + if (log.isTraceEnabled()) + log.trace("Notified creation of slc execution " + slcExecution.getUuid()); } catch (SoapFaultClientException e) { - manageSoapException(e); + WebServiceUtils.manageSoapException(e); + } catch (WebServiceIOException e) { + manageIoException(e); } } - public void newExecution(SlcExecution slcExecution) { + public void updateExecution(SlcExecution slcExecution) { + if (cannotConnect) + return; + SlcExecutionRequest req = new SlcExecutionRequest(); req.setSlcExecution(slcExecution); try { - template.marshalSendAndReceive(req); - if (log.isDebugEnabled()) - log.debug("Notified creation of slc execution " + WebServiceUtils.marshalSendAndReceive(template, req); + if (log.isTraceEnabled()) + log.trace("Notified update of slc execution " + slcExecution.getUuid()); } catch (SoapFaultClientException e) { - manageSoapException(e); + WebServiceUtils.manageSoapException(e); + } catch (WebServiceIOException e) { + manageIoException(e); } } - public void updateExecution(SlcExecution slcExecution) { - SlcExecutionRequest req = new SlcExecutionRequest(); - req.setSlcExecution(slcExecution); + public void updateStatus(SlcExecution slcExecution, String oldStatus, + String newStatus) { + if (cannotConnect) + return; + + SlcExecutionStatusRequest req = new SlcExecutionStatusRequest( + slcExecution.getUuid(), newStatus); try { - template.marshalSendAndReceive(req); - if (log.isDebugEnabled()) - log.debug("Notify update of slc execution " + WebServiceUtils.marshalSendAndReceive(template, req); + if (log.isTraceEnabled()) + log.trace("Notified status update of slc execution " + slcExecution.getUuid()); } catch (SoapFaultClientException e) { - manageSoapException(e); + WebServiceUtils.manageSoapException(e); + } catch (WebServiceIOException e) { + manageIoException(e); + } + } + + public void addSteps(SlcExecution slcExecution, + List additionalSteps) { + if (cannotConnect) + return; + + SlcExecutionStepsRequest req = new SlcExecutionStepsRequest(); + req.setSlcExecutionUuid(slcExecution.getUuid()); + req.setSteps(additionalSteps); + if (log.isTraceEnabled()) { + for (SlcExecutionStep step : additionalSteps) { + log.trace("Step " + step.getUuid() + ": " + step.logAsString()); + } + } + + try { + WebServiceUtils.marshalSendAndReceive(template, req); + if (log.isTraceEnabled()) + log.trace("Added steps to slc execution " + + slcExecution.getUuid()); + } catch (SoapFaultClientException e) { + WebServiceUtils.manageSoapException(e); + } catch (WebServiceIOException e) { + manageIoException(e); } } @@ -70,28 +106,12 @@ public class WebServiceSlcExecutionNotifier implements SlcExecutionNotifier { 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 void manageIoException(WebServiceIOException e) { + if (!cannotConnect) { + log.error("Cannot connect to " + template.getDefaultUri() + + ". Won't try again.", e); + cannotConnect = true; } } + }