2 * Copyright (C) 2007-2012 Mathieu Baudier
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.ws
.process
;
18 import java
.util
.List
;
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
;
35 public class WebServiceSlcExecutionNotifier
implements SlcExecutionNotifier
{
36 private WebServiceTemplate template
;
38 private Log log
= LogFactory
.getLog(getClass());
40 private Boolean cannotConnect
= false;
42 public void newExecution(ExecutionProcess process
) {
43 SlcExecution slcExecution
= (SlcExecution
) process
;
47 SlcExecutionRequest req
= new SlcExecutionRequest();
48 req
.setSlcExecution(slcExecution
);
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
) {
61 public void updateExecution(SlcExecution slcExecution
) {
65 SlcExecutionRequest req
= new SlcExecutionRequest();
66 req
.setSlcExecution(slcExecution
);
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
) {
79 public void updateStatus(ExecutionProcess process
, String oldStatus
,
81 SlcExecution slcExecution
= (SlcExecution
) process
;
85 SlcExecutionStatusRequest req
= new SlcExecutionStatusRequest(
86 slcExecution
.getUuid(), newStatus
);
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
) {
99 public void addSteps(ExecutionProcess process
,
100 List
<ExecutionStep
> additionalSteps
) {
101 SlcExecution slcExecution
= (SlcExecution
) process
;
105 SlcExecutionStepsRequest req
= new SlcExecutionStepsRequest(
106 slcExecution
.getUuid(), additionalSteps
);
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
);
119 public void setTemplate(WebServiceTemplate template
) {
120 this.template
= template
;
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;