@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)); }
@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")); }
/** * 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()); }
/** * 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()); }
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(),
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(),