ActivitiEndpoint.java 6.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.activiti.camel;

16 17 18
import java.util.HashMap;
import java.util.Map;

T
Tijs Rademakers 已提交
19
import org.activiti.engine.ActivitiException;
20
import org.activiti.engine.IdentityService;
21
import org.activiti.engine.RepositoryService;
22
import org.activiti.engine.RuntimeService;
T
Tijs Rademakers 已提交
23 24 25 26 27
import org.apache.camel.CamelContext;
import org.apache.camel.Consumer;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
28
import org.apache.camel.impl.DefaultEndpoint;
T
Tijs Rademakers 已提交
29
import org.apache.commons.lang3.StringUtils;
30

31 32 33 34 35 36
/**
 * This class has been modified to be consistent with the changes to CamelBehavior and its implementations. The set of changes
 * significantly increases the flexibility of our Camel integration, as you can either choose one of three "out-of-the-box" modes,
 * or you can choose to create your own. Please reference the comments for the "CamelBehavior" class for more information on the 
 * out-of-the-box implementation class options.  
 * 
37
 * @author Ryan Johnston (@rjfsu), Tijs Rademakers, Arnold Schrijver
38
 */
39 40
public class ActivitiEndpoint extends DefaultEndpoint {

41
  protected IdentityService identityService;
42

43
  protected RuntimeService runtimeService;
44 45
  
  protected RepositoryService repositoryService;
46

47
  protected ActivitiConsumer activitiConsumer;
48

49
  protected boolean copyVariablesToProperties;
50

51
  protected boolean copyVariablesToBodyAsMap;
52

53
  protected boolean copyCamelBodyToBody;
54
  
55
  protected String copyVariablesFromProperties;
56

57
  protected String copyVariablesFromHeader;
58 59
  
  protected boolean copyCamelBodyToBodyAsString;
60
  
61
  protected String processInitiatorHeaderName;
62
  
63
  protected Map<String, Object> returnVarMap = new HashMap<String, Object>();
64
  
65
  protected long timeout = 5000;
66
  
67
  protected int timeResolution = 100;
68

69
  public ActivitiEndpoint(String uri, CamelContext camelContext) {
70 71 72
    super();
    setCamelContext(camelContext);
    setEndpointUri(uri);
T
Tijs Rademakers 已提交
73
  }
74

75 76
  public void process(Exchange ex) throws Exception {
    if (activitiConsumer == null) {
T
Tijs Rademakers 已提交
77
      throw new ActivitiException("Activiti consumer not defined for " + getEndpointUri());
78
    }
79 80
    activitiConsumer.getProcessor().process(ex);
  }
81

82
  public Producer createProducer() throws Exception {
83 84 85
    ActivitiProducer producer = new ActivitiProducer(this, getTimeout(), getTimeResolution());
    producer.setRuntimeService(runtimeService);
    producer.setIdentityService(identityService);
86
    producer.setRepositoryService(repositoryService);
87
    return producer;
88
  }
89

90 91 92
  public Consumer createConsumer(Processor processor) throws Exception {
    return new ActivitiConsumer(this, processor);
  }
93 94 95
  
  protected void addConsumer(ActivitiConsumer consumer) {
    if (activitiConsumer != null) {
T
Tijs Rademakers 已提交
96
      throw new ActivitiException("Activiti consumer already defined for " + getEndpointUri() + "!");
97 98 99 100 101 102 103
    }
    activitiConsumer = consumer;
  }
  
  protected void removeConsumer() {
    activitiConsumer = null;
  }
104

105 106 107
  public boolean isSingleton() {
    return true;
  }
108 109 110 111 112 113 114 115
  
  public void setIdentityService(IdentityService identityService) {
    this.identityService = identityService;
  }

  public void setRuntimeService(RuntimeService runtimeService) {
    this.runtimeService = runtimeService;
  }
116 117 118 119
  
  public void setRepositoryService(RepositoryService repositoryService) {
    this.repositoryService = repositoryService;
  }
120

121 122 123 124 125 126 127 128
  public boolean isCopyVariablesToProperties() {
    return copyVariablesToProperties;
  }

  public void setCopyVariablesToProperties(boolean copyVariablesToProperties) {
    this.copyVariablesToProperties = copyVariablesToProperties;
  }

129 130
  public boolean isCopyCamelBodyToBody() {
    return copyCamelBodyToBody;
131 132
  }

133 134
  public void setCopyCamelBodyToBody(boolean copyCamelBodyToBody) {
    this.copyCamelBodyToBody = copyCamelBodyToBody;
135 136
  }

137 138 139 140 141 142 143
  public boolean isCopyVariablesToBodyAsMap() {
    return copyVariablesToBodyAsMap;
  }

  public void setCopyVariablesToBodyAsMap(boolean copyVariablesToBodyAsMap) {
    this.copyVariablesToBodyAsMap = copyVariablesToBodyAsMap;
  }
144 145 146 147 148

  public String getCopyVariablesFromProperties() {
    return copyVariablesFromProperties ;
  }

S
Saeid Mirzaei 已提交
149
  
150
  public void setCopyVariablesFromProperties(String copyVariablesFromProperties) {
151 152 153
    this.copyVariablesFromProperties = copyVariablesFromProperties;
  }

154 155
  public String getCopyVariablesFromHeader() {
    return copyVariablesFromHeader;
156
  }
157
  
158
  public void setCopyVariablesFromHeader(String copyVariablesFromHeader) {
159 160 161 162 163 164 165 166 167 168 169
    this.copyVariablesFromHeader = copyVariablesFromHeader;
  }
  
  public boolean isCopyCamelBodyToBodyAsString() {
    return copyCamelBodyToBodyAsString;
  }
  
  public void setCopyCamelBodyToBodyAsString(boolean copyCamelBodyToBodyAsString) {
    this.copyCamelBodyToBodyAsString = copyCamelBodyToBodyAsString;
  }
  
170
  public boolean isSetProcessInitiator() {
171
    return StringUtils.isNotEmpty(getProcessInitiatorHeaderName());
172 173
  }
  
174 175 176 177 178 179 180 181
  public Map<String, Object> getReturnVarMap() {
    return returnVarMap;
  }

  public void setReturnVarMap(Map<String, Object> returnVarMap) {
    this.returnVarMap = returnVarMap;
  }
  
182
  public String getProcessInitiatorHeaderName() {
183
    return processInitiatorHeaderName;
184 185 186
  }
  
  public void setProcessInitiatorHeaderName(String processInitiatorHeaderName) {
187
    this.processInitiatorHeaderName = processInitiatorHeaderName;
188 189
  }
  
190 191 192 193
  @Override
  public boolean isLenientProperties() {
    return true;
  }
194 195 196 197 198 199 200 201
  
  public long getTimeout() {
    return timeout;
  }
  
  public int getTimeResolution() {
    return timeResolution;
  }
202

203
}