@Override public synchronized Service registerService(Service service) { if (!_services.containsKey(service.getName())) { _services.put(service.getName(), new LinkedList<Service>()); } _services.get(service.getName()).add(service); if (_logger.isDebugEnabled()) { _logger.debug("Registered Service '" + service.getName() + "'."); } return service; }
/** * Create a RemoteEndpoint representation from a registered service. * @param service registered service * @return reference to this RemoteEndpoint */ public static RemoteEndpoint fromService(Service service) { return new RemoteEndpoint(service.getName(), service.getDomain().getName(), null, null, RemoteInterface.fromInterface(service.getInterface())); } }
/** * Replaces an existing service registration (e.g. reference binding) with a test handler using * the same contract as the existing service provider. If multiple services are registered with * the specified name, the first one found is used. Generally speaking, it's not a good idea * to use this method if you have multiple services registered with the same name. In that * situation, use the removeService() and registerService() methods instead. * @param name name of the service to replace * @param handler implementation to use as the service provider * @throws SwitchYardException if a service with the specified name does not exist */ public void replaceService(QName name, ExchangeHandler handler) throws SwitchYardException { List<Service> services = getServiceDomain().getServices(name); if (services.isEmpty()) { throw new SwitchYardException("Failed to replace service: " + name + ". No service is registered with that name."); } // select the service to replace Service replacedService = services.get(0); replacedService.unregister(); // add the replacement service getServiceDomain().registerService(name, replacedService.getInterface(), handler, replacedService.getServiceMetadata()); }
@Override public synchronized void unregisterService(Service service) { List<Service> serviceList =_services.get(service.getName()); if (serviceList != null) { serviceList.remove(service); if (_logger.isDebugEnabled()) { QName serviceName = service.getName(); String domainName = ""; if ((service.getDomain() != null) && (service.getDomain().getName() != null)) { domainName = service.getDomain().getName().toString(); } _logger.debug("Unregistered Service '" + serviceName + "' from ServiceDomain '" + domainName + "'."); } } }
ServiceOperation providerOp = service.getInterface().getOperation(consumerOp.getName()); if (service.getInterface().getOperations().size() == 1) { providerOp = service.getInterface().getOperations().iterator().next(); } else { throw RuntimeMessages.MESSAGES.operationNotIncluded(consumerOp.getName(), service.getName().toString()); for (Policy policy : service.getServiceMetadata().getRequiredPolicies()) { PolicyUtil.require(exchange, policy);
activation.getActivator().deactivateService(service.getName(), activation.getHandler()); } catch (Throwable e) { BaseDeployLogger.ROOT_LOGGER.errorDeactivatingService(e); service.unregister(); service.unregister();
/** * Gets the SecurityMetadata from the Exchange. * @param exchange the Exchange * @return the SecurityMetadata */ public static final SecurityMetadata getSecurityMetadata(Exchange exchange) { Source source = null; ServiceDomain serviceDomain = null; ServiceSecurity serviceSecurity = null; Service service = exchange.getProvider(); if (service != null) { source = Source.PROVIDER; serviceDomain = service.getDomain(); serviceSecurity = service.getServiceMetadata().getSecurity(); } if (serviceSecurity == null) { ServiceReference serviceReference = exchange.getConsumer(); if (serviceReference != null) { source = Source.CONSUMER; serviceDomain = serviceReference.getDomain(); serviceSecurity = serviceReference.getServiceMetadata().getSecurity(); } } return new SecurityMetadata(source, serviceDomain, serviceSecurity); }
/** * Removes all service providers from the domain with the specified name. * @param serviceName qualified name of the service */ public void removeService(QName serviceName) { for (Service service : getServiceDomain().getServices(serviceName)) { service.unregister(); } }
@Test public void testRegisterServiceWithoutInterface() { Service service = _domain.registerService( new QName("no-interface"), null, new MockHandler()); // default interface should be used, which has one operation - process() Assert.assertNotNull(service.getInterface()); Assert.assertTrue(service.getInterface().getOperations().size() == 1); Assert.assertNotNull(service.getInterface().getOperation( ServiceInterface.DEFAULT_OPERATION)); }
public void handleMessage(final Exchange exchange) throws HandlerException { final Service service = exchange.getProvider(); ServiceSecurity serviceSecurity = service.getServiceMetadata().getSecurity(); if (serviceSecurity != null) { SecurityContext securityContext = _securityContextManager.getContext(exchange); service.getProviderHandler().handleMessage(exchange);
ServiceOperation providerOp = service.getInterface().getOperation(consumerOp.getName()); if (service.getInterface().getOperations().size() == 1) { providerOp = service.getInterface().getOperations().iterator().next(); } else { throw RuntimeMessages.MESSAGES.operationNotIncluded(consumerOp.getName(), service.getName().toString()); for (Policy policy : service.getServiceMetadata().getRequiredPolicies()) { PolicyUtil.require(exchange, policy);
@Override public synchronized void unregisterService(Service service) { List<Service> serviceList =_services.get(service.getName()); if (serviceList != null) { serviceList.remove(service); if (_logger.isDebugEnabled()) { QName serviceName = service.getName(); String domainName = ""; if ((service.getDomain() != null) && (service.getDomain().getName() != null)) { domainName = service.getDomain().getName().toString(); } _logger.debug("Unregistered Service '" + serviceName + "' from ServiceDomain '" + domainName + "'."); } } }
/** * Gets the SecurityMetadata from the Exchange. * @param exchange the Exchange * @return the SecurityMetadata */ public static final SecurityMetadata getSecurityMetadata(Exchange exchange) { Source source = null; ServiceDomain serviceDomain = null; ServiceSecurity serviceSecurity = null; Service service = exchange.getProvider(); if (service != null) { source = Source.PROVIDER; serviceDomain = service.getDomain(); serviceSecurity = service.getServiceMetadata().getSecurity(); } if (serviceSecurity == null) { ServiceReference serviceReference = exchange.getConsumer(); if (serviceReference != null) { source = Source.CONSUMER; serviceDomain = serviceReference.getDomain(); serviceSecurity = serviceReference.getServiceMetadata().getSecurity(); } } return new SecurityMetadata(source, serviceDomain, serviceSecurity); }
/** * Removes all service providers from the domain with the specified name. * @param serviceName qualified name of the service */ public void removeService(QName serviceName) { for (Service service : getServiceDomain().getServices(serviceName)) { service.unregister(); } }
@Test public void testRegisterServiceWithInterface() { Service service = _domain.registerService(new QName("my-interface"), JavaService.fromClass(MyInterface.class), new MockHandler()); // default interface should be used, which has one operation - process() Assert.assertNotNull(service.getInterface()); Assert.assertTrue(service.getInterface().getOperations().size() == 1); Assert.assertNotNull(service.getInterface().getOperation("myOperation")); }
public void handleMessage(final Exchange exchange) throws HandlerException { final Service service = exchange.getProvider(); ServiceSecurity serviceSecurity = service.getServiceMetadata().getSecurity(); if (serviceSecurity != null) { SecurityContext securityContext = _securityContextManager.getContext(exchange); service.getProviderHandler().handleMessage(exchange);
@Override public synchronized Service registerService(Service service) { if (!_services.containsKey(service.getName())) { _services.put(service.getName(), new LinkedList<Service>()); } _services.get(service.getName()).add(service); if (_logger.isDebugEnabled()) { _logger.debug("Registered Service '" + service.getName() + "'."); } return service; }
/** * Replaces an existing service registration (e.g. reference binding) with a test handler using * the same contract as the existing service provider. If multiple services are registered with * the specified name, the first one found is used. Generally speaking, it's not a good idea * to use this method if you have multiple services registered with the same name. In that * situation, use the removeService() and registerService() methods instead. * @param name name of the service to replace * @param handler implementation to use as the service provider * @throws SwitchYardException if a service with the specified name does not exist */ public void replaceService(QName name, ExchangeHandler handler) throws SwitchYardException { List<Service> services = getServiceDomain().getServices(name); if (services.isEmpty()) { throw new SwitchYardException("Failed to replace service: " + name + ". No service is registered with that name."); } // select the service to replace Service replacedService = services.get(0); replacedService.unregister(); // add the replacement service getServiceDomain().registerService(name, replacedService.getInterface(), handler, replacedService.getServiceMetadata()); }