]> git.argeo.org Git - gpl/argeo-slc.git/blob - WebServiceSlcExecutionNotifier.java
d341a63a3409aae9d1805359ca3add5620a6080c
[gpl/argeo-slc.git] / WebServiceSlcExecutionNotifier.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
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 package org.argeo.slc.ws.process;
17
18 import java.util.List;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.argeo.slc.msg.process.SlcExecutionRequest;
23 import org.argeo.slc.msg.process.SlcExecutionStatusRequest;
24 import org.argeo.slc.msg.process.SlcExecutionStepsRequest;
25 import org.argeo.slc.execution.ExecutionStep;
26 import org.argeo.slc.execution.ExecutionProcess;
27 import org.argeo.slc.process.SlcExecution;
28 import org.argeo.slc.process.SlcExecutionNotifier;
29 import org.argeo.slc.process.SlcExecutionStep;
30 import org.argeo.slc.ws.client.WebServiceUtils;
31 import org.springframework.ws.client.WebServiceIOException;
32 import org.springframework.ws.client.core.WebServiceTemplate;
33 import org.springframework.ws.soap.client.SoapFaultClientException;
34
35 public class WebServiceSlcExecutionNotifier implements SlcExecutionNotifier {
36 private WebServiceTemplate template;
37
38 private Log log = LogFactory.getLog(getClass());
39
40 private Boolean cannotConnect = false;
41
42 public void newExecution(ExecutionProcess process) {
43 SlcExecution slcExecution = (SlcExecution) process;
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 creation 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 updateExecution(SlcExecution slcExecution) {
62 if (cannotConnect)
63 return;
64
65 SlcExecutionRequest req = new SlcExecutionRequest();
66 req.setSlcExecution(slcExecution);
67 try {
68 WebServiceUtils.marshalSendAndReceive(template, req);
69 if (log.isTraceEnabled())
70 log.trace("Notified 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 updateStatus(ExecutionProcess process, String oldStatus,
80 String newStatus) {
81 SlcExecution slcExecution = (SlcExecution) process;
82 if (cannotConnect)
83 return;
84
85 SlcExecutionStatusRequest req = new SlcExecutionStatusRequest(
86 slcExecution.getUuid(), newStatus);
87 try {
88 WebServiceUtils.marshalSendAndReceive(template, req);
89 if (log.isTraceEnabled())
90 log.trace("Notified status update of slc execution "
91 + slcExecution.getUuid());
92 } catch (SoapFaultClientException e) {
93 WebServiceUtils.manageSoapException(e);
94 } catch (WebServiceIOException e) {
95 manageIoException(e);
96 }
97 }
98
99 public void addSteps(ExecutionProcess process,
100 List<ExecutionStep> additionalSteps) {
101 SlcExecution slcExecution = (SlcExecution) process;
102 if (cannotConnect)
103 return;
104
105 SlcExecutionStepsRequest req = new SlcExecutionStepsRequest(
106 slcExecution.getUuid(), additionalSteps);
107 try {
108 WebServiceUtils.marshalSendAndReceive(template, req);
109 if (log.isTraceEnabled())
110 log.trace("Added steps to slc execution "
111 + slcExecution.getUuid());
112 } catch (SoapFaultClientException e) {
113 WebServiceUtils.manageSoapException(e);
114 } catch (WebServiceIOException e) {
115 manageIoException(e);
116 }
117 }
118
119 public void setTemplate(WebServiceTemplate template) {
120 this.template = template;
121 }
122
123 protected void manageIoException(WebServiceIOException e) {
124 if (!cannotConnect) {
125 log.error("Cannot connect to " + template.getDefaultUri()
126 + ". Won't try again.", e);
127 cannotConnect = true;
128 }
129 }
130
131 }