]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.ws.client/src/main/java/org/argeo/slc/ws/process/WebServiceSlcExecutionNotifier.java
cae997b689a3653749d841c536ce3f508f94889e
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.ws.client / src / main / java / org / argeo / slc / ws / process / WebServiceSlcExecutionNotifier.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.argeo.slc.ws.process;
18
19 import java.util.List;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.argeo.slc.msg.process.SlcExecutionRequest;
24 import org.argeo.slc.msg.process.SlcExecutionStatusRequest;
25 import org.argeo.slc.msg.process.SlcExecutionStepsRequest;
26 import org.argeo.slc.process.SlcExecution;
27 import org.argeo.slc.process.SlcExecutionNotifier;
28 import org.argeo.slc.process.SlcExecutionStep;
29 import org.argeo.slc.ws.client.WebServiceUtils;
30 import org.springframework.ws.client.WebServiceIOException;
31 import org.springframework.ws.client.core.WebServiceTemplate;
32 import org.springframework.ws.soap.client.SoapFaultClientException;
33
34 public class WebServiceSlcExecutionNotifier implements SlcExecutionNotifier {
35 private WebServiceTemplate template;
36
37 private Log log = LogFactory.getLog(getClass());
38
39 private Boolean cannotConnect = false;
40
41 public void newExecution(SlcExecution slcExecution) {
42 if (cannotConnect)
43 return;
44
45 SlcExecutionRequest req = new SlcExecutionRequest();
46 req.setSlcExecution(slcExecution);
47 try {
48 WebServiceUtils.marshalSendAndReceive(template, req);
49 if (log.isTraceEnabled())
50 log.trace("Notified creation of slc execution "
51 + slcExecution.getUuid());
52 } catch (SoapFaultClientException e) {
53 WebServiceUtils.manageSoapException(e);
54 } catch (WebServiceIOException e) {
55 manageIoException(e);
56 }
57 }
58
59 public void updateExecution(SlcExecution slcExecution) {
60 if (cannotConnect)
61 return;
62
63 SlcExecutionRequest req = new SlcExecutionRequest();
64 req.setSlcExecution(slcExecution);
65 try {
66 WebServiceUtils.marshalSendAndReceive(template, req);
67 if (log.isTraceEnabled())
68 log.trace("Notified update of slc execution "
69 + slcExecution.getUuid());
70 } catch (SoapFaultClientException e) {
71 WebServiceUtils.manageSoapException(e);
72 } catch (WebServiceIOException e) {
73 manageIoException(e);
74 }
75 }
76
77 public void updateStatus(SlcExecution slcExecution, String oldStatus,
78 String newStatus) {
79 if (cannotConnect)
80 return;
81
82 SlcExecutionStatusRequest req = new SlcExecutionStatusRequest(
83 slcExecution.getUuid(), newStatus);
84 try {
85 WebServiceUtils.marshalSendAndReceive(template, req);
86 if (log.isTraceEnabled())
87 log.trace("Notified status update of slc execution "
88 + slcExecution.getUuid());
89 } catch (SoapFaultClientException e) {
90 WebServiceUtils.manageSoapException(e);
91 } catch (WebServiceIOException e) {
92 manageIoException(e);
93 }
94 }
95
96 public void addSteps(SlcExecution slcExecution,
97 List<SlcExecutionStep> additionalSteps) {
98 if (cannotConnect)
99 return;
100
101 SlcExecutionStepsRequest req = new SlcExecutionStepsRequest();
102 req.setSlcExecutionUuid(slcExecution.getUuid());
103 req.setSteps(additionalSteps);
104 if (log.isTraceEnabled()) {
105 for (SlcExecutionStep step : additionalSteps) {
106 log.trace("Step " + step.getUuid() + ": " + step);
107 }
108 }
109
110 try {
111 WebServiceUtils.marshalSendAndReceive(template, req);
112 if (log.isTraceEnabled())
113 log.trace("Added steps to slc execution "
114 + slcExecution.getUuid());
115 } catch (SoapFaultClientException e) {
116 WebServiceUtils.manageSoapException(e);
117 } catch (WebServiceIOException e) {
118 manageIoException(e);
119 }
120 }
121
122 public void setTemplate(WebServiceTemplate template) {
123 this.template = template;
124 }
125
126 protected void manageIoException(WebServiceIOException e) {
127 if (!cannotConnect) {
128 log.error("Cannot connect to " + template.getDefaultUri()
129 + ". Won't try again.", e);
130 cannotConnect = true;
131 }
132 }
133
134 }