private void _registerServletContext(ServletContext servletContext) {
    BundleContext bundleContext = _framework.getBundleContext();

    Hashtable<String, Object> properties = new Hashtable<String, Object>();

    properties.put(ServicePropsKeys.BEAN_ID, ServletContext.class.getName());
    properties.put(ServicePropsKeys.ORIGINAL_BEAN, Boolean.TRUE);
    properties.put(ServicePropsKeys.VENDOR, ReleaseInfo.getVendor());

    bundleContext.registerService(
        new String[] {ServletContext.class.getName()}, servletContext, properties);
  }
예제 #2
0
  protected void registerPortalInitialized() {
    Registry registry = RegistryUtil.getRegistry();

    Map<String, Object> properties = new HashMap<>();

    properties.put("module.service.lifecycle", "portal.initialized");
    properties.put("service.vendor", ReleaseInfo.getVendor());
    properties.put("service.version", ReleaseInfo.getVersion());

    _portalModuleServiceLifecycleServiceRegistration =
        registry.registerService(
            ModuleServiceLifecycle.class, new ModuleServiceLifecycle() {}, properties);

    properties = new HashMap<>();

    properties.put("bean.id", ServletContext.class.getName());
    properties.put("original.bean", Boolean.TRUE);
    properties.put("service.vendor", ReleaseInfo.getVendor());

    _servletContextServiceRegistration =
        registry.registerService(ServletContext.class, getServletContext(), properties);
  }
  private void _registerService(BundleContext bundleContext, String beanName, Object bean) {

    Set<Class<?>> interfaces = _getInterfaces(bean);

    if (interfaces.isEmpty()) {
      return;
    }

    List<String> names = new ArrayList<String>(interfaces.size());

    for (Class<?> interfaceClass : interfaces) {
      String interfaceClassName = interfaceClass.getName();

      if (!_isIgnoredInterface(interfaceClassName)) {
        names.add(interfaceClassName);
      }
    }

    if (names.isEmpty()) {
      return;
    }

    Hashtable<String, Object> properties = new Hashtable<String, Object>();

    Map<String, Object> osgiBeanProperties = OSGiBeanProperties.Convert.fromObject(bean);

    if (osgiBeanProperties != null) {
      properties.putAll(osgiBeanProperties);
    }

    properties.put(ServicePropsKeys.BEAN_ID, beanName);
    properties.put(ServicePropsKeys.ORIGINAL_BEAN, Boolean.TRUE);
    properties.put(ServicePropsKeys.VENDOR, ReleaseInfo.getVendor());

    bundleContext.registerService(names.toArray(new String[names.size()]), bean, properties);
  }
  private Map<String, String> _buildFrameworkProperties(Class<?> clazz) {
    Map<String, String> properties = new HashMap<String, String>();

    properties.put(Constants.BUNDLE_DESCRIPTION, ReleaseInfo.getReleaseInfo());
    properties.put(Constants.BUNDLE_NAME, ReleaseInfo.getName());
    properties.put(Constants.BUNDLE_VENDOR, ReleaseInfo.getVendor());
    properties.put(Constants.BUNDLE_VERSION, ReleaseInfo.getVersion());
    properties.put(FrameworkPropsKeys.FELIX_FILEINSTALL_DIR, _getFelixFileInstallDir());
    properties.put(FrameworkPropsKeys.FELIX_FILEINSTALL_LOG_LEVEL, _getFelixFileInstallLogLevel());
    properties.put(
        FrameworkPropsKeys.FELIX_FILEINSTALL_POLL,
        String.valueOf(PropsValues.MODULE_FRAMEWORK_AUTO_DEPLOY_INTERVAL));
    properties.put(
        FrameworkPropsKeys.FELIX_FILEINSTALL_TMPDIR,
        SystemProperties.get(SystemProperties.TMP_DIR));
    properties.put(
        Constants.FRAMEWORK_BEGINNING_STARTLEVEL,
        String.valueOf(PropsValues.MODULE_FRAMEWORK_BEGINNING_START_LEVEL));
    properties.put(Constants.FRAMEWORK_BUNDLE_PARENT, Constants.FRAMEWORK_BUNDLE_PARENT_APP);
    properties.put(Constants.FRAMEWORK_STORAGE, PropsValues.MODULE_FRAMEWORK_STATE_DIR);

    properties.put("eclipse.security", null);
    properties.put("java.security.manager", null);
    properties.put("org.osgi.framework.security", null);

    ProtectionDomain protectionDomain = clazz.getProtectionDomain();

    CodeSource codeSource = protectionDomain.getCodeSource();

    URL codeSourceURL = codeSource.getLocation();

    properties.put(FrameworkPropsKeys.OSGI_FRAMEWORK, codeSourceURL.toExternalForm());

    File frameworkFile = new File(codeSourceURL.getFile());

    properties.put(FrameworkPropsKeys.OSGI_INSTALL_AREA, frameworkFile.getParent());

    Properties extraProperties =
        PropsUtil.getProperties(PropsKeys.MODULE_FRAMEWORK_PROPERTIES, true);

    for (Map.Entry<Object, Object> entry : extraProperties.entrySet()) {
      String key = (String) entry.getKey();
      String value = (String) entry.getValue();

      // We need to support an empty string and a null value distinctly.
      // This is due to some different behaviors between OSGi
      // implementations. If a property is passed as xyz= it will be
      // treated as an empty string. Otherwise, xyz=null will be treated
      // as an explicit null value.

      if (value.equals(StringPool.NULL)) {
        value = null;
      }

      properties.put(key, value);
    }

    String systemPackagesExtra = _getSystemPackagesExtra();

    properties.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, systemPackagesExtra);

    return properties;
  }
