[cdi-dev] [JBoss JIRA] (CDI-452) Specify that web scoped (request, session, application) beans are injectable in async servlets

arjan tijms (JIRA) issues at jboss.org
Wed Oct 5 03:31:00 EDT 2016


    [ https://issues.jboss.org/browse/CDI-452?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13302698#comment-13302698 ] 

arjan tijms commented on CDI-452:
---------------------------------

[~marembo2008]

The mentioned opaque security context is not particular to EJB. In fact, CDI already makes use of it by having a build-in bean for {{Principal}}, meaning you can do {{@Inject Principal principal}}. And Servlet containers use the same thing via web.xml constraints and things like {{HttpServletRequest.getUserPrincipal}}.

So nothing of what I mentioned is EJB specific. Even things like {{@RolesAllowed}} are in fact not EJB (they're from Common Annotations, aka JSR 250), and every spec, including CDI can use it. This is also one of the goals of JSR 375 (Java EE Security API).

> Specify that web scoped (request, session, application) beans are injectable in async servlets
> ----------------------------------------------------------------------------------------------
>
>                 Key: CDI-452
>                 URL: https://issues.jboss.org/browse/CDI-452
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>          Components: Contexts, Java EE integration
>    Affects Versions: 1.0
>            Reporter: Ed Burns
>            Assignee: John Ament
>             Fix For: 2.0 (discussion)
>
>
> Consider this code based on this blog post: < https://weblogs.java.net/blog/swchan2/archive/2013/06/06/asynchronous-servlet-and-java-ee-concurrency-utilities >.
> {code}
> @WebServlet(urlPatterns="/test2", asyncSupported=true)
> public class TestAsyncMESServlet extends HttpServlet {
>     @Resource
>     private ManagedExecutorService managedExecutorService;
>     @Inject
>     MyRunnableImpl myRunnableImpl;
>     @Override
>     protected void doGet(HttpServletRequest req, HttpServletResponse res)
>             throws ServletException, IOException {
>         final AsyncContext asyncContext = req.startAsync();
>         final PrintWriter writer = res.getWriter();
>         managedExecutorService.submit(myRunnableImpl);
>     }
>     public static class MyRunnableImpl implements Runnable {
>       @Inject
>       Bean bean; // Bean is @RequestScoped
>       @Override
>       public void run() {
> 	  writer.println("Done");
> 	  asyncContext.complete();
>       }
>     }
> }
> {code}
> According to Jozef Hartzinger, this currently does not work, because only @Dependent and @ApplicationScoped beans are propagated to the new thread.  To keep CDI relevant in light of the reactive programming movement and the popularity of node.js, we need to make this work.



--
This message was sent by Atlassian JIRA
(v6.4.11#64026)


More information about the cdi-dev mailing list