1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
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 | |
|
42 | |
|
43 | |
|
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 | |
|
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 | |
|
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 | |
|
163 | 0 | clientFactory.getOutInterceptors().add(new CXFWSS4JOutInterceptor(true)); |
164 | 0 | clientFactory.getInInterceptors().add(new CXFWSS4JInInterceptor(true)); |
165 | |
|
166 | |
|
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 | |
} |