예제 #5
0
  protected void processStartupEvents() throws Exception {

    // Print release information

    Class<?> clazz = getClass();

    ClassLoader classLoader = clazz.getClassLoader();

    try (InputStream inputStream =
        classLoader.getResourceAsStream("com/liferay/portal/events/dependencies/startup.txt")) {

      System.out.println(_toString(inputStream));
    }

    System.out.println("Starting " + ReleaseInfo.getReleaseInfo() + "\n");

    if (_log.isDebugEnabled()) {
      _log.debug("Portal Resiliency - NOT SUPPORTED");
    }

    // Shutdown hook

    if (_log.isDebugEnabled()) {
      _log.debug("Add shutdown hook");
    }

    Runtime runtime = Runtime.getRuntime();

    runtime.addShutdownHook(new Thread(new ShutdownHook()));

    // MySQL version

    DB db = DBManagerUtil.getDB();

    if ((db.getDBType() == DBType.MYSQL) && GetterUtil.getFloat(db.getVersionString()) < 5.6F) {

      throw new ServletException(
          "Please upgrade to at least MySQL 5.6.4. The portal no "
              + "longer supports older versions of MySQL.");
    }

    // Check required build number

    if (_log.isDebugEnabled()) {
      _log.debug("Check required build number");
    }

    DBUpgrader.checkRequiredBuildNumber(ReleaseInfo.getParentBuildNumber());

    Registry registry = RegistryUtil.getRegistry();

    Map<String, Object> properties = new HashMap<>();

    properties.put("module.service.lifecycle", "database.initialized");
    properties.put("service.vendor", ReleaseInfo.getVendor());
    properties.put("service.version", ReleaseInfo.getVersion());

    _dbModuleServiceLifecycleServiceRegistration =
        registry.registerService(
            ModuleServiceLifecycle.class, new ModuleServiceLifecycle() {}, properties);

    // Check class names

    if (_log.isDebugEnabled()) {
      _log.debug("Check class names");
    }

    ClassNameLocalServiceUtil.checkClassNames();
  }