Coverage Report - org.kuali.rice.ksb.impl.registry.LazyRemoteServiceRegistryConnector
 
Classes in this File Line Coverage Branch Coverage Complexity
LazyRemoteServiceRegistryConnector
0%
0/41
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.core.cxf.interceptors.ImmutableCollectionsInInterceptor;
 30  
 import org.kuali.rice.ksb.api.registry.RemoveAndPublishResult;
 31  
 import org.kuali.rice.ksb.api.registry.ServiceDescriptor;
 32  
 import org.kuali.rice.ksb.api.registry.ServiceEndpoint;
 33  
 import org.kuali.rice.ksb.api.registry.ServiceEndpointStatus;
 34  
 import org.kuali.rice.ksb.api.registry.ServiceInfo;
 35  
 import org.kuali.rice.ksb.api.registry.ServiceRegistry;
 36  
 import org.kuali.rice.ksb.security.soap.CXFWSS4JInInterceptor;
 37  
 import org.kuali.rice.ksb.security.soap.CXFWSS4JOutInterceptor;
 38  
 import org.kuali.rice.ksb.util.KSBConstants;
 39  
 
 40  
 /**
 41  
  * TODO... 
 42  
  * 
 43  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 44  
  *
 45  
  */
 46  0
 public class LazyRemoteServiceRegistryConnector implements ServiceRegistry {
 47  
 
 48  0
         private final Object initLock = new Object();
 49  
         private volatile ServiceRegistry delegate;
 50  
         
 51  
         // injected
 52  
         private Bus cxfBus;
 53  
         
 54  
         public void setCxfBus(Bus cxfBus) {
 55  0
                 this.cxfBus = cxfBus;
 56  0
         }
 57  
         
 58  
         @Override
 59  
         public List<ServiceInfo> getOnlineServicesByName(QName serviceName)
 60  
                         throws RiceIllegalArgumentException {
 61  0
                 return getDelegate().getOnlineServicesByName(serviceName);
 62  
         }
 63  
 
 64  
         @Override
 65  
         public List<ServiceInfo> getAllOnlineServices() {
 66  0
                 return getDelegate().getAllOnlineServices();
 67  
         }
 68  
 
 69  
         @Override
 70  
         public List<ServiceInfo> getAllServices() {
 71  0
                 return getDelegate().getAllServices();
 72  
         }
 73  
         
 74  
         @Override
 75  
         public List<ServiceInfo> getAllServicesForInstance(String instanceId) {
 76  0
                 return getDelegate().getAllServicesForInstance(instanceId);
 77  
         }
 78  
 
 79  
         @Override
 80  
         public ServiceDescriptor getServiceDescriptor(String serviceDescriptorId)
 81  
                         throws RiceIllegalArgumentException {
 82  0
                 return getDelegate().getServiceDescriptor(serviceDescriptorId);
 83  
         }
 84  
 
 85  
         @Override
 86  
         public List<ServiceDescriptor> getServiceDescriptors(
 87  
                         List<String> serviceDescriptorIds)
 88  
                         throws RiceIllegalArgumentException {
 89  0
                 return getDelegate().getServiceDescriptors(serviceDescriptorIds);
 90  
         }
 91  
 
 92  
         @Override
 93  
         public ServiceEndpoint publishService(ServiceEndpoint serviceEndpoint)
 94  
                         throws RiceIllegalArgumentException {
 95  0
                 return getDelegate().publishService(serviceEndpoint);
 96  
         }
 97  
 
 98  
         @Override
 99  
         public List<ServiceEndpoint> publishServices(List<ServiceEndpoint> serviceEndpoints)
 100  
                         throws RiceIllegalArgumentException {
 101  0
                 return getDelegate().publishServices(serviceEndpoints);
 102  
         }
 103  
 
 104  
         @Override
 105  
         public ServiceEndpoint removeServiceEndpoint(String serviceId)
 106  
                         throws RiceIllegalArgumentException {
 107  0
                 return getDelegate().removeServiceEndpoint(serviceId);
 108  
         }
 109  
 
 110  
         @Override
 111  
         public List<ServiceEndpoint> removeServiceEndpoints(List<String> serviceIds)
 112  
                         throws RiceIllegalArgumentException {
 113  0
                 return getDelegate().removeServiceEndpoints(serviceIds);
 114  
         }
 115  
 
 116  
         @Override
 117  
         public RemoveAndPublishResult removeAndPublish(List<String> removeServiceIds,
 118  
                         List<ServiceEndpoint> publishServiceEndpoints) {
 119  0
                 return getDelegate().removeAndPublish(removeServiceIds, publishServiceEndpoints);
 120  
         }
 121  
 
 122  
         @Override
 123  
         public boolean updateStatus(String serviceId, ServiceEndpointStatus status) throws RiceIllegalArgumentException {
 124  0
                 return getDelegate().updateStatus(serviceId, status);
 125  
         }
 126  
 
 127  
         @Override
 128  
         public List<String> updateStatuses(List<String> serviceIds, ServiceEndpointStatus status) throws RiceIllegalArgumentException {
 129  0
                 return getDelegate().updateStatuses(serviceIds, status);
 130  
         }
 131  
 
 132  
         @Override
 133  
         public void takeInstanceOffline(String instanceId)
 134  
                         throws RiceIllegalArgumentException {
 135  0
                 getDelegate().takeInstanceOffline(instanceId);
 136  0
         }
 137  
         
 138  
         private ServiceRegistry getDelegate() {
 139  
                 // double-checked locking idiom - see Effective Java, Item 71
 140  0
                 ServiceRegistry internalDelegate = this.delegate;
 141  0
                 if (internalDelegate == null) {
 142  0
                         synchronized (initLock) {
 143  0
                                 internalDelegate = this.delegate;
 144  0
                                 if (internalDelegate == null) {
 145  0
                                         this.delegate = internalDelegate = initializeRemoteServiceRegistry();
 146  
                                 }
 147  0
                         }
 148  
                 }
 149  0
                 return internalDelegate;
 150  
         }
 151  
         
 152  
         protected ServiceRegistry initializeRemoteServiceRegistry() {
 153  0
                 String registryBootstrapUrl = ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.REGISTRY_SERVICE_URL);
 154  0
                 if (StringUtils.isBlank(registryBootstrapUrl)) {
 155  0
                         throw new RiceRuntimeException("Failed to load registry bootstrap service from url: " + registryBootstrapUrl);
 156  
                 }
 157  0
                 ClientProxyFactoryBean clientFactory = new JaxWsProxyFactoryBean();
 158  0
                 clientFactory.setServiceClass(ServiceRegistry.class);
 159  0
                 clientFactory.setBus(cxfBus);
 160  0
                 clientFactory.setAddress(registryBootstrapUrl);
 161  
                 
 162  
                 // Set security interceptors
 163  0
                 clientFactory.getOutInterceptors().add(new CXFWSS4JOutInterceptor(true));
 164  0
                 clientFactory.getInInterceptors().add(new CXFWSS4JInInterceptor(true));
 165  
 
 166  
         //Set transformation interceptors
 167  0
         clientFactory.getInInterceptors().add(new ImmutableCollectionsInInterceptor());
 168  
                 
 169  0
                 Object service = clientFactory.create();
 170  0
                 if (!(service instanceof ServiceRegistry)) {
 171  0
                         throw new RiceRuntimeException("Endpoint to service registry at URL '" + registryBootstrapUrl + "' was not an instance of ServiceRegistry, instead was: " + service);
 172  
                 }
 173  0
                 return (ServiceRegistry)service;
 174  
         }
 175  
         
 176  
 }