| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.ksb.api.bus.support; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
| 20 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
| 21 | |
import org.apache.commons.lang.builder.ReflectionToStringBuilder; |
| 22 | |
import org.apache.log4j.Logger; |
| 23 | |
import org.kuali.rice.core.api.CoreConstants; |
| 24 | |
import org.kuali.rice.core.api.config.ConfigurationException; |
| 25 | |
import org.kuali.rice.core.api.config.CoreConfigHelper; |
| 26 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
| 27 | |
import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; |
| 28 | |
import org.kuali.rice.core.api.security.credentials.CredentialsType; |
| 29 | |
import org.kuali.rice.core.api.util.ClassLoaderUtils; |
| 30 | |
import org.kuali.rice.ksb.api.bus.Endpoint; |
| 31 | |
import org.kuali.rice.ksb.api.bus.ServiceConfiguration; |
| 32 | |
import org.kuali.rice.ksb.api.bus.ServiceDefinition; |
| 33 | |
|
| 34 | |
import javax.xml.namespace.QName; |
| 35 | |
import java.net.URL; |
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
public abstract class AbstractServiceDefinition implements ServiceDefinition { |
| 44 | |
|
| 45 | 0 | private static final Logger LOG = Logger.getLogger(AbstractServiceDefinition.class); |
| 46 | |
|
| 47 | |
|
| 48 | |
private String localServiceName; |
| 49 | |
private String serviceNameSpaceURI; |
| 50 | |
|
| 51 | |
private Object service; |
| 52 | |
private QName serviceName; |
| 53 | |
private boolean queue; |
| 54 | |
private Integer priority; |
| 55 | |
private Integer retryAttempts; |
| 56 | |
private Long millisToLive; |
| 57 | |
private String messageExceptionHandler; |
| 58 | |
private String servicePath; |
| 59 | |
private URL endpointUrl; |
| 60 | |
private Boolean busSecurity; |
| 61 | |
private CredentialsType credentialsType; |
| 62 | |
private String serviceVersion; |
| 63 | |
private String applicationId; |
| 64 | |
private String instanceId; |
| 65 | |
|
| 66 | |
|
| 67 | |
private ClassLoader serviceClassLoader; |
| 68 | |
private String cacheManager; |
| 69 | |
|
| 70 | 0 | protected AbstractServiceDefinition() { |
| 71 | 0 | this.busSecurity = Boolean.TRUE; |
| 72 | 0 | this.queue = true; |
| 73 | 0 | this.serviceClassLoader = ClassLoaderUtils.getDefaultClassLoader(); |
| 74 | 0 | } |
| 75 | |
|
| 76 | |
public Object getService() { |
| 77 | 0 | return this.service; |
| 78 | |
} |
| 79 | |
public void setService(Object service) { |
| 80 | 0 | this.service = service; |
| 81 | 0 | } |
| 82 | |
|
| 83 | |
public String getLocalServiceName() { |
| 84 | 0 | return this.localServiceName; |
| 85 | |
} |
| 86 | |
|
| 87 | |
public void setLocalServiceName(String serviceName) { |
| 88 | 0 | this.localServiceName = serviceName; |
| 89 | 0 | } |
| 90 | |
|
| 91 | |
public String getMessageExceptionHandler() { |
| 92 | 0 | return this.messageExceptionHandler; |
| 93 | |
} |
| 94 | |
|
| 95 | |
public void setMessageExceptionHandler(String messageExceptionHandler) { |
| 96 | 0 | this.messageExceptionHandler = messageExceptionHandler; |
| 97 | 0 | } |
| 98 | |
|
| 99 | |
public Integer getPriority() { |
| 100 | 0 | return this.priority; |
| 101 | |
} |
| 102 | |
|
| 103 | |
public void setPriority(Integer priority) { |
| 104 | 0 | this.priority = priority; |
| 105 | 0 | } |
| 106 | |
|
| 107 | |
public boolean isQueue() { |
| 108 | 0 | return this.queue; |
| 109 | |
} |
| 110 | |
|
| 111 | |
public void setQueue(boolean queue) { |
| 112 | 0 | this.queue = queue; |
| 113 | 0 | } |
| 114 | |
|
| 115 | |
public Integer getRetryAttempts() { |
| 116 | 0 | return this.retryAttempts; |
| 117 | |
} |
| 118 | |
|
| 119 | |
public void setRetryAttempts(Integer retryAttempts) { |
| 120 | 0 | this.retryAttempts = retryAttempts; |
| 121 | 0 | } |
| 122 | |
|
| 123 | |
public QName getServiceName() { |
| 124 | 0 | if (this.serviceName == null) { |
| 125 | 0 | if (this.serviceNameSpaceURI == null) { |
| 126 | 0 | return new QName(this.applicationId, this.localServiceName); |
| 127 | |
} else { |
| 128 | 0 | return new QName(this.serviceNameSpaceURI, this.localServiceName); |
| 129 | |
} |
| 130 | |
|
| 131 | |
} |
| 132 | 0 | return this.serviceName; |
| 133 | |
} |
| 134 | |
public void setServiceName(QName serviceName) { |
| 135 | 0 | this.serviceName = serviceName; |
| 136 | 0 | } |
| 137 | |
|
| 138 | |
@Override |
| 139 | |
public URL getEndpointUrl() { |
| 140 | 0 | return this.endpointUrl; |
| 141 | |
} |
| 142 | |
public void setEndpointUrl(URL endpointUrl) { |
| 143 | 0 | this.endpointUrl = endpointUrl; |
| 144 | 0 | } |
| 145 | |
|
| 146 | |
public void setCredentialsType(CredentialsType credentialsType) { |
| 147 | 0 | this.credentialsType = credentialsType; |
| 148 | 0 | } |
| 149 | |
|
| 150 | |
public CredentialsType getCredentialsType() { |
| 151 | 0 | return this.credentialsType; |
| 152 | |
} |
| 153 | |
|
| 154 | |
public String getServiceVersion() { |
| 155 | 0 | return serviceVersion; |
| 156 | |
} |
| 157 | |
|
| 158 | |
public void setServiceVersion(String serviceVersion) { |
| 159 | 0 | this.serviceVersion = serviceVersion; |
| 160 | 0 | } |
| 161 | |
|
| 162 | |
public String getApplicationId() { |
| 163 | 0 | return applicationId; |
| 164 | |
} |
| 165 | |
|
| 166 | |
public void setApplicationId(String applicationId) { |
| 167 | 0 | this.applicationId = applicationId; |
| 168 | 0 | } |
| 169 | |
|
| 170 | |
@Override |
| 171 | |
public String getInstanceId() { |
| 172 | 0 | return instanceId; |
| 173 | |
} |
| 174 | |
|
| 175 | |
public void setInstanceId(String instanceId) { |
| 176 | 0 | this.instanceId = instanceId; |
| 177 | 0 | } |
| 178 | |
|
| 179 | |
@Override |
| 180 | |
public ClassLoader getServiceClassLoader() { |
| 181 | 0 | return this.serviceClassLoader; |
| 182 | |
} |
| 183 | |
|
| 184 | |
public void setServiceClassLoader(ClassLoader serviceClassLoader) { |
| 185 | 0 | this.serviceClassLoader = serviceClassLoader; |
| 186 | 0 | } |
| 187 | |
|
| 188 | |
@Override |
| 189 | |
public String getCacheManager() { |
| 190 | 0 | return cacheManager; |
| 191 | |
} |
| 192 | |
|
| 193 | |
public void setCacheManager(String cacheManager) { |
| 194 | 0 | this.cacheManager = cacheManager; |
| 195 | 0 | } |
| 196 | |
|
| 197 | |
@Override |
| 198 | |
public void validate() { |
| 199 | |
|
| 200 | 0 | if (this.serviceName == null && this.localServiceName == null) { |
| 201 | 0 | throw new ConfigurationException("Must give a serviceName or localServiceName"); |
| 202 | |
} |
| 203 | |
|
| 204 | 0 | if (this.applicationId == null) { |
| 205 | 0 | String applicationId = CoreConfigHelper.getApplicationId(); |
| 206 | 0 | if (applicationId == null) { |
| 207 | 0 | throw new ConfigurationException("Must have an applicationId"); |
| 208 | |
} |
| 209 | 0 | this.applicationId = applicationId; |
| 210 | |
} |
| 211 | |
|
| 212 | 0 | if (this.instanceId == null) { |
| 213 | 0 | String instanceId = CoreConfigHelper.getInstanceId(); |
| 214 | 0 | if (instanceId == null) { |
| 215 | 0 | throw new ConfigurationException("Must have an instanceId"); |
| 216 | |
} |
| 217 | 0 | this.instanceId = instanceId; |
| 218 | |
} |
| 219 | |
|
| 220 | 0 | if (this.serviceName != null && this.localServiceName == null) { |
| 221 | 0 | this.localServiceName = this.getServiceName().getLocalPart(); |
| 222 | |
} |
| 223 | |
|
| 224 | 0 | if (this.servicePath != null){ |
| 225 | 0 | if (this.servicePath.endsWith("/")){ |
| 226 | 0 | this.servicePath = StringUtils.chop(servicePath); |
| 227 | |
} |
| 228 | 0 | if (!this.servicePath.startsWith("/")){ |
| 229 | 0 | this.servicePath = "/" + this.servicePath; |
| 230 | |
} |
| 231 | |
} else { |
| 232 | |
|
| 233 | 0 | this.servicePath = "/"; |
| 234 | |
} |
| 235 | |
|
| 236 | |
|
| 237 | 0 | if (StringUtils.isBlank(serviceVersion)) { |
| 238 | 0 | setServiceVersion(CoreConstants.Versions.UNSPECIFIED); |
| 239 | |
} |
| 240 | |
|
| 241 | 0 | LOG.debug("Validating service " + this.serviceName); |
| 242 | |
|
| 243 | |
|
| 244 | 0 | if (this.endpointUrl == null) { |
| 245 | 0 | String endPointURL = ConfigContext.getCurrentContextConfig().getEndPointUrl(); |
| 246 | 0 | if (endPointURL == null) { |
| 247 | 0 | throw new ConfigurationException("Must provide a serviceEndPoint or serviceServletURL"); |
| 248 | |
} |
| 249 | 0 | if (! endPointURL.endsWith("/")) { |
| 250 | 0 | endPointURL += servicePath; |
| 251 | |
} else { |
| 252 | 0 | endPointURL = StringUtils.chop(endPointURL) + servicePath; |
| 253 | |
} |
| 254 | |
try { |
| 255 | 0 | if (servicePath.equals("/")){ |
| 256 | 0 | this.endpointUrl = new URL(endPointURL + this.getServiceName().getLocalPart()); |
| 257 | |
} else { |
| 258 | 0 | this.endpointUrl = new URL(endPointURL + "/" + this.getServiceName().getLocalPart()); |
| 259 | |
} |
| 260 | 0 | } catch (Exception e) { |
| 261 | 0 | throw new ConfigurationException("Service Endpoint URL creation failed.", e); |
| 262 | 0 | } |
| 263 | |
|
| 264 | |
} |
| 265 | |
|
| 266 | 0 | if (this.priority == null) { |
| 267 | 0 | setPriority(5); |
| 268 | |
} |
| 269 | |
|
| 270 | 0 | if (this.retryAttempts == null) { |
| 271 | 0 | setRetryAttempts(0); |
| 272 | |
} |
| 273 | |
|
| 274 | 0 | if (this.millisToLive == null) { |
| 275 | 0 | setMillisToLive(new Long(-1)); |
| 276 | |
} |
| 277 | |
|
| 278 | 0 | if (StringUtils.isBlank(cacheManager)) { |
| 279 | 0 | LOG.warn("The cache manager was blank for " + (serviceName != null ? serviceName : localServiceName) + ". This service will not have client-side caching."); |
| 280 | 0 | } else if (GlobalResourceLoader.getService(cacheManager) == null){ |
| 281 | |
|
| 282 | |
|
| 283 | |
} |
| 284 | |
|
| 285 | 0 | } |
| 286 | |
|
| 287 | |
@Override |
| 288 | |
public Endpoint establishEndpoint() { |
| 289 | 0 | return BasicEndpoint.newEndpoint(configure(), getService()); |
| 290 | |
} |
| 291 | |
|
| 292 | |
protected abstract ServiceConfiguration configure(); |
| 293 | |
|
| 294 | |
public String getServiceNameSpaceURI() { |
| 295 | 0 | return this.serviceNameSpaceURI; |
| 296 | |
} |
| 297 | |
public void setServiceNameSpaceURI(String serviceNameSpaceURI) { |
| 298 | 0 | this.serviceNameSpaceURI = serviceNameSpaceURI; |
| 299 | 0 | } |
| 300 | |
public Long getMillisToLive() { |
| 301 | 0 | return this.millisToLive; |
| 302 | |
} |
| 303 | |
public void setMillisToLive(Long millisToLive) { |
| 304 | 0 | this.millisToLive = millisToLive; |
| 305 | 0 | } |
| 306 | |
public Boolean getBusSecurity() { |
| 307 | 0 | return this.busSecurity; |
| 308 | |
} |
| 309 | |
public void setBusSecurity(Boolean busSecurity) { |
| 310 | 0 | this.busSecurity = busSecurity; |
| 311 | 0 | } |
| 312 | |
|
| 313 | |
|
| 314 | |
|
| 315 | |
|
| 316 | |
public String getServicePath() { |
| 317 | 0 | return this.servicePath; |
| 318 | |
} |
| 319 | |
|
| 320 | |
|
| 321 | |
|
| 322 | |
|
| 323 | |
public void setServicePath(String servicePath) { |
| 324 | 0 | this.servicePath = servicePath; |
| 325 | 0 | } |
| 326 | |
|
| 327 | |
public String toString() { |
| 328 | 0 | return ReflectionToStringBuilder.toString(this); |
| 329 | |
} |
| 330 | |
|
| 331 | |
@Override |
| 332 | |
public boolean equals(Object object) { |
| 333 | 0 | return EqualsBuilder.reflectionEquals(object, this); |
| 334 | |
} |
| 335 | |
|
| 336 | |
@Override |
| 337 | |
public int hashCode() { |
| 338 | 0 | return HashCodeBuilder.reflectionHashCode(this); |
| 339 | |
} |
| 340 | |
|
| 341 | |
|
| 342 | |
} |