Fórum

Atmosphere Runtime 2.4.6 refuses to load in Liferay Portal 7

John Edward Platts, modificado 6 Anos atrás.

Atmosphere Runtime 2.4.6 refuses to load in Liferay Portal 7

New Member Postagens: 9 Data de Entrada: 08/08/09 Postagens Recentes
Atmosphere Runtime 2.4.6 refuses to load in Liferay Portal 7 because it declares two different ServletContainerInitializer classes in the META-INF/services/javax.servlet.ServletContainerInitializer file of its JAR.

There is a bug in com.liferay.portal.osgi.web.wab.extender.internal.WabBundleProcessor.initServletContainerInitializers(Bundle, ServletContext) that prevents Atmosphere Runtime 2.4.6 from loading in Liferay Portal 7.

The code for com.liferay.portal.osgi.web.wab.extender.internal.WabBundleProcessor can be found at https://github.com/liferay/com-liferay-portal-osgi-web/blob/master/portal-osgi-web-wab-extender/src/main/java/com/liferay/portal/osgi/web/wab/extender/internal/WabBundleProcessor.java.

Here is how initServletContainerInitializers is currently implemented in com.liferay.portal.osgi.web.wab.extender.internal.WabBundleProcessor:
protected void initServletContainerInitializers(
		Bundle bundle, ServletContext servletContext)
	throws IOException {

	BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);

	Enumeration<url> initializerResources = bundle.getResources(
		"META-INF/services/javax.servlet.ServletContainerInitializer");

	if (initializerResources == null) {
		return;
	}

	while (initializerResources.hasMoreElements()) {
		URL url = initializerResources.nextElement();

		try (InputStream inputStream = url.openStream()) {
			String fqcn = StringUtil.read(inputStream);

			processServletContainerInitializerClass(
				fqcn, bundle, bundleWiring, servletContext);
		}
		catch (IOException ioe) {
			_logger.log(Logger.LOG_ERROR, ioe.getMessage(), ioe);
		}
	}
}</url>


Here is the fixed version of initServletContainerInitializers in com.liferay.portal.osgi.web.wab.extender.internal.WabBundleProcessor that would solve the problem of Atmosphere failing to load in Liferay 7:
protected void initServletContainerInitializers(
        Bundle bundle, ServletContext servletContext)
    throws IOException {
    
    BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
    
    Enumeration<url> initializerResources = bundle.getResources(
        "META-INF/services/javax.servlet.ServletContainerInitializer");
    
    if (initializerResources == null) {
        return;
    }
    
    while (initializerResources.hasMoreElements()) {
        URL url = initializerResources.nextElement();
        
        try (InputStream inputStream = url.openStream()) {
            try(UnsyncBufferedReader unsyncBufferedReader =
                new UnsyncBufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
                String line;
                while((line = unsyncBufferedReader.readLine()) != null) {
                    // Remove comments from the line
                    int hashIndex = line.indexOf('#');
                    if(hashIndex == 0) {
                        continue;
                    } else if(hashIndex &gt; 0) {
                        line = line.substring(0, hashIndex);
                    }
                    
                    // Trim line
                    line = line.trim();

                    // Skip over any empty lines
                    if(line.isEmpty()) {
                        continue;
                    }
                    
                    // line should now be a fully qualified name of a class that implements the
                    // javax.servlet.ServletContainerInitializer interface
                    String fqcn = line;
                    
                    processServletContainerInitializerClass(
                        fqcn, bundle, bundleWiring, servletContext);
                }
            }
        }
        catch (IOException ioe) {
            _logger.log(Logger.LOG_ERROR, ioe.getMessage(), ioe);
        }
    }
}</url>
thumbnail
David H Nebinger, modificado 6 Anos atrás.

RE: Atmosphere Runtime 2.4.6 refuses to load in Liferay Portal 7

Liferay Legend Postagens: 14916 Data de Entrada: 02/09/06 Postagens Recentes
Great! If you open a ticket on issues.liferay.com, the issue can get addressed by Liferay folks and perhaps your fix will get included!









Come meet me at the 2017 LSNA!