Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jakartaee-platform-dev] Assumption that WAR can contain SE service files (for CDI extensions) causes TCK failures

Hi,

The CDI TCK makes in 3 of its tests the assumption that a .war can contain a CDI extension (configured by a file in "WEB-INF/classes/META-INF/services") and without a beans.xml is not an bean archive.

They are:
  • ChangeObserverQualifierTest
  • CustomStereotypeTest
  • SyntheticBeanWithLookupTest
For example:

    @Deployment
    public static WebArchive createTestArchive() {
        // no beans.xml + an extension = not a bean archive, bean classes are added through the extension
        return new WebArchiveBuilder()
                .withTestClassPackage(SyntheticBeanWithLookupTest.class)
                .withBuildCompatibleExtension(SyntheticBeanWithLookupExtension.class)
                .withoutBeansXml()
                .build();
    }

GlassFish fails all these tests. We always look in [root]/META-INF to check for this, e.g.:

/**
     * Determine if an archive is a valid bda based on what the spec says about extensions. See section 12.1 which states
     * that if an archive contains an extension but no beans.xml then it is NOT a valid bean deployment archive.
     *
     * @param archive The archive to check.
     * @return false if there is an extension and no beans.xml true otherwise
     */
    public static boolean isValidBdaBasedOnExtensionAndBeansXml(ReadableArchive archive) {
        try {
            if (archive.exists("META-INF/services/jakarta.enterprise.inject.spi.Extension") || archive.exists("META-INF/services/jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension")) {
                try (InputStream inputStream = getBeansXmlInputStream(archive)) {
                    if (inputStream != null) {
                        return true; // extension and beans.xml: it is a valid bda
                    }

                    return false; // extension and no beans.xml: no a bda
                }

            }
        } catch (IOException ignore) {
        }

        return true;
    }

(the "META-INF/services/jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension check" is new for 4.0, the rest of the code has been like that since the beginning of time).

Now by coincidence, this same discussion came up here:

https://github.com/jakartaee/cdi/issues/611#issuecomment-1134495331

In short, I'm not sure it's defined anywhere that a Servlet container should be able to load SE service files from "WEB-INF/classes/META-INF/services", as the spec only ever talks about jars in WEB-INF/lib.

Now I love that this would be defined indeed, and that WAR archives can officially contain services such as the CDI extension and ServletContainerInitializer in "WEB-INF/classes/META-INF/services", but I'm not sure this is the case.

Thoughts?

Kind regards,
Arjan Tijms




Back to the top