void start(BundleContext::Ptr pContext) { ServiceRef::Ptr pPrefsRef = pContext->registry().findByName(PreferencesService::SERVICE_NAME); AutoPtr<PreferencesService> pPrefs = pPrefsRef->castedInstance<PreferencesService>(); bool enable = pPrefs->configuration()->getBool("auth.simple.enable", true); if (enable) { std::string adminName = pPrefs->configuration()->getString("auth.simple.admin.name", "admin"); std::string adminPasswordHash = pPrefs->configuration()->getString("auth.simple.admin.passwordHash", ""); std::string userName = pPrefs->configuration()->getString("auth.simple.user.name", "user"); std::string userPasswordHash = pPrefs->configuration()->getString("auth.simple.user.passwordHash", ""); std::string salt = pPrefs->configuration()->getString("auth.simple.salt", ""); std::string perms = pPrefs->configuration()->getString("auth.simple.user.permissions", ""); StringTokenizer tok(perms, ",;", StringTokenizer::TOK_TRIM | StringTokenizer::TOK_IGNORE_EMPTY); std::set<std::string> userPermissions; for (StringTokenizer::Iterator it = tok.begin(); it != tok.end(); ++it) { userPermissions.insert(*it); } AutoPtr<SimpleAuthService> pService = new SimpleAuthService(adminName, adminPasswordHash, userName, userPasswordHash, userPermissions, salt); _pService = pContext->registry().registerService("osp.auth", pService, Properties()); } else { pContext->logger().information("Simple authentication service disabled."); } }
void start(BundleContext::Ptr pContext) { MediaTypeMapper::Ptr pMediaTypeMapper = new MediaTypeMapper; std::auto_ptr<std::istream> pStream(pContext->thisBundle()->getResource("mime.types")); if (pStream.get()) { pMediaTypeMapper->load(*pStream); } _pMediaTypeMapperSvc = pContext->registry().registerService(MediaTypeMapper::SERVICE_NAME, pMediaTypeMapper, Properties()); ServiceRef::Ptr pPrefsSvcRef = pContext->registry().findByName("osp.core.preferences"); std::string authServiceName(pContext->thisBundle()->properties().getString("authServiceName", "")); bool cacheResources(pContext->thisBundle()->properties().getBool("cacheResources", false)); bool compressResponse(pContext->thisBundle()->properties().getBool("compressResponses", false)); std::string compressedMediaTypesString(pContext->thisBundle()->properties().getString("compressedMediaTypes", "")); std::string sessionCookiePersistence(pContext->thisBundle()->properties().getString("cookiePersistence", "persistent")); if (pPrefsSvcRef) { Poco::AutoPtr<PreferencesService> pPrefsSvc = pPrefsSvcRef->castedInstance<PreferencesService>(); authServiceName = pPrefsSvc->configuration()->getString("osp.web.authServiceName", authServiceName); cacheResources = pPrefsSvc->configuration()->getBool("osp.web.cacheResources", cacheResources); compressResponse = pPrefsSvc->configuration()->getBool("osp.web.compressResponses", compressResponse); compressedMediaTypesString = pPrefsSvc->configuration()->getString("osp.web.compressedMediaTypes", compressedMediaTypesString); sessionCookiePersistence = pPrefsSvc->configuration()->getString("osp.web.sessionManager.cookiePersistence", sessionCookiePersistence); } Poco::StringTokenizer tok(compressedMediaTypesString, ",", Poco::StringTokenizer::TOK_TRIM | Poco::StringTokenizer::TOK_IGNORE_EMPTY); std::set<std::string> compressedMediaTypes(tok.begin(), tok.end()); AutoPtr<WebServerDispatcher> pWebServerDispatcher = new WebServerDispatcher(pContext, pMediaTypeMapper, authServiceName, compressResponse, compressedMediaTypes, cacheResources); _pWebServerDispatcherSvc = pContext->registry().registerService(WebServerDispatcher::SERVICE_NAME, pWebServerDispatcher, Properties()); WebSessionManager::CookiePersistence cookiePersistence = WebSessionManager::COOKIE_PERSISTENT; if (sessionCookiePersistence == "transient") cookiePersistence = WebSessionManager::COOKIE_TRANSIENT; else if (sessionCookiePersistence != "persistent") pContext->logger().warning(Poco::format("Ignoring invalid value for osp.web.sessionManager.cookiePersistence: '%s'. Valid values are 'transient' or 'persistent'.", sessionCookiePersistence)); AutoPtr<WebSessionManager> pWebSessionManager = new WebSessionManager; pWebSessionManager->setCookiePersistence(cookiePersistence); _pWebSessionManagerSvc = pContext->registry().registerService(WebSessionManager::SERVICE_NAME, pWebSessionManager, Properties()); ServiceRef::Ptr pXPSRef = pContext->registry().findByName("osp.core.xp"); if (pXPSRef) { AutoPtr<ExtensionPointService> pXPS = pXPSRef->castedInstance<ExtensionPointService>(); _pWebServerExtensionPoint = new WebServerExtensionPoint(pContext, pWebServerDispatcher); pXPS->registerExtensionPoint(pContext->thisBundle(), WebServerExtensionPoint::EXTPOINT_DIRECTORY, _pWebServerExtensionPoint); pXPS->registerExtensionPoint(pContext->thisBundle(), WebServerExtensionPoint::EXTPOINT_HANDLER, _pWebServerExtensionPoint); _pWebFilterExtensionPoint = new WebFilterExtensionPoint(pContext, pWebServerDispatcher); pXPS->registerExtensionPoint(pContext->thisBundle(), WebFilterExtensionPoint::EXTPOINT_FILTER, _pWebFilterExtensionPoint); } else { pContext->logger().error("The ExtensionPointService is not available."); } }
void stop(BundleContext::Ptr pContext) { pContext->registry().unregisterService(_pWebSessionManagerSvc); pContext->registry().unregisterService(_pWebServerDispatcherSvc); pContext->registry().unregisterService(_pMediaTypeMapperSvc); _pWebSessionManagerSvc = 0; _pWebServerDispatcherSvc = 0; _pMediaTypeMapperSvc = 0; _pWebServerExtensionPoint = 0; _pWebFilterExtensionPoint = 0; }
void stop(BundleContext::Ptr pContext) { if (_pService) { pContext->registry().unregisterService(_pService); } }
void start(BundleContext::Ptr pContext) { // Create an instance of the GreetingService GreetingService::Ptr pService = new GreetingServiceImpl(pContext); // Register the GreetingService with the ServiceRegistry. _pService = pContext->registry().registerService("com.appinf.osp.samples.GreetingService", pService, Properties()); }
void start(BundleContext::Ptr pContext) { typedef Poco::RemotingNG::ServerHelper<IoT::WebEvent::WebEventNotifier> ServerHelper; Poco::SharedPtr<IoT::WebEvent::WebEventNotifier> pWebEventNotifier = new WebEventNotifierImpl(pContext); std::string oid("io.macchina.services.webeventnotifier"); ServerHelper::RemoteObjectPtr pWebEventNotifierRemoteObject = ServerHelper::createRemoteObject(pWebEventNotifier, oid); ServiceRef::Ptr pServiceRef = pContext->registry().registerService(oid, pWebEventNotifierRemoteObject, Properties()); }
void start(BundleContext::Ptr pContext) { // Obtain the GreetingService object from the Service Registry. ServiceRef::Ptr pServiceRef = pContext->registry().findByName("com.appinf.osp.samples.GreetingService"); if (pServiceRef) { // Service is available - let's invoke it GreetingService::Ptr pService = pServiceRef->castedInstance<GreetingService>(); std::string greeting = pService->greeting(); std::string msg("****** "); msg += greeting; msg += " ******"; pContext->logger().information(msg); } else { // The service is not available pContext->logger().error("The GreetingService is not available."); } }
void start(BundleContext::Ptr pContext) { // find ExtensionPointService using the Service Registry ServiceRef::Ptr pXPSRef = pContext->registry().findByName("osp.core.xp"); if (pXPSRef) { // ExtensionPointService is available AutoPtr<ExtensionPointService> pXPS = pXPSRef->castedInstance<ExtensionPointService>(); // Create an ExtensionPoint ExtensionPoint::Ptr pXP = new TestExtensionPoint(pContext); // Register ExtensionPoint pXPS->registerExtensionPoint(pContext->thisBundle(), "com.appinf.osp.unit.test", pXP); } else { // The service is not available pContext->logger().error("The ExtensionPointService is not available."); } }
void stop(BundleContext::Ptr pContext) { for (std::vector<Poco::OSP::ServiceRef::Ptr>::iterator it = _serviceRefs.begin(); it != _serviceRefs.end(); ++it) { pContext->registry().unregisterService(*it); } _serviceRefs.clear(); for (std::vector<MQTTClientImpl::Ptr>::iterator it = _clients.begin(); it != _clients.end(); ++it) { try { (*it)->disconnect(200); } catch (Poco::Exception& exc) { pContext->logger().log(exc); } } _clients.clear(); ServerHelper::shutdown(); }
void stop(BundleContext::Ptr pContext) { // Unregister the GreetingService pContext->registry().unregisterService(_pService); }