payara / Payara

Payara Server is an open source middleware platform that supports reliable and secure deployments of Java EE (Jakarta EE) and MicroProfile applications in any environment: on premise, in the cloud or hybrid.
http://www.payara.fish
Other
886 stars 307 forks source link

method with [observer @Initialized(ApplicationScoped.class) ServletContext init] is not invoked inside Jar files\FISH-6640 #5968

Open MedMahmoud0207 opened 2 years ago

MedMahmoud0207 commented 2 years ago

Description


Hello, I was trying to migrate from payara/micro:4.181 to payara/micro:5.2022.3 and I noticed that the initialization method with observer [@Initialized(ApplicationScoped.class) ServletContext init] is not invoked inside Jar files.

public void init(@Observes @Initialized(ApplicationScoped.class) ServletContext init)

It is invoked correcly when using payara/micro:4.181 though.

Expected Outcome

The init method is invoked to execute some initialization logic

Current Outcome

The init method is not invoked when inside a .jar dependency

Steps to reproduce

To reproduce the described behaviour:

  1. download the attached reproduce_observer_issue.zip
  2. unzip the files into "current_dir"
  3. the unzipped files contains a Dockerfile with following content:
    #FROM payara/micro:5.2022.3
    FROM payara/micro:4.181
    COPY app.war $DEPLOY_DIR

uncomment the line corresponding to the version of payara/micro you want to run the app with.

  1. go to run the following docker commands to deploy the app :
    • docker build -t repissue:v1 .
    • docker run repissue:v1
  2. If you check the path "current_dir\sources\libs\lib\src\main\java\mylib\Library.java" you can see that it contains two init methods, however when deploying on payara/micro:5.2022.3 init(@Observes @Initialized(ApplicationScoped.class) ServletContext init) won't be invoked (check logs)
package mylib;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Initialized;
import javax.enterprise.event.Observes;
import javax.servlet.ServletContext;

@ApplicationScoped
public class Library {
    public boolean someLibraryMethod() {
        return true;
    }

    public void init(@Observes @Initialized(ApplicationScoped.class) Object init) {
        System.out.println(" ### log-1 mylib.Library.init(java.lang.Object) called ###");
    }

    public void init(@Observes @Initialized(ApplicationScoped.class) ServletContext init) {
        System.out.println(" ### log-2 mylib.Library.init(javax.servlet.ServletContext) invoked ###");
    }
}

reproduce_observer_issue.zip

Environment

MedMahmoud0207 commented 2 years ago

The same behaviour described above happens when deploying on Payara Server 5.2022.3 (Full) instead of docker

JamesHillyard commented 2 years ago

Hi @MedMahmoud0207,

The reproducer you shared doesn't appear to contain all the files for the reproducer, in sources\project\app\src\main\java\someapp only App.java is present, no other classes such as the application scoped Library class you mention in the reproducer. Could you please share the complete reproducer with all the source files?

Thanks, James

MedMahmoud0207 commented 2 years ago

Hi @JamesHillyard, Thanks for your feedback

The Library class is in a .jar dependency included under sources\project\app\libs\lib.jar and the source code of this lib.jar is under sources\libs\lib

Regards,

MedMahmoud0207 commented 2 years ago

Hello @JamesHillyard ,

Hope you were able to find the file you asked for, anyway I will be close in case any further infos are needed.

Thanks

shub8968 commented 2 years ago

Hi @MedMahmoud0207,

I've escalated this issue to our platform development team as FISH-6640. Thanks.

haducloc commented 1 year ago

Today is 02/02/2023. I got the same issue with the latest version of Payara Micro 6.2023.1. I don't understand it has been 6 months since the issue was reported, but the issue is still there? I did not have the issue with Wildfly.