]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.launcher/src/main/java/org/argeo/slc/ws/process/WebServiceSlcExecutionNotifier.java
Introduce org.argeo.slc.lib.detached
[gpl/argeo-slc.git] / runtime / org.argeo.slc.launcher / src / main / java / org / argeo / slc / ws / process / WebServiceSlcExecutionNotifier.java
1 package org.argeo.slc.ws.process;
2
3 import java.util.List;
4
5 import org.apache.commons.logging.Log;
6 import org.apache.commons.logging.LogFactory;
7 import org.argeo.slc.core.process.SlcExecution;
8 import org.argeo.slc.core.process.SlcExecutionNotifier;
9 import org.argeo.slc.core.process.SlcExecutionStep;
10 import org.argeo.slc.msg.process.SlcExecutionRequest;
11 import org.argeo.slc.msg.process.SlcExecutionStatusRequest;
12 import org.argeo.slc.msg.process.SlcExecutionStepsRequest;
13 import org.argeo.slc.ws.client.WebServiceUtils;
14 import org.springframework.ws.client.WebServiceIOException;
15 import org.springframework.ws.client.core.WebServiceTemplate;
16 import org.springframework.ws.soap.client.SoapFaultClientException;
17
18 public class WebServiceSlcExecutionNotifier implements SlcExecutionNotifier {
19 private WebServiceTemplate template;
20
21 private Log log = LogFactory.getLog(getClass());
22
23 private Boolean cannotConnect = false;
24
25 public void newExecution(SlcExecution slcExecution) {
26 if (cannotConnect)
27 return;
28
29 SlcExecutionRequest req = new SlcExecutionRequest();
30 req.setSlcExecution(slcExecution);
31 try {
32 WebServiceUtils.marshalSendAndReceive(template, req);
33 if (log.isTraceEnabled())
34 log.trace("Notified creation of slc execution "
35 + slcExecution.getUuid());
36 } catch (SoapFaultClientException e) {
37 WebServiceUtils.manageSoapException(e);
38 } catch (WebServiceIOException e) {
39 manageIoException(e);
40 }
41 }
42
43 public void updateExecution(SlcExecution slcExecution) {
44 if (cannotConnect)
45 return;
46
47 SlcExecutionRequest req = new SlcExecutionRequest();
48 req.setSlcExecution(slcExecution);
49 try {
50 WebServiceUtils.marshalSendAndReceive(template, req);
51 if (log.isTraceEnabled())
52 log.trace("Notified update of slc execution "
53 + slcExecution.getUuid());
54 } catch (SoapFaultClientException e) {
55 WebServiceUtils.manageSoapException(e);
56 } catch (WebServiceIOException e) {
57 manageIoException(e);
58 }
59 }
60
61 public void updateStatus(SlcExecution slcExecution, String oldStatus,
62 String newStatus) {
63 if (cannotConnect)
64 return;
65
66 SlcExecutionStatusRequest req = new SlcExecutionStatusRequest(
67 slcExecution.getUuid(), newStatus);
68 try {
69 WebServiceUtils.marshalSendAndReceive(template, req);
70 if (log.isTraceEnabled())
71 log.trace("Notified status update of slc execution "
72 + slcExecution.getUuid());
73 } catch (SoapFaultClientException e) {
74 WebServiceUtils.manageSoapException(e);
75 } catch (WebServiceIOException e) {
76 manageIoException(e);
77 }
78 }
79
80 public void addSteps(SlcExecution slcExecution,
81 List<SlcExecutionStep> additionalSteps) {
82 if (cannotConnect)
83 return;
84
85 SlcExecutionStepsRequest req = new SlcExecutionStepsRequest();
86 req.setSlcExecutionUuid(slcExecution.getUuid());
87 req.setSteps(additionalSteps);
88 if (log.isTraceEnabled()) {
89 for (SlcExecutionStep step : additionalSteps) {
90 log.trace("Step " + step.getUuid() + ": " + step.logAsString());
91 }
92 }
93
94 try {
95 WebServiceUtils.marshalSendAndReceive(template, req);
96 if (log.isTraceEnabled())
97 log.trace("Added steps to slc execution "
98 + slcExecution.getUuid());
99 } catch (SoapFaultClientException e) {
100 WebServiceUtils.manageSoapException(e);
101 } catch (WebServiceIOException e) {
102 manageIoException(e);
103 }
104 }
105
106 public void setTemplate(WebServiceTemplate template) {
107 this.template = template;
108 }
109
110 protected void manageIoException(WebServiceIOException e) {
111 if (!cannotConnect) {
112 log.error("Cannot connect to " + template.getDefaultUri()
113 + ". Won't try again.", e);
114 cannotConnect = true;
115 }
116 }
117
118 }