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