/** * Returns ICF connector info manager that manages local connectors. The * manager will be created if it does not exist yet. * * @return ICF connector info manager that manages local connectors */ private ConnectorInfoManager getLocalConnectorInfoManager() { if (null == localConnectorInfoManager) { URL[] urls = bundleURIs.stream().map(MiscUtil::toUrlUnchecked).toArray(URL[]::new); localConnectorInfoManager = connectorInfoManagerFactory.getLocalManager(urls); } return localConnectorInfoManager; }
/** * Returns local manager or null. * @param dataProvider * @param fact * @return null in case configuration is NOT provided * @throws RuntimeException if creation fails although properties were provided */ private static ConnectorInfoManager getLocalManager(final DataProvider dataProvider, final ConnectorInfoManagerFactory fact) { ConnectorInfoManager manager = null; // try to load bundleJar property (which should be set by ant) File bundleJar = new File(((String) dataProvider.getTestSuiteAttribute("bundleJar")).trim()); Assert.assertTrue("BundleJar does not exist: " + bundleJar.getAbsolutePath(), bundleJar .isFile()); try { manager = fact.getLocalManager(bundleJar.toURI().toURL()); } catch (MalformedURLException ex) { throw ContractException.wrap(ex); } return manager; }
/** * Returns local manager or null. * * @param dataProvider * @param fact * @return null in case configuration is NOT provided * @throws RuntimeException if creation fails although properties were provided */ private static ConnectorInfoManager getLocalManager(final DataProvider dataProvider, final ConnectorInfoManagerFactory fact) { ConnectorInfoManager manager = null; // try to load bundleJar property (which should be set by ant) File bundleJar = new File(((String) dataProvider.getTestSuiteAttribute("bundleJar")).trim()); assertTrue(bundleJar.isFile(), "BundleJar does not exist: " + bundleJar.getAbsolutePath()); try { manager = fact.getLocalManager(bundleJar.toURI().toURL()); } catch (MalformedURLException ex) { throw ContractException.wrap(ex); } return manager; }
/** * Returns local manager or null. * * @param dataProvider * @param fact * @return null in case configuration is NOT provided * @throws RuntimeException if creation fails although properties were provided */ private static ConnectorInfoManager getLocalManager(final DataProvider dataProvider, final ConnectorInfoManagerFactory fact) { ConnectorInfoManager manager = null; // try to load bundleJar property (which should be set by ant) File bundleJar = new File(((String) dataProvider.getTestSuiteAttribute("bundleJar")).trim()); assertTrue("BundleJar does not exist: " + bundleJar.getAbsolutePath(), bundleJar.isFile()); try { manager = fact.getLocalManager(bundleJar.toURI().toURL()); } catch (MalformedURLException ex) { throw ContractException.wrap(ex); } return manager; }
private void initLocal(final URI location) { // 1. Find bundles inside local directory File bundleDirectory = new File(location); String[] bundleFiles = bundleDirectory.list(); if (bundleFiles == null) { throw new NotFoundException("Local bundles directory " + location); } List<URL> bundleFileURLs = new ArrayList<>(); for (String file : bundleFiles) { try { bundleFileURLs.add(IOUtil.makeURL(bundleDirectory, file)); } catch (IOException ignore) { // ignore exception and don't add bundle LOG.debug("{}/{} is not a valid connector bundle", bundleDirectory.toString(), file, ignore); } } if (bundleFileURLs.isEmpty()) { LOG.warn("No connector bundles found in {}", location); } LOG.debug("Configuring local connector server:" + "\n\tFiles: {}", bundleFileURLs); // 2. Get connector info manager ConnectorInfoManager manager = ConnectorInfoManagerFactory.getInstance().getLocalManager( bundleFileURLs.toArray(new URL[bundleFileURLs.size()])); if (manager == null) { throw new NotFoundException("Local ConnectorInfoManager"); } connInfoManagers.put(location, manager); }
/** * Test if bundle internal configuration and dependencies are OK * @param bundleUrl * tested bundle URL * @return true if OK */ private Boolean isThisBundleCompatible(URL bundleUrl) { if (null == bundleUrl) return false; try { ConnectorInfoManager localManager = ConnectorInfoManagerFactory.getInstance().getLocalManager(bundleUrl); List<ConnectorInfo> connectorInfos = localManager.getConnectorInfos(); if (connectorInfos == null || connectorInfos.isEmpty()) { LOGGER.error("Strange error happened. ConnId is not accepting bundle {}. But no error is indicated.", bundleUrl); return false; } else { LOGGER.trace("Found {} compatible connectors in bundle {}", connectorInfos.size(), bundleUrl); return true; } } catch (Exception ex) { if (LOGGER.isDebugEnabled()) { LOGGER.error("Error instantiating ICF bundle using URL '{}': {}-{}", new Object[] { bundleUrl, ex.getMessage(), ex}); } else { LOGGER.error("Error instantiating ICF bundle using URL '{}': {}", new Object[] { bundleUrl, ex.getMessage()}); } return false; } }