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