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