Coverage Report - org.kuali.rice.ksb.impl.registry.LazyRemoteServiceRegistryConnector
 
Classes in this File Line Coverage Branch Coverage Complexity
LazyRemoteServiceRegistryConnector
0%
0/40
0%
0/8
1.353
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl1.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.ksb.impl.registry;
 17  
 
 18  
 import java.util.List;
 19  
 
 20  
 import javax.xml.namespace.QName;
 21  
 
 22  
 import org.apache.commons.lang.StringUtils;
 23  
 import org.apache.cxf.Bus;
 24  
 import org.apache.cxf.frontend.ClientProxyFactoryBean;
 25  
 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
 26  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 27  
 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
 28  
 import org.kuali.rice.core.api.exception.RiceRuntimeException;
 29  
 import org.kuali.rice.ksb.api.registry.RemoveAndPublishResult;
 30  
 import org.kuali.rice.ksb.api.registry.ServiceDescriptor;
 31  
 import org.kuali.rice.ksb.api.registry.ServiceEndpoint;
 32  
 import org.kuali.rice.ksb.api.registry.ServiceEndpointStatus;
 33  
 import org.kuali.rice.ksb.api.registry.ServiceInfo;
 34  
 import org.kuali.rice.ksb.api.registry.ServiceRegistry;
 35  
 import org.kuali.rice.ksb.security.soap.CXFWSS4JInInterceptor;
 36  
 import org.kuali.rice.ksb.security.soap.CXFWSS4JOutInterceptor;
 37  
 import org.kuali.rice.ksb.util.KSBConstants;
 38  
 
 39  
 /**
 40  
  * TODO... 
 41  
  * 
 42  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 43  
  *
 44  
  */
 45  0
 public class LazyRemoteServiceRegistryConnector implements ServiceRegistry {
 46  
 
 47  0
         private final Object initLock = new Object();
 48  
         private volatile ServiceRegistry delegate;
 49  
         
 50  
         // injected
 51  
         private Bus cxfBus;
 52  
         
 53  
         public void setCxfBus(Bus cxfBus) {
 54  0
                 this.cxfBus = cxfBus;
 55  0
         }
 56  
         
 57  
         @Override
 58  
         public List<ServiceInfo> getOnlineServicesByName(QName serviceName)
 59  
                         throws RiceIllegalArgumentException {
 60  0
                 return getDelegate().getOnlineServicesByName(serviceName);
 61  
         }
 62  
 
 63  
         @Override
 64  
         public List<ServiceInfo> getAllOnlineServices() {
 65  0
                 return getDelegate().getAllOnlineServices();
 66  
         }
 67  
 
 68  
         @Override
 69  
         public List<ServiceInfo> getAllServices() {
 70  0
                 return getDelegate().getAllServices();
 71  
         }
 72  
         
 73  
         @Override
 74  
         public List<ServiceInfo> getAllServicesForInstance(String instanceId) {
 75  0
                 return getDelegate().getAllServicesForInstance(instanceId);
 76  
         }
 77  
 
 78  
         @Override
 79  
         public ServiceDescriptor getServiceDescriptor(String serviceDescriptorId)
 80  
                         throws RiceIllegalArgumentException {
 81  0
                 return getDelegate().getServiceDescriptor(serviceDescriptorId);
 82  
         }
 83  
 
 84  
         @Override
 85  
         public List<ServiceDescriptor> getServiceDescriptors(
 86  
                         List<String> serviceDescriptorIds)
 87  
                         throws RiceIllegalArgumentException {
 88  0
                 return getDelegate().getServiceDescriptors(serviceDescriptorIds);
 89  
         }
 90  
 
 91  
         @Override
 92  
         public ServiceEndpoint publishService(ServiceEndpoint serviceEndpoint)
 93  
                         throws RiceIllegalArgumentException {
 94  0
                 return getDelegate().publishService(serviceEndpoint);
 95  
         }
 96  
 
 97  
         @Override
 98  
         public List<ServiceEndpoint> publishServices(List<ServiceEndpoint> serviceEndpoints)
 99  
                         throws RiceIllegalArgumentException {
 100  0
                 return getDelegate().publishServices(serviceEndpoints);
 101  
         }
 102  
 
 103  
         @Override
 104  
         public ServiceEndpoint removeServiceEndpoint(String serviceId)
 105  
                         throws RiceIllegalArgumentException {
 106  0
                 return getDelegate().removeServiceEndpoint(serviceId);
 107  
         }
 108  
 
 109  
         @Override
 110  
         public List<ServiceEndpoint> removeServiceEndpoints(List<String> serviceIds)
 111  
                         throws RiceIllegalArgumentException {
 112  0
                 return getDelegate().removeServiceEndpoints(serviceIds);
 113  
         }
 114  
 
 115  
         @Override
 116  
         public RemoveAndPublishResult removeAndPublish(List<String> removeServiceIds,
 117  
                         List<ServiceEndpoint> publishServiceEndpoints) {
 118  0
                 return getDelegate().removeAndPublish(removeServiceIds, publishServiceEndpoints);
 119  
         }
 120  
 
 121  
         @Override
 122  
         public boolean updateStatus(String serviceId, ServiceEndpointStatus status) throws RiceIllegalArgumentException {
 123  0
                 return getDelegate().updateStatus(serviceId, status);
 124  
         }
 125  
 
 126  
         @Override
 127  
         public List<String> updateStatuses(List<String> serviceIds, ServiceEndpointStatus status) throws RiceIllegalArgumentException {
 128  0
                 return getDelegate().updateStatuses(serviceIds, status);
 129  
         }
 130  
 
 131  
         @Override
 132  
         public void takeInstanceOffline(String instanceId)
 133  
                         throws RiceIllegalArgumentException {
 134  0
                 getDelegate().takeInstanceOffline(instanceId);
 135  0
         }
 136  
         
 137  
         private ServiceRegistry getDelegate() {
 138  
                 // double-checked locking idiom - see Effective Java, Item 71
 139  0
                 ServiceRegistry internalDelegate = this.delegate;
 140  0
                 if (internalDelegate == null) {
 141  0
                         synchronized (initLock) {
 142  0
                                 internalDelegate = this.delegate;
 143  0
                                 if (internalDelegate == null) {
 144  0
                                         this.delegate = internalDelegate = initializeRemoteServiceRegistry();
 145  
                                 }
 146  0
                         }
 147  
                 }
 148  0
                 return internalDelegate;
 149  
         }
 150  
         
 151  
         protected ServiceRegistry initializeRemoteServiceRegistry() {
 152  0
                 String registryBootstrapUrl = ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.REGISTRY_SERVICE_URL);
 153  0
                 if (StringUtils.isBlank(registryBootstrapUrl)) {
 154  0
                         throw new RiceRuntimeException("Failed to load registry bootstrap service from url: " + registryBootstrapUrl);
 155  
                 }
 156  0
                 ClientProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
 157  0
                 clientFactory.setServiceClass(ServiceRegistry.class);
 158  0
                 clientFactory.setBus(cxfBus);
 159  0
                 clientFactory.setAddress(registryBootstrapUrl);
 160  
                 
 161  
                 // Set security interceptors
 162  0
                 clientFactory.getOutInterceptors().add(new CXFWSS4JOutInterceptor(true));
 163  0
                 clientFactory.getInInterceptors().add(new CXFWSS4JInInterceptor(true));
 164  
                 
 165  0
                 Object service = clientFactory.create();
 166  0
                 if (!(service instanceof ServiceRegistry)) {
 167  0
                         throw new RiceRuntimeException("Endpoint to service registry at URL '" + registryBootstrapUrl + "' was not an instance of ServiceRegistry, instead was: " + service);
 168  
                 }
 169  0
                 return (ServiceRegistry)service;
 170  
         }
 171  
         
 172  
 }