| 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.codec.binary.Base64; |
| 20 | |
import org.apache.commons.lang.StringUtils; |
| 21 | |
import org.apache.commons.lang.builder.ReflectionToStringBuilder; |
| 22 | |
import org.hibernate.annotations.GenericGenerator; |
| 23 | |
import org.hibernate.annotations.Parameter; |
| 24 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
| 25 | |
import org.kuali.rice.core.api.exception.RiceRuntimeException; |
| 26 | |
import org.kuali.rice.core.framework.persistence.jpa.OrmUtils; |
| 27 | |
import org.kuali.rice.core.util.RiceUtilities; |
| 28 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
| 29 | |
|
| 30 | |
import javax.persistence.Column; |
| 31 | |
import javax.persistence.Entity; |
| 32 | |
import javax.persistence.GeneratedValue; |
| 33 | |
import javax.persistence.Id; |
| 34 | |
import javax.persistence.NamedQueries; |
| 35 | |
import javax.persistence.NamedQuery; |
| 36 | |
import javax.persistence.Table; |
| 37 | |
import javax.persistence.Transient; |
| 38 | |
import javax.persistence.Version; |
| 39 | |
import javax.xml.namespace.QName; |
| 40 | |
import java.io.ByteArrayOutputStream; |
| 41 | |
import java.io.IOException; |
| 42 | |
import java.io.ObjectOutput; |
| 43 | |
import java.io.ObjectOutputStream; |
| 44 | |
import java.io.Serializable; |
| 45 | |
import java.io.UnsupportedEncodingException; |
| 46 | |
import java.security.GeneralSecurityException; |
| 47 | |
import java.security.MessageDigest; |
| 48 | |
|
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
@Entity |
| 57 | |
@Table(name="KRSB_SVC_DEF_T") |
| 58 | |
|
| 59 | |
@NamedQueries({ |
| 60 | |
@NamedQuery(name="ServiceInfo.FetchAll", query="select s from ServiceInfo s"), |
| 61 | |
@NamedQuery(name="ServiceInfo.FetchAllActive",query="select s from ServiceInfo s where s.alive = true"), |
| 62 | |
@NamedQuery(name="ServiceInfo.FetchActiveByName",query="select s from ServiceInfo s where s.alive = true AND s.serviceName LIKE :serviceName"), |
| 63 | |
@NamedQuery(name="ServiceInfo.FindLocallyPublishedServices",query="select s from ServiceInfo s where s.serverIp = :serverIp AND s.serviceNamespace = :serviceNamespace"), |
| 64 | |
@NamedQuery(name="ServiceInfo.DeleteLocallyPublishedServices",query="delete from ServiceInfo s WHERE s.serverIp = :serverIp AND s.serviceNamespace = :serviceNamespace"), |
| 65 | |
@NamedQuery(name="ServiceInfo.DeleteByEntry",query="delete from ServiceInfo s where s.messageEntryId = :messageEntryId") |
| 66 | |
}) |
| 67 | |
public class ServiceInfo implements Serializable { |
| 68 | |
|
| 69 | |
private static final long serialVersionUID = -4244884858494208070L; |
| 70 | |
@Transient |
| 71 | |
private ServiceDefinition serviceDefinition; |
| 72 | |
@Id |
| 73 | |
@GeneratedValue(generator="KRSB_SVC_DEF_S") |
| 74 | |
@GenericGenerator(name="KRSB_SVC_DEF_S",strategy="org.hibernate.id.enhanced.SequenceStyleGenerator",parameters={ |
| 75 | |
@Parameter(name="sequence_name",value="KRSB_SVC_DEF_S"), |
| 76 | |
@Parameter(name="value_column",value="id") |
| 77 | |
}) |
| 78 | |
@Column(name="SVC_DEF_ID") |
| 79 | |
private Long messageEntryId; |
| 80 | |
@Transient |
| 81 | |
private QName qname; |
| 82 | |
@Column(name="SVC_URL", length=500) |
| 83 | |
private String endpointUrl; |
| 84 | |
@Transient |
| 85 | |
private String endpointAlternateUrl; |
| 86 | |
@Column(name="FLT_SVC_DEF_ID") |
| 87 | |
private Long flattenedServiceDefinitionId; |
| 88 | |
@Transient |
| 89 | |
private FlattenedServiceDefinition serializedServiceNamespace; |
| 90 | |
@Column(name="SVC_NM") |
| 91 | |
private String serviceName; |
| 92 | 0 | @Column(name="SVC_ALIVE") |
| 93 | |
private Boolean alive = true; |
| 94 | |
@Column(name="SVC_NMSPC") |
| 95 | |
private String serviceNamespace; |
| 96 | |
@Column(name="SRVR_IP") |
| 97 | |
private String serverIp; |
| 98 | |
@Version |
| 99 | |
@Column(name="VER_NBR") |
| 100 | |
private Integer lockVerNbr; |
| 101 | |
@Column(name="SVC_DEF_CHKSM", length=30) |
| 102 | |
private String checksum; |
| 103 | |
|
| 104 | |
@Transient |
| 105 | |
private transient ClassLoader serviceClassLoader; |
| 106 | |
|
| 107 | 0 | public ServiceInfo() { |
| 108 | |
|
| 109 | 0 | } |
| 110 | |
|
| 111 | |
|
| 112 | |
public void beforeInsert(){ |
| 113 | 0 | OrmUtils.populateAutoIncValue(this, KSBServiceLocator.getRegistryEntityManagerFactory().createEntityManager()); |
| 114 | 0 | } |
| 115 | |
|
| 116 | 0 | public ServiceInfo(ServiceDefinition serviceDefinition, String serverIp, String checksum) { |
| 117 | 0 | this.setServiceDefinition(serviceDefinition); |
| 118 | 0 | this.setQname(serviceDefinition.getServiceName()); |
| 119 | 0 | this.setServiceNamespace(ConfigContext.getCurrentContextConfig().getServiceNamespace()); |
| 120 | 0 | this.setServerIp(serverIp); |
| 121 | 0 | this.setEndpointUrl(serviceDefinition.getServiceEndPoint().toString()); |
| 122 | 0 | this.setServiceName(this.getQname().toString()); |
| 123 | 0 | this.setServiceClassLoader(serviceDefinition.getServiceClassLoader()); |
| 124 | 0 | this.setChecksum((checksum != null) ? checksum : this.objectToChecksum(serviceDefinition)); |
| 125 | 0 | } |
| 126 | |
|
| 127 | 0 | public ServiceInfo(ServiceDefinition serviceDefinition) { |
| 128 | 0 | this.setServiceDefinition(serviceDefinition); |
| 129 | 0 | this.setQname(serviceDefinition.getServiceName()); |
| 130 | 0 | this.setServiceNamespace(ConfigContext.getCurrentContextConfig().getServiceNamespace()); |
| 131 | 0 | this.setServerIp(RiceUtilities.getIpNumber()); |
| 132 | 0 | this.setEndpointUrl(serviceDefinition.getServiceEndPoint().toString()); |
| 133 | 0 | this.setServiceName(this.getQname().toString()); |
| 134 | 0 | this.setServiceClassLoader(serviceDefinition.getServiceClassLoader()); |
| 135 | 0 | this.setChecksum(this.objectToChecksum(serviceDefinition)); |
| 136 | 0 | } |
| 137 | |
|
| 138 | |
public Long getMessageEntryId() { |
| 139 | 0 | return this.messageEntryId; |
| 140 | |
} |
| 141 | |
|
| 142 | |
public void setMessageEntryId(Long messageEntryId) { |
| 143 | 0 | this.messageEntryId = messageEntryId; |
| 144 | 0 | } |
| 145 | |
|
| 146 | |
public ServiceDefinition getServiceDefinition() { |
| 147 | 0 | return getServiceDefinition(KSBServiceLocator.getMessageHelper()); |
| 148 | |
} |
| 149 | |
|
| 150 | |
public ServiceDefinition getServiceDefinition(MessageHelper enMessageHelper) { |
| 151 | 0 | if (this.serviceDefinition == null) { |
| 152 | 0 | this.serviceDefinition = (ServiceDefinition) |
| 153 | |
(enMessageHelper==null |
| 154 | |
?KSBServiceLocator.getMessageHelper().deserializeObject(this.getSerializedServiceNamespace().getFlattenedServiceDefinitionData()) |
| 155 | |
:enMessageHelper.deserializeObject(this.getSerializedServiceNamespace().getFlattenedServiceDefinitionData())); |
| 156 | 0 | this.serviceDefinition.setServiceClassLoader(getServiceClassLoader()); |
| 157 | |
} |
| 158 | 0 | return this.serviceDefinition; |
| 159 | |
} |
| 160 | |
|
| 161 | |
public void setServiceDefinition(ServiceDefinition serviceDefinition) { |
| 162 | 0 | this.serviceDefinition = serviceDefinition; |
| 163 | 0 | } |
| 164 | |
|
| 165 | |
public QName getQname() { |
| 166 | 0 | if (this.qname == null) { |
| 167 | 0 | this.qname = QName.valueOf(this.getServiceName()); |
| 168 | |
} |
| 169 | 0 | return this.qname; |
| 170 | |
} |
| 171 | |
|
| 172 | |
public void setQname(QName serviceName) { |
| 173 | 0 | this.qname = serviceName; |
| 174 | 0 | } |
| 175 | |
public String getEndpointUrl() { |
| 176 | 0 | return this.endpointUrl; |
| 177 | |
} |
| 178 | |
public void setEndpointUrl(String ipNumber) { |
| 179 | 0 | this.endpointUrl = ipNumber; |
| 180 | 0 | } |
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
public String getEndpointAlternateUrl() { |
| 186 | 0 | return this.endpointAlternateUrl; |
| 187 | |
} |
| 188 | |
|
| 189 | |
public String getActualEndpointUrl() { |
| 190 | 0 | if (!StringUtils.isBlank(getEndpointAlternateUrl())) { |
| 191 | 0 | return getEndpointAlternateUrl(); |
| 192 | |
} |
| 193 | 0 | return getEndpointUrl(); |
| 194 | |
} |
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
public void setEndpointAlternateUrl(String endpointAlternateUrl) { |
| 200 | 0 | this.endpointAlternateUrl = endpointAlternateUrl; |
| 201 | 0 | } |
| 202 | |
|
| 203 | |
public ClassLoader getServiceClassLoader() { |
| 204 | 0 | return this.serviceClassLoader; |
| 205 | |
} |
| 206 | |
|
| 207 | |
public void setServiceClassLoader(ClassLoader serviceClassLoader) { |
| 208 | 0 | this.serviceClassLoader = serviceClassLoader; |
| 209 | 0 | } |
| 210 | |
|
| 211 | |
public Integer getLockVerNbr() { |
| 212 | 0 | return this.lockVerNbr; |
| 213 | |
} |
| 214 | |
public void setLockVerNbr(Integer lockVerNbr) { |
| 215 | 0 | this.lockVerNbr = lockVerNbr; |
| 216 | 0 | } |
| 217 | |
public String getServiceNamespace() { |
| 218 | 0 | return this.serviceNamespace; |
| 219 | |
} |
| 220 | |
|
| 221 | |
public void setServiceNamespace(String ServiceNamespace) { |
| 222 | 0 | this.serviceNamespace = ServiceNamespace; |
| 223 | 0 | } |
| 224 | |
public String getServerIp() { |
| 225 | 0 | return this.serverIp; |
| 226 | |
} |
| 227 | |
|
| 228 | |
public void setServerIp(String serverIp) { |
| 229 | 0 | this.serverIp = serverIp; |
| 230 | 0 | } |
| 231 | |
public Boolean getAlive() { |
| 232 | 0 | return this.alive; |
| 233 | |
} |
| 234 | |
|
| 235 | |
public void setAlive(Boolean alive) { |
| 236 | 0 | this.alive = alive; |
| 237 | 0 | } |
| 238 | |
public void setSerializedServiceNamespace(FlattenedServiceDefinition serializedServiceNamespace) { |
| 239 | 0 | this.serializedServiceNamespace = serializedServiceNamespace; |
| 240 | 0 | } |
| 241 | |
|
| 242 | |
public FlattenedServiceDefinition getSerializedServiceNamespace() { |
| 243 | 0 | if (this.serializedServiceNamespace == null && this.getFlattenedServiceDefinitionId() != null) { |
| 244 | 0 | this.serializedServiceNamespace = KSBServiceLocator.getServiceRegistry().getFlattenedServiceDefinition(this.getFlattenedServiceDefinitionId()); |
| 245 | |
} |
| 246 | 0 | return this.serializedServiceNamespace; |
| 247 | |
} |
| 248 | |
|
| 249 | |
public String getServiceName() { |
| 250 | 0 | return this.serviceName; |
| 251 | |
} |
| 252 | |
|
| 253 | |
public void setServiceName(String serviceName) { |
| 254 | 0 | this.serviceName = serviceName; |
| 255 | 0 | } |
| 256 | |
|
| 257 | |
public String toString() { |
| 258 | 0 | return ReflectionToStringBuilder.toString(this); |
| 259 | |
} |
| 260 | |
|
| 261 | |
public String getChecksum() { |
| 262 | 0 | return this.checksum; |
| 263 | |
} |
| 264 | |
|
| 265 | |
public void setChecksum(String checksum) { |
| 266 | 0 | this.checksum = checksum; |
| 267 | 0 | } |
| 268 | |
|
| 269 | |
public Long getFlattenedServiceDefinitionId() { |
| 270 | 0 | return this.flattenedServiceDefinitionId; |
| 271 | |
} |
| 272 | |
|
| 273 | |
public void setFlattenedServiceDefinitionId(Long flattenedServiceDefinitionId) { |
| 274 | 0 | this.flattenedServiceDefinitionId = flattenedServiceDefinitionId; |
| 275 | 0 | } |
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
|
| 281 | |
|
| 282 | |
|
| 283 | |
public String objectToChecksum(Serializable object) { |
| 284 | 0 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
| 285 | 0 | ObjectOutput out = null; |
| 286 | |
try { |
| 287 | 0 | out = new ObjectOutputStream(bos); |
| 288 | 0 | out.writeObject(object); |
| 289 | 0 | } catch (IOException e) { |
| 290 | 0 | throw new RiceRuntimeException(e); |
| 291 | |
} finally { |
| 292 | 0 | try { |
| 293 | 0 | out.close(); |
| 294 | 0 | } catch (IOException e) {} |
| 295 | 0 | } |
| 296 | |
try { |
| 297 | 0 | MessageDigest md = MessageDigest.getInstance("SHA-1"); |
| 298 | 0 | return new String( Base64.encodeBase64( md.digest( bos.toByteArray() ) ), "UTF-8"); |
| 299 | 0 | } catch( GeneralSecurityException ex ) { |
| 300 | 0 | throw new RiceRuntimeException(ex); |
| 301 | 0 | } catch( UnsupportedEncodingException ex ) { |
| 302 | 0 | throw new RiceRuntimeException(ex); |
| 303 | |
} |
| 304 | |
} |
| 305 | |
} |