OpenLiberty / open-liberty

Open Liberty is a highly composable, fast to start, dynamic application server runtime environment
https://openliberty.io
Eclipse Public License 2.0
1.15k stars 592 forks source link

Configuration BND and EXT module names not validated when there is no application.xml #19510

Open troy-bishop opened 2 years ago

troy-bishop commented 2 years ago

Kernel Assessment Medium. See: https://github.com/OpenLiberty/open-liberty/issues/19510#issuecomment-2015384407

Describe the bug
It looks like there’s a bug that causes the CWWKC2277E error message to be emitted when there is no application.xml, there are multiple web modules, and at least one of the modules doesn’t have a web-ext override in server.xml.. The web-ext overrides are picked up, though.

Steps to Reproduce
Create an EAR (with no application.xml) that has 2 web modules where the context-root is overridden in the server.xml via the web-ext property, example:

EAR (zdt-mc) contains 2 web modules: zdt-restapi.war and zdt-webui.war.

    <application id="zdt-mc" location="zdt-mc.ear" name="zdt-mc" type="ear">
        <application-bnd>
            <security-role name="AuthenticatedUsers">
                <special-subject type="ALL_AUTHENTICATED_USERS" />
            </security-role>
        </application-bnd>
        <web-ext moduleName="zdt-webui" context-root="TEST"/>
    </application>

The server does bind the context-root TEST to zdt-webui but still emits the CWWKC2277E error message.

Expected behavior
No CWWKC2277E error message emitted when starting the server with this application.

Diagnostic information:

Additional context
N/A

troy-bishop commented 2 years ago

messages.log

See line:

[2021-11-30, 10:40:51:557 EST] 00000038 com.ibm.ws.javaee.ddmodel.webext.WebExtAdapter               E CWWKC2277E: One or more module names on the web-ext element are invalid. The invalid module name or names are [zdt-restapi, zdt-webui].
barulheira commented 2 years ago

I can confirm.

brenthdaniel commented 2 years ago

It looks like this error was removed altogether fairly recently (it probably won't be in a release until 22.0.0.1). That resolves the issue you were seeing, but means that there will not be an error message for an invalid module name if application.xml doesn't exist. I'm going to use this issue to add back the error in a way that also works in your scenario.

tbitonti commented 2 years ago

The problem of validating module names is exposed in the web binding adapter:

dev/com.ibm.ws.javaee.ddmodel/src.gen/com/ibm/ws/javaee/ddmodel/webbnd/WebBndAdapter.java dev/com.ibm.ws.javaee.ddmodel/src.gen/com/ibm/ws/javaee/ddmodel/common/BndExtAdapter.java

There is a problem in that when no application descriptor is available, the modules list is computed. See:

DeployedAppInfoBase.moduleContainerInfos
EARDeployedAppInfo.createModuleContainerInfo

SimpleDeployedAppInfoBase.preDeployApp
SimpleDeployedAppInfoBase$ModuleContainerInfoBase.createModuleMetaData
ModuleHandlerBase.createModuleMetaData

The computed modules list is not currently available to the web bnd adapter.

tbitonti commented 7 months ago

This looks like a medium fix.

There is a problem that the validation of module names requires steps not immediately accessible to the bindings and extensions processing. The problem is that when no application.xml is present, the modules list must be computed before the module names can be obtained. Determining modules is a complex process done away from the bindings and extensions processing.

See comments on: open-liberty/dev/com.ibm.ws.javaee.ddmodel/src.gen/com/ibm/ws/javaee/ddmodel/common/BndExtAdapter.java

    // TFB:
    //
    // Retrieval of module names, as implemented, is unreliable.
    // The implementation relies on the application descriptor, which
    // may be absent.  
    //
    // The completed modules list is computed by the deployed application. See:
    //
    // open-liberty/dev/com.ibm.ws.app.manager.module/src/
    //         com/ibm/ws/app/manager/module/internal/
    //             DeployedAppInfoBase.java
    //             SimpleDeployedAppInfoBase.java
    //
    // open-liberty/dev/com.ibm.ws.app.manager.war/src/
    //         com/ibm/ws/app/manager/ear/internal/
    //             EARDeployedAppInfo.java
    //
    // In particular, see:
    //         DeployedAppInfoBase.moduleContainerInfos
    //         EARDeployedAppInfo.createModuleContainerInfo
    //
    //         SimpleDeployedAppInfoBase.preDeployApp
    //         SimpleDeployedAppInfoBase$ModuleContainerInfoBase.createModuleMetaData
    //         ModuleHandlerBase.createModuleMetaData
    //
    // The current implementation fails with a NullPointerException for an application which
    // does not have a application deployment descriptor (META-INF/application.xml):
    //
    // Stack Dump = java.lang.NullPointerException
    //         at com.ibm.ws.javaee.ddmodel.common.BndExtAdapter.getModuleNames(BndExtAdapter.java:369)
...
    //         at com.ibm.ws.app.manager.ear.internal.EARApplicationHandlerImpl.install(EARApplicationHandlerImpl.java:77)
    //         at com.ibm.ws.app.manager.internal.statemachine.StartAction.execute(StartAction.java:149)
    //         at com.ibm.ws.app.manager.internal.statemachine.ApplicationStateMachineImpl.enterState(ApplicationStateMachineImpl.java:1352)
    //
    // A correct implementation would provide the complete modules list.  That would introduce a new type
    // and new dependencies, and is not done at this time.