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.lang.StringUtils; |
20 | |
import org.apache.log4j.Logger; |
21 | |
import org.kuali.rice.core.api.config.ConfigurationException; |
22 | |
import org.kuali.rice.core.api.config.property.Config; |
23 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
24 | |
import org.kuali.rice.core.util.ClassLoaderUtils; |
25 | |
import org.kuali.rice.core.util.RiceUtilities; |
26 | |
import org.kuali.rice.kns.util.ObjectUtils; |
27 | |
import org.kuali.rice.ksb.messaging.callforwarding.ForwardedCallHandler; |
28 | |
import org.kuali.rice.ksb.messaging.callforwarding.ForwardedCallHandlerImpl; |
29 | |
import org.kuali.rice.ksb.messaging.service.ServiceRegistry; |
30 | |
import org.kuali.rice.ksb.messaging.serviceexporters.ServiceExporterFactory; |
31 | |
import org.kuali.rice.ksb.service.KSBContextServiceLocator; |
32 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
33 | |
import org.kuali.rice.ksb.util.KSBConstants; |
34 | |
import org.springframework.web.servlet.mvc.Controller; |
35 | |
|
36 | |
import javax.servlet.http.HttpServletRequest; |
37 | |
import javax.servlet.http.HttpServletResponse; |
38 | |
import javax.xml.namespace.QName; |
39 | |
import java.net.URI; |
40 | |
import java.util.ArrayList; |
41 | |
import java.util.Collections; |
42 | |
import java.util.HashMap; |
43 | |
import java.util.Iterator; |
44 | |
import java.util.List; |
45 | |
import java.util.Map; |
46 | |
import java.util.concurrent.ScheduledFuture; |
47 | |
import java.util.concurrent.TimeUnit; |
48 | |
|
49 | 0 | public class RemotedServiceRegistryImpl implements RemotedServiceRegistry, Runnable { |
50 | |
|
51 | 0 | private static final Logger LOG = Logger.getLogger(RemotedServiceRegistryImpl.class); |
52 | |
|
53 | 0 | private Map<QName, ServerSideRemotedServiceHolder> publishedServices = Collections.synchronizedMap(new HashMap<QName, ServerSideRemotedServiceHolder>()); |
54 | |
|
55 | 0 | private Map<QName, ServerSideRemotedServiceHolder> publishedTempServices = Collections.synchronizedMap(new HashMap<QName, ServerSideRemotedServiceHolder>()); |
56 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | 0 | private Map<QName, ServiceInfo> serviceInfoCopies = Collections.synchronizedMap(new HashMap<QName, ServiceInfo>()); |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | 0 | private Map<QName, ServiceInfo> serviceInfoCopyHolder = Collections.synchronizedMap(new HashMap<QName, ServiceInfo>()); |
68 | |
|
69 | |
private String serverIp; |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | 0 | private ServiceNameFinder publishedServiceNameFinder = new ServiceNameFinder(); |
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | 0 | private ServiceNameFinder publishedTempServiceNameFinder = new ServiceNameFinder(); |
80 | |
|
81 | |
private boolean started; |
82 | |
|
83 | |
private ScheduledFuture future; |
84 | |
|
85 | |
protected ServiceRegistry serviceRegistry; |
86 | |
|
87 | |
protected KSBContextServiceLocator serviceLocator; |
88 | |
|
89 | |
public void handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { |
90 | 0 | ((Controller) handler).handleRequest(request, response); |
91 | 0 | } |
92 | |
|
93 | |
private void registerService(ServiceInfo entry, Object serviceImpl) throws Exception { |
94 | 0 | ServerSideRemotedServiceHolder serviceHolder = ServiceExporterFactory.getServiceExporter(entry, serviceLocator).getServiceExporter(serviceImpl); |
95 | 0 | this.publishedServices.put(entry.getQname(), serviceHolder); |
96 | 0 | this.serviceInfoCopies.put(entry.getQname(), this.serviceInfoCopyHolder.get(entry.getQname())); |
97 | 0 | this.publishedServiceNameFinder.register(entry, entry.getQname()); |
98 | 0 | } |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
private ServiceInfo createServiceInfoAndServiceInfoCopy(ServiceDefinition serviceDef) { |
108 | 0 | ServiceInfo copiedInfo = this.serviceInfoCopies.get(serviceDef.getServiceName()); |
109 | |
|
110 | 0 | if (copiedInfo == null) { |
111 | |
|
112 | 0 | copiedInfo = new ServiceInfo(); |
113 | 0 | copiedInfo.setServiceDefinition((ServiceDefinition) ObjectUtils.deepCopy(serviceDef)); |
114 | 0 | copiedInfo.setChecksum(copiedInfo.objectToChecksum(serviceDef)); |
115 | 0 | } else if (!serviceDef.isSame(copiedInfo.getServiceDefinition(serviceLocator.getMessageHelper()))) { |
116 | |
|
117 | 0 | copiedInfo.setServiceDefinition((ServiceDefinition) ObjectUtils.deepCopy(serviceDef)); |
118 | 0 | copiedInfo.setChecksum(copiedInfo.objectToChecksum(serviceDef)); |
119 | |
} |
120 | 0 | this.serviceInfoCopyHolder.put(serviceDef.getServiceName(), copiedInfo); |
121 | |
|
122 | |
|
123 | 0 | if (serviceDef.getServiceEndPoint() == null) { |
124 | 0 | System.err.println("the service def:" + serviceDef); |
125 | |
|
126 | |
} |
127 | 0 | return new ServiceInfo(serviceDef, this.serverIp, copiedInfo.getChecksum()); |
128 | |
} |
129 | |
|
130 | |
private ServiceInfo getForwardHandlerServiceInfo(ServiceDefinition serviceDef) { |
131 | 0 | ForwardedCallHandler callHandler = new ForwardedCallHandlerImpl(); |
132 | |
|
133 | 0 | ServiceDefinition serviceDefinition = new JavaServiceDefinition(); |
134 | 0 | serviceDefinition.setBusSecurity(serviceDef.getBusSecurity()); |
135 | 0 | if (serviceDef.getLocalServiceName() == null && serviceDef.getServiceName() != null) { |
136 | 0 | serviceDefinition.setServiceName(new QName(serviceDef.getServiceName().getNamespaceURI(), serviceDef.getServiceName().getLocalPart() + KSBConstants.FORWARD_HANDLER_SUFFIX)); |
137 | |
} else { |
138 | 0 | serviceDefinition.setLocalServiceName(serviceDef.getLocalServiceName() + KSBConstants.FORWARD_HANDLER_SUFFIX); |
139 | 0 | serviceDefinition.setServiceNameSpaceURI(serviceDef.getServiceNameSpaceURI()); |
140 | |
} |
141 | 0 | serviceDefinition.setMessageExceptionHandler(serviceDef.getMessageExceptionHandler()); |
142 | 0 | serviceDefinition.setMillisToLive(serviceDef.getMillisToLive()); |
143 | 0 | serviceDefinition.setPriority(serviceDef.getPriority()); |
144 | 0 | serviceDefinition.setQueue(serviceDef.getQueue()); |
145 | 0 | serviceDefinition.setRetryAttempts(serviceDef.getRetryAttempts()); |
146 | 0 | serviceDefinition.setService(callHandler); |
147 | 0 | serviceDefinition.validate(); |
148 | |
|
149 | 0 | return createServiceInfoAndServiceInfoCopy(serviceDefinition); |
150 | |
} |
151 | |
|
152 | |
|
153 | |
public void registerService(ServiceDefinition serviceDefinition, boolean forceRegistryRefresh) { |
154 | 0 | if (serviceDefinition == null) { |
155 | 0 | throw new RuntimeException("Service Definition is null"); |
156 | |
} |
157 | 0 | final Config config = ConfigContext.getCurrentContextConfig(); |
158 | |
|
159 | |
@SuppressWarnings("unchecked") |
160 | 0 | List<ServiceDefinition> services = (List<ServiceDefinition>) config.getObject(Config.BUS_DEPLOYED_SERVICES); |
161 | 0 | if (services == null) { |
162 | 0 | services = new ArrayList<ServiceDefinition>(); |
163 | 0 | config.putObject(Config.BUS_DEPLOYED_SERVICES, services); |
164 | |
} |
165 | |
|
166 | |
|
167 | 0 | removeServicesWithName(serviceDefinition.getServiceName(), services); |
168 | 0 | services.add(serviceDefinition); |
169 | |
|
170 | |
|
171 | 0 | if (forceRegistryRefresh) { |
172 | 0 | run(); |
173 | |
} |
174 | 0 | } |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
|
181 | |
|
182 | |
private void removeServicesWithName(QName name, List<ServiceDefinition> services) { |
183 | 0 | for (Iterator<ServiceDefinition> i = services.iterator(); i.hasNext(); ) { |
184 | 0 | final ServiceDefinition service = i.next(); |
185 | 0 | if (service.getServiceName().equals(name)) { |
186 | 0 | LOG.debug("removing existing service with QName: " + service.getServiceName()); |
187 | 0 | i.remove(); |
188 | |
} |
189 | 0 | } |
190 | 0 | } |
191 | |
|
192 | |
public void registerTempService(ServiceDefinition serviceDefinition, Object service) { |
193 | 0 | ServiceInfo serviceInfo = new ServiceInfo(serviceDefinition); |
194 | 0 | Object existingService = getService(serviceInfo.getQname()); |
195 | 0 | if (existingService != null) { |
196 | 0 | throw new RuntimeException("Service with that name is already registered"); |
197 | |
} |
198 | |
try { |
199 | 0 | ServerSideRemotedServiceHolder serviceHolder = |
200 | |
ServiceExporterFactory.getServiceExporter(serviceInfo, serviceLocator).getServiceExporter(service); |
201 | 0 | this.publishedTempServices.put(serviceInfo.getQname(), serviceHolder); |
202 | 0 | this.publishedTempServiceNameFinder.register(serviceInfo, serviceInfo.getQname()); |
203 | |
|
204 | 0 | LOG.debug("Registered temp service " + serviceDefinition.getServiceName()); |
205 | 0 | } catch (Exception e) { |
206 | 0 | throw new RuntimeException(e); |
207 | 0 | } |
208 | 0 | } |
209 | |
|
210 | |
public ServerSideRemotedServiceHolder getRemotedServiceHolder(QName qname) { |
211 | 0 | final ServerSideRemotedServiceHolder serviceHolder = this.publishedServices.get(qname); |
212 | 0 | return serviceHolder != null ? serviceHolder : this.publishedTempServices.get(qname); |
213 | |
} |
214 | |
|
215 | |
public Object getService(QName qName, String url) { |
216 | 0 | ServerSideRemotedServiceHolder serviceHolder = this.publishedServices.get(qName); |
217 | 0 | if (serviceHolder != null && serviceHolder.getServiceInfo().getEndpointUrl().equals(url)) { |
218 | 0 | return serviceHolder.getInjectedPojo(); |
219 | |
} |
220 | |
|
221 | 0 | serviceHolder = this.publishedTempServices.get(qName); |
222 | 0 | if (serviceHolder != null && serviceHolder.getServiceInfo().getEndpointUrl().equals(url)) { |
223 | 0 | return serviceHolder.getInjectedPojo(); |
224 | |
} |
225 | |
|
226 | 0 | return null; |
227 | |
} |
228 | |
|
229 | |
public Object getLocalService(QName serviceName) { |
230 | 0 | ServerSideRemotedServiceHolder serviceHolder = this.publishedServices.get(serviceName); |
231 | 0 | if (serviceHolder == null) { |
232 | 0 | return null; |
233 | |
} |
234 | 0 | return serviceHolder.getInjectedPojo(); |
235 | |
} |
236 | |
|
237 | |
public Object getService(QName qname) { |
238 | 0 | ServiceHolder serviceHolder = getRemotedServiceHolder(qname); |
239 | 0 | if (serviceHolder != null) { |
240 | |
try { |
241 | 0 | Object service = serviceHolder.getService(); |
242 | 0 | return service; |
243 | 0 | } catch (Exception e) { |
244 | 0 | this.removeRemoteServiceFromRegistry(qname); |
245 | |
} |
246 | |
} |
247 | 0 | if (!StringUtils.isEmpty(qname.getNamespaceURI())) { |
248 | 0 | return getService(new QName(qname.getLocalPart())); |
249 | |
} |
250 | 0 | return null; |
251 | |
} |
252 | |
|
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
public QName getServiceName(String url){ |
260 | 0 | QName qname = null; |
261 | 0 | qname = this.publishedServiceNameFinder.lookup(url); |
262 | |
|
263 | |
|
264 | 0 | if (qname == null) { |
265 | 0 | qname = this.publishedTempServiceNameFinder.lookup(url); |
266 | |
} |
267 | |
|
268 | 0 | return qname; |
269 | |
} |
270 | |
|
271 | |
public void removeRemoteServiceFromRegistry(QName serviceName) { |
272 | |
ServerSideRemotedServiceHolder serviceHolder; |
273 | 0 | serviceHolder = this.publishedTempServices.remove(serviceName); |
274 | 0 | if (serviceHolder != null){ |
275 | 0 | this.publishedTempServiceNameFinder.remove(serviceHolder.getServiceInfo().getEndpointUrl()); |
276 | |
} |
277 | 0 | } |
278 | |
|
279 | |
public void refresh() { |
280 | 0 | run(); |
281 | 0 | } |
282 | |
|
283 | |
public synchronized void run() { |
284 | 0 | String serviceNamespace = ConfigContext.getCurrentContextConfig().getServiceNamespace(); |
285 | 0 | LOG.debug("Checking for newly published services on service namespace " + serviceNamespace + " ..."); |
286 | 0 | this.serverIp = RiceUtilities.getIpNumber(); |
287 | |
|
288 | 0 | String serviceServletUrl = (String) ConfigContext.getConfig(ClassLoaderUtils.getDefaultClassLoader()).getProperty(Config.SERVICE_SERVLET_URL); |
289 | 0 | if (serviceServletUrl == null) { |
290 | 0 | throw new RuntimeException("No service url provided to locate services. This is configured in the KSBConfigurer."); |
291 | |
} |
292 | |
|
293 | |
|
294 | |
|
295 | 0 | List<ServiceDefinition> javaServices = (List<ServiceDefinition>) ConfigContext.getCurrentContextConfig().getObject(Config.BUS_DEPLOYED_SERVICES); |
296 | |
|
297 | 0 | List<ServiceInfo> configuredJavaServices = new ArrayList<ServiceInfo>(); |
298 | 0 | for (ServiceDefinition serviceDef: javaServices) { |
299 | 0 | configuredJavaServices.add(createServiceInfoAndServiceInfoCopy(serviceDef)); |
300 | 0 | configuredJavaServices.add(getForwardHandlerServiceInfo(serviceDef)); |
301 | |
} |
302 | |
|
303 | 0 | List<ServiceInfo> configuredServices = new ArrayList<ServiceInfo>(); |
304 | 0 | configuredServices.addAll(configuredJavaServices); |
305 | 0 | List<ServiceInfo> fetchedServices = null; |
306 | |
|
307 | |
|
308 | |
|
309 | 0 | if (ConfigContext.getCurrentContextConfig().getDevMode() || ConfigContext.getCurrentContextConfig().getBatchMode()) { |
310 | 0 | fetchedServices = new ArrayList<ServiceInfo>(); |
311 | |
} else { |
312 | |
|
313 | 0 | fetchedServices = this.getServiceRegistry().findLocallyPublishedServices(RiceUtilities.getIpNumber(), serviceNamespace); |
314 | |
} |
315 | |
|
316 | 0 | RoutingTableDiffCalculator diffCalc = new RoutingTableDiffCalculator(); |
317 | 0 | diffCalc.setEnMessageHelper(serviceLocator.getMessageHelper()); |
318 | 0 | boolean needUpdated = diffCalc.calculateServerSideUpdateLists(configuredServices, fetchedServices); |
319 | 0 | if (needUpdated) { |
320 | 0 | boolean updateSRegTable = true; |
321 | 0 | if (ConfigContext.getCurrentContextConfig().getDevMode() || ConfigContext.getCurrentContextConfig().getBatchMode()) { |
322 | 0 | updateSRegTable = false; |
323 | |
} |
324 | 0 | if (updateSRegTable) { |
325 | 0 | getServiceRegistry().saveEntries(diffCalc.getServicesNeedUpdated()); |
326 | 0 | getServiceRegistry().removeEntries(diffCalc.getServicesNeedRemoved()); |
327 | |
} |
328 | 0 | this.publishedServices.clear(); |
329 | 0 | this.serviceInfoCopies.clear(); |
330 | 0 | publishServiceList(diffCalc.getMasterServiceList()); |
331 | 0 | } else if (this.publishedServices.isEmpty()) { |
332 | 0 | publishServiceList(configuredServices); |
333 | |
} |
334 | 0 | this.serviceInfoCopyHolder.clear(); |
335 | 0 | LOG.debug("...Finished checking for remote services."); |
336 | 0 | } |
337 | |
|
338 | |
private void publishServiceList(List<ServiceInfo> services) { |
339 | 0 | for (ServiceInfo serviceInfo : services) { |
340 | |
try { |
341 | 0 | registerService(serviceInfo, serviceInfo.getServiceDefinition(serviceLocator.getMessageHelper()).getService()); |
342 | 0 | } catch (Exception e) { |
343 | 0 | LOG.error("Encountered error registering service " + serviceInfo.getQname(), e); |
344 | 0 | this.publishedServices.remove(serviceInfo.getQname()); |
345 | 0 | this.serviceInfoCopies.remove(serviceInfo.getQname()); |
346 | 0 | this.publishedServiceNameFinder.remove(serviceInfo.getEndpointUrl()); |
347 | 0 | continue; |
348 | 0 | } |
349 | |
} |
350 | 0 | } |
351 | |
|
352 | |
public boolean isStarted() { |
353 | 0 | return this.started; |
354 | |
} |
355 | |
|
356 | |
public synchronized void start() throws Exception { |
357 | 0 | if (isStarted()) { |
358 | 0 | return; |
359 | |
} |
360 | 0 | LOG.info("Starting the Service Registry..."); |
361 | 0 | run(); |
362 | 0 | if (!ConfigContext.getCurrentContextConfig().getDevMode()) { |
363 | 0 | int refreshRate = ConfigContext.getCurrentContextConfig().getRefreshRate(); |
364 | 0 | this.future = serviceLocator.getScheduledPool()==null?KSBServiceLocator.getScheduledPool().scheduleWithFixedDelay(this, 30, refreshRate, TimeUnit.SECONDS) |
365 | |
:serviceLocator.getScheduledPool().scheduleWithFixedDelay(this, 30, refreshRate, TimeUnit.SECONDS); |
366 | |
} |
367 | 0 | this.started = true; |
368 | 0 | LOG.info("...Service Registry successfully started."); |
369 | 0 | } |
370 | |
|
371 | |
public void stop() throws Exception { |
372 | 0 | LOG.info("Stopping the Service Registry..."); |
373 | |
|
374 | 0 | if (this.future != null) { |
375 | 0 | if (!this.future.cancel(false)) { |
376 | 0 | LOG.warn("Failed to cancel the RemotedServiceRegistry."); |
377 | |
} |
378 | 0 | this.future = null; |
379 | |
} |
380 | 0 | List<ServiceInfo> fetchedServices = this.getServiceRegistry().findLocallyPublishedServices(RiceUtilities.getIpNumber(), ConfigContext.getCurrentContextConfig().getServiceNamespace()); |
381 | 0 | this.getServiceRegistry().markServicesDead(fetchedServices); |
382 | 0 | this.publishedServices.clear(); |
383 | 0 | this.getPublishedTempServices().clear(); |
384 | 0 | this.serviceInfoCopies.clear(); |
385 | 0 | this.started = false; |
386 | 0 | LOG.info("...Service Registry successfully stopped."); |
387 | 0 | } |
388 | |
|
389 | |
public String getContents(String indent, boolean servicePerLine) { |
390 | 0 | String content = indent + "RemotedServiceRegistryImpl services="; |
391 | |
|
392 | 0 | for (ServiceHolder serviceHolder : this.publishedServices.values()) { |
393 | 0 | if (servicePerLine) { |
394 | 0 | content += indent + "+++" + serviceHolder.getServiceInfo().toString() + "\n"; |
395 | |
} else { |
396 | 0 | content += serviceHolder.getServiceInfo().toString() + ", "; |
397 | |
} |
398 | |
} |
399 | 0 | return content; |
400 | |
} |
401 | |
|
402 | |
public ServiceRegistry getServiceRegistry() { |
403 | 0 | return serviceRegistry == null ? KSBServiceLocator.getServiceRegistry() : serviceRegistry; |
404 | |
} |
405 | |
|
406 | |
public Map<QName, ServerSideRemotedServiceHolder> getPublishedServices() { |
407 | 0 | if (!isStarted()) { |
408 | |
try { |
409 | 0 | start(); |
410 | 0 | } catch (Exception e) { |
411 | 0 | throw new ConfigurationException(e); |
412 | 0 | } |
413 | |
} |
414 | 0 | return this.publishedServices; |
415 | |
} |
416 | |
|
417 | |
public Map<QName, ServerSideRemotedServiceHolder> getPublishedTempServices() { |
418 | 0 | return this.publishedTempServices; |
419 | |
} |
420 | |
|
421 | |
public void setServiceRegistry(ServiceRegistry serviceRegistry) { |
422 | 0 | this.serviceRegistry = serviceRegistry; |
423 | 0 | } |
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
public KSBContextServiceLocator getServiceLocator() { |
429 | 0 | return this.serviceLocator; |
430 | |
} |
431 | |
|
432 | |
|
433 | |
|
434 | |
|
435 | |
public void setServiceLocator(KSBContextServiceLocator serviceLocator) { |
436 | 0 | this.serviceLocator = serviceLocator; |
437 | 0 | } |
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
|
445 | |
|
446 | |
|
447 | 0 | private static class ServiceNameFinder { |
448 | |
|
449 | |
|
450 | |
|
451 | |
|
452 | 0 | private Map<String, QName> servicePathToQName = Collections.synchronizedMap(new HashMap<String, QName>()); |
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
|
458 | |
|
459 | |
|
460 | |
|
461 | |
|
462 | |
|
463 | |
|
464 | |
|
465 | |
|
466 | |
|
467 | |
private String trimServiceUrlBase(String url) { |
468 | 0 | String trimmedUrl = |
469 | |
StringUtils.removeStart(url, ConfigContext.getCurrentContextConfig().getEndPointUrl()); |
470 | |
|
471 | 0 | if (trimmedUrl.length() == url.length()) { |
472 | |
|
473 | |
|
474 | 0 | URI serviceUri = URI.create(url); |
475 | 0 | URI endpointUrlBase = URI.create(ConfigContext.getCurrentContextConfig().getEndPointUrl()); |
476 | |
|
477 | 0 | String reqPath = serviceUri.getPath(); |
478 | 0 | String basePath = endpointUrlBase.getPath(); |
479 | |
|
480 | 0 | trimmedUrl = StringUtils.removeStart(reqPath, basePath); |
481 | |
} |
482 | |
|
483 | 0 | return trimmedUrl; |
484 | |
} |
485 | |
|
486 | |
|
487 | |
|
488 | |
|
489 | |
|
490 | |
|
491 | |
|
492 | |
public void register(ServiceInfo entry, QName serviceName) { |
493 | 0 | String serviceUrlBase = trimServiceUrlBase(entry.getEndpointUrl()); |
494 | |
|
495 | 0 | if (serviceUrlBase.endsWith("/")) |
496 | 0 | serviceUrlBase = StringUtils.chop(serviceUrlBase); |
497 | |
|
498 | 0 | servicePathToQName.put(serviceUrlBase, serviceName); |
499 | 0 | } |
500 | |
|
501 | |
|
502 | |
|
503 | |
|
504 | |
|
505 | |
|
506 | |
public void remove(String serviceUrl) { |
507 | 0 | servicePathToQName.remove(trimServiceUrlBase(serviceUrl)); |
508 | 0 | } |
509 | |
|
510 | |
|
511 | |
|
512 | |
|
513 | |
|
514 | |
|
515 | |
|
516 | |
public QName lookup(String serviceUrl) { |
517 | 0 | String serviceUrlBase = trimServiceUrlBase(serviceUrl); |
518 | |
|
519 | |
|
520 | 0 | if (serviceUrlBase.length() > 0 && serviceUrlBase.lastIndexOf('?') != -1) { |
521 | 0 | serviceUrlBase = serviceUrlBase.substring(0, serviceUrlBase.lastIndexOf('?')); |
522 | |
} |
523 | |
|
524 | 0 | QName qname = null; |
525 | |
|
526 | 0 | while (qname == null) { |
527 | 0 | qname = servicePathToQName.get(serviceUrlBase); |
528 | |
|
529 | 0 | int lastSeparatorIndex = serviceUrlBase.lastIndexOf('/'); |
530 | 0 | if (lastSeparatorIndex == -1) |
531 | 0 | break; |
532 | 0 | serviceUrlBase = serviceUrlBase.substring(0, lastSeparatorIndex); |
533 | 0 | } |
534 | |
|
535 | 0 | return qname; |
536 | |
} |
537 | |
|
538 | |
} |
539 | |
|
540 | |
} |