| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.ksb.impl.bus; |
| 17 | |
|
| 18 | |
import org.apache.commons.codec.binary.Base64; |
| 19 | |
import org.apache.commons.lang.StringUtils; |
| 20 | |
import org.kuali.rice.core.api.exception.RiceRuntimeException; |
| 21 | |
import org.kuali.rice.core.api.util.ChecksumUtils; |
| 22 | |
import org.kuali.rice.core.api.util.RiceUtilities; |
| 23 | |
import org.kuali.rice.ksb.api.bus.Endpoint; |
| 24 | |
import org.kuali.rice.ksb.api.bus.ServiceConfiguration; |
| 25 | |
import org.kuali.rice.ksb.api.bus.ServiceDefinition; |
| 26 | |
import org.kuali.rice.ksb.api.registry.ServiceDescriptor; |
| 27 | |
import org.kuali.rice.ksb.api.registry.ServiceEndpoint; |
| 28 | |
import org.kuali.rice.ksb.api.registry.ServiceEndpointStatus; |
| 29 | |
import org.kuali.rice.ksb.api.registry.ServiceInfo; |
| 30 | |
|
| 31 | |
import javax.xml.namespace.QName; |
| 32 | |
import java.io.ByteArrayOutputStream; |
| 33 | |
import java.io.IOException; |
| 34 | |
import java.io.ObjectOutput; |
| 35 | |
import java.io.ObjectOutputStream; |
| 36 | |
import java.io.UnsupportedEncodingException; |
| 37 | |
import java.security.GeneralSecurityException; |
| 38 | |
import java.security.MessageDigest; |
| 39 | |
|
| 40 | |
public final class LocalService { |
| 41 | |
|
| 42 | |
private final ServiceDefinition serviceDefinition; |
| 43 | |
private final Endpoint endpoint; |
| 44 | |
private final ServiceEndpoint serviceEndpoint; |
| 45 | |
|
| 46 | |
LocalService(String instanceId, ServiceDefinition serviceDefinition) { |
| 47 | 0 | this(instanceId, serviceDefinition, null); |
| 48 | 0 | } |
| 49 | |
|
| 50 | 0 | LocalService(String instanceId, ServiceDefinition serviceDefinition, ServiceEndpoint serviceEndpoint) { |
| 51 | 0 | if (StringUtils.isBlank(instanceId)) { |
| 52 | 0 | throw new IllegalArgumentException("instanceId was blank or null"); |
| 53 | |
} |
| 54 | 0 | if (serviceDefinition == null) { |
| 55 | 0 | throw new IllegalArgumentException("serviceDefinition was null"); |
| 56 | |
} |
| 57 | 0 | this.serviceDefinition = serviceDefinition; |
| 58 | 0 | this.endpoint = serviceDefinition.establishEndpoint(); |
| 59 | 0 | if (serviceEndpoint != null) { |
| 60 | 0 | this.serviceEndpoint = serviceEndpoint; |
| 61 | |
} else { |
| 62 | 0 | this.serviceEndpoint = constructServiceEndpoint(instanceId, this.endpoint); |
| 63 | |
} |
| 64 | 0 | } |
| 65 | |
|
| 66 | |
LocalService(LocalService currentLocalService, ServiceEndpoint newServiceEndpoint) { |
| 67 | 0 | this(newServiceEndpoint.getInfo().getInstanceId(), currentLocalService.getServiceDefinition(), newServiceEndpoint); |
| 68 | 0 | } |
| 69 | |
|
| 70 | |
public QName getServiceName() { |
| 71 | 0 | return endpoint.getServiceConfiguration().getServiceName(); |
| 72 | |
} |
| 73 | |
|
| 74 | |
public ServiceDefinition getServiceDefinition() { |
| 75 | 0 | return serviceDefinition; |
| 76 | |
} |
| 77 | |
|
| 78 | |
public Endpoint getEndpoint() { |
| 79 | 0 | return endpoint; |
| 80 | |
} |
| 81 | |
|
| 82 | |
public ServiceEndpoint getServiceEndpoint() { |
| 83 | 0 | return this.serviceEndpoint; |
| 84 | |
} |
| 85 | |
|
| 86 | |
static ServiceEndpoint constructServiceEndpoint(String instanceId, Endpoint endpoint) { |
| 87 | 0 | ServiceInfo.Builder serviceInfo = constructServiceInfo(instanceId, endpoint.getServiceConfiguration()); |
| 88 | 0 | ServiceDescriptor.Builder serviceDescriptor = constructDescriptor(endpoint.getServiceConfiguration()); |
| 89 | 0 | ServiceEndpoint.Builder builder = ServiceEndpoint.Builder.create(serviceInfo, serviceDescriptor); |
| 90 | 0 | return builder.build(); |
| 91 | |
} |
| 92 | |
|
| 93 | |
static ServiceInfo.Builder constructServiceInfo(String instanceId, ServiceConfiguration serviceConfiguration) { |
| 94 | 0 | ServiceInfo.Builder builder = ServiceInfo.Builder.create(); |
| 95 | 0 | builder.setInstanceId(instanceId); |
| 96 | 0 | builder.setApplicationId(serviceConfiguration.getApplicationId()); |
| 97 | 0 | builder.setChecksum(ChecksumUtils.calculateChecksum(serviceConfiguration)); |
| 98 | 0 | builder.setEndpointUrl(serviceConfiguration.getEndpointUrl().toExternalForm()); |
| 99 | 0 | builder.setServerIpAddress(RiceUtilities.getIpNumber()); |
| 100 | 0 | builder.setServiceName(serviceConfiguration.getServiceName()); |
| 101 | 0 | builder.setServiceVersion(serviceConfiguration.getServiceVersion()); |
| 102 | 0 | builder.setStatus(ServiceEndpointStatus.ONLINE); |
| 103 | 0 | builder.setType(serviceConfiguration.getType()); |
| 104 | 0 | return builder; |
| 105 | |
} |
| 106 | |
|
| 107 | |
static ServiceDescriptor.Builder constructDescriptor(ServiceConfiguration serviceConfiguration) { |
| 108 | 0 | ServiceDescriptor.Builder builder = ServiceDescriptor.Builder.create(); |
| 109 | 0 | builder.setDescriptor(ServiceConfigurationSerializationHandler.marshallToXml(serviceConfiguration)); |
| 110 | 0 | return builder; |
| 111 | |
} |
| 112 | |
|
| 113 | |
} |