2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.
17 package org
.argeo
.slc
.ws
.process
;
19 import java
.util
.List
;
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
;
34 public class WebServiceSlcExecutionNotifier
implements SlcExecutionNotifier
{
35 private WebServiceTemplate template
;
37 private Log log
= LogFactory
.getLog(getClass());
39 private Boolean cannotConnect
= false;
41 public void newExecution(SlcExecution slcExecution
) {
45 SlcExecutionRequest req
= new SlcExecutionRequest();
46 req
.setSlcExecution(slcExecution
);
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
) {
59 public void updateExecution(SlcExecution slcExecution
) {
63 SlcExecutionRequest req
= new SlcExecutionRequest();
64 req
.setSlcExecution(slcExecution
);
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
) {
77 public void updateStatus(SlcExecution slcExecution
, String oldStatus
,
82 SlcExecutionStatusRequest req
= new SlcExecutionStatusRequest(
83 slcExecution
.getUuid(), newStatus
);
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
) {
96 public void addSteps(SlcExecution slcExecution
,
97 List
<SlcExecutionStep
> additionalSteps
) {
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
);
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
);
122 public void setTemplate(WebServiceTemplate template
) {
123 this.template
= template
;
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;