Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@HelidonTest request scope support without discovery #7564

Closed
danielkec opened this issue Sep 11, 2023 · 2 comments · Fixed by #7916
Closed

@HelidonTest request scope support without discovery #7564

danielkec opened this issue Sep 11, 2023 · 2 comments · Fixed by #7916
Assignees
Labels
2.x Issues for 2.x version branch 3.x Issues for 3.x version branch 4.x Version 4.x bug Something isn't working P2 testing
Milestone

Comments

@danielkec
Copy link
Contributor

Environment Details

  • Helidon Version: 2.x, 3.x, 4.x
  • Helidon MP

Problem Description

@HelidonTest with disabled discovery doesn't support request scoped bean without explicitly adding:

@AddExtension(org.glassfish.jersey.ext.cdi1x.internal.ProcessAllAnnotatedTypes.class)
@AddBean(org.glassfish.jersey.weld.se.WeldRequestScope.class)

Failing with WELD-001303:

org.jboss.weld.contexts.ContextNotActiveException: WELD-001303: No active contexts for scope type jakarta.enterprise.context.RequestScoped
	at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:647)
	at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:89)
	at org.jboss.weld.bean.ContextualInstanceStrategy$CachingContextualInstanceStrategy.getIfExists(ContextualInstanceStrategy.java:164)
	at org.jboss.weld.bean.ContextualInstance.getIfExists(ContextualInstance.java:63)
	at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:87)
	at org.jboss.weld.bean.proxy.ProxyMethodHandler.getInstance(ProxyMethodHandler.java:131)
	at com.example.ReqScopeDisabledDiscoveryTest$MyController$Proxy$_$$_WeldClientProxy.get(Unknown Source)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory.lambda$static$0(ResourceMethodInvocationHandlerFactory.java:52)
	at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:134)
	at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:177)
	at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:176)
	at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:81)
	at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:478)
	at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:400)
	at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:81)
	at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:256)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)
	at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:292)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:274)
	at org.glassfish.jersey.internal.Errors.process(Errors.java:244)
	at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:265)
	at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:235)
	at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:684)
	at io.helidon.webserver.jersey.JerseySupport$JerseyHandler.lambda$doAccept$6(JerseySupport.java:339)

Steps to reproduce

@HelidonTest
@DisableDiscovery
@AddExtension(ServerCdiExtension.class)
@AddExtension(JaxRsCdiExtension.class)
@AddExtension(CdiComponentProvider.class)

// JAX-RS Request scope
//@AddExtension(org.glassfish.jersey.ext.cdi1x.internal.ProcessAllAnnotatedTypes.class)
//@AddBean(org.glassfish.jersey.weld.se.WeldRequestScope.class)

@AddBean(ReqScopeDisabledDiscoveryTest.MyController.class)
public class ReqScopeDisabledDiscoveryTest {
    @Inject
    private WebTarget target;

    @Test
    void testGet() {
        assertEquals("Hallo!", target
                .path("/greeting")
                .request()
                .get(String.class));
    }

    @Path("/greeting")
    @RequestScoped
    public static class MyController {
        @GET
        public Response get() {
            return Response.ok("Hallo!").build();
        }
    }
}
@danielkec
Copy link
Contributor Author

We should consider adding convenience annotation @AddJaxRs which would throw exception unless used in disable discovery mode

@m0mus m0mus added bug Something isn't working 3.x Issues for 3.x version branch 4.x Version 4.x 2.x Issues for 2.x version branch testing P2 labels Sep 14, 2023
@m0mus m0mus added this to the 4.0.1 milestone Nov 16, 2023
@trentjeff
Copy link
Member

Would like to see this backported to 2.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.x Issues for 2.x version branch 3.x Issues for 3.x version branch 4.x Version 4.x bug Something isn't working P2 testing
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants