resteasy / resteasy-spring-boot

Apache License 2.0
123 stars 49 forks source link

getClasses() and getSingletones() not called (version 6.0.0.Final and resteasy 6.2.1.Final) #207

Closed asafbennatan closed 1 year ago

asafbennatan commented 1 year ago

digging further i think i found the issue:

public class ResteasyApplicationBuilder {

    public static final String BEAN_NAME = "JaxrsApplicationServletBuilder";

    private static final Logger logger = LoggerFactory.getLogger(ResteasyApplicationBuilder.class);

    public ServletRegistrationBean build(String applicationClassName, String path, Set<Class<?>> resources, Set<Class<?>> providers) {
        Servlet servlet = new HttpServlet30Dispatcher();

        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(servlet);

        servletRegistrationBean.setName(applicationClassName);
        servletRegistrationBean.setLoadOnStartup(1);
        servletRegistrationBean.setAsyncSupported(true);
        servletRegistrationBean.addInitParameter(Application.class.getTypeName(), applicationClassName);

notice this line specifically: servletRegistrationBean.addInitParameter(Application.class.getTypeName(), applicationClassName);

now look at the ServletContainerDispatcher code from resteasy core

public void init(ServletContext servletContext, ConfigurationBootstrap bootstrap, HttpRequestFactory requestFactory, HttpResponseFactory responseFactory) throws ServletException {
        this.requestFactory = requestFactory;
        this.responseFactory = responseFactory;
        ResteasyDeployment ctxDeployment = (ResteasyDeployment)servletContext.getAttribute(ResteasyDeployment.class.getName());
        ResteasyProviderFactory globalFactory = (ResteasyProviderFactory)servletContext.getAttribute(ResteasyProviderFactory.class.getName());
        if (globalFactory == null && ctxDeployment != null) {
            globalFactory = ctxDeployment.getProviderFactory();
        }

        Dispatcher globalDispatcher = (Dispatcher)servletContext.getAttribute(Dispatcher.class.getName());
        if (globalDispatcher == null && ctxDeployment != null) {
            globalDispatcher = ctxDeployment.getDispatcher();
        }

        String application = bootstrap.getInitParameter("jakarta.ws.rs.Application");

specifically

String application = bootstrap.getInitParameter("jakarta.ws.rs.Application"); while Application.class resolves to jakarta.ws.rs.core.Application causing application to allways be null

this matters because later in the ServletContainerDispatcher code we check if application is not null ,in this case we call process application which in turn calls getClassesand getSingletons

not sure if the fix should be in this repo or in the resteasy core repo

asafbennatan commented 1 year ago

PR contributed

liweinan commented 1 year ago

@asafbennatan thanks for the finding! I guess this should be fixed in resteasy-core, I'll submit issue to it.

asafbennatan commented 1 year ago

@liweinan once created could you link to this issue - so i can follow its progress ? - Thanks

liweinan commented 1 year ago

@asafbennatan sure

liweinan commented 1 year ago

PR submitted in the upstream project: https://github.com/resteasy/resteasy/pull/3379