<HTML><BODY>Hi all,<br><br>I found out that in order to control instance creating in Grizzly it is necessary<br>to override some methods in WebappContext. So I created these two classes:<br><a href="https://github.com/PavelKastornyy/weld-core/tree/master/environments/servlet/core/src/main/java/org/jboss/weld/environment/grizzly" rel=" noopener noreferrer" target="_blank" data-snippet-id="c8edd021-f1d5-790f-1e00-fe0cdb34d0b9" data-mce-href="https://github.com/PavelKastornyy/weld-core/tree/master/environments/servlet/core/src/main/java/org/jboss/weld/environment/grizzly">https://github.com/PavelKastornyy/weld-core/tree/master/environments/servlet/core/src/main/java/org/jboss/weld/environment/grizzly</a>&nbsp;<br>However, objects are not injected in servlets as expected. Could anyone of Weld developers comment my code?<br><br>Best regards, Alex<br><br><br><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;">
        Понедельник, 21 мая 2018, 17:49 +03:00 от Martin Kouba &lt;mkouba@redhat.com&gt;:<br>
        <br>
        <div id="">






<div class="js-helper js-readmsg-msg">
        <style type="text/css"></style>
         <div>
                <base target="_self" href="https://e.mail.ru/">
                
            <div id="style_15269141780000000879_BODY">Dne 21.5.2018 v 16:44 Alex Sviridov napsal(a):<br>
&gt; Hi Martin,<br>
&gt; <br>
&gt; Thank you for your answer. I implemented half of container -<br>
&gt; <a href="https://github.com/PashaTurok/core/blob/master/environments/servlet/core/src/main/java/org/jboss/weld/environment/grizzly/GrizzlyContainer.java" target="_blank">https://github.com/PashaTurok/core/blob/master/environments/servlet/core/src/main/java/org/jboss/weld/environment/grizzly/GrizzlyContainer.java</a> <br>
&gt; <br>
&gt; and changed WeldServletLifecycle <br>
&gt; <a href="https://github.com/PashaTurok/core/blob/20398c204f4e24d2a6f1c1ea3bc1d9381ff8f25f/environments/servlet/core/src/main/java/org/jboss/weld/environment/servlet/WeldServletLifecycle.java#L363" target="_blank">https://github.com/PashaTurok/core/blob/20398c204f4e24d2a6f1c1ea3bc1d9381ff8f25f/environments/servlet/core/src/main/java/org/jboss/weld/environment/servlet/WeldServletLifecycle.java#L363</a> <br>
&gt; <br>
&gt; <br>
&gt; To use my Context I do:<br>
&gt; WebappContext webContext = new WebappContext("WebappContext", "");<br>
&gt; Listener listener = new Listener();<br>
&gt; webContext.addListener(listener);<br>
&gt; webContext.deploy(server);<br>
&gt; <br>
&gt; to add some servlet/filter to Grizzly WITHOUT CDI I do :<br>
&gt; ServletRegistration registration = <br>
&gt; webContext.addServlet("ServletContainer",&nbsp; (Class&lt;Servlet&gt;) <br>
&gt; Class.forName("org.temp.TestServlet"));<br>
&gt; registration.addMapping("/");<br>
&gt; <br>
&gt; I've looked through undertow WeldServletExtension but can't understand <br>
&gt; when and where this extension is called.<br>
<br>
In undertow an extension is a service provider of <br>
io.undertow.servlet.ServletExtension, loaded automatically during <br>
startup (see also java.util.ServiceLoader). You need to find out how and <br>
where Grizzly allows to customize the instantiation/injection of <br>
components.<br>
<br>
&gt; As I understand I need to make Grizzly webContext use CDI, so I need to <br>
&gt; make some factory for every<br>
&gt; servlet/filter/listener that will create instances of them using <br>
&gt; BeanManager and make Grizzly to use<br>
&gt; these factories. But where is the point where these factories will be <br>
&gt; used? Could you show me the direction?<br>
&gt; <br>
&gt; Best regards, Alex<br>
&gt; <br>
&gt;     Понедельник, 21 мая 2018, 15:23 +03:00 от Martin Kouba<br>
&gt;     &lt;<a href="mailto:mkouba@redhat.com">mkouba@redhat.com</a>&gt;:<br>
&gt; <br>
&gt;     Hi Alex,<br>
&gt; <br>
&gt;     do you have some publicly available project so that we can discuss a<br>
&gt;     real code?<br>
&gt; <br>
&gt;     In general, if you want to integrate Weld servlet with a custom servlet<br>
&gt;     container:<br>
&gt; <br>
&gt;     1. Implement org.jboss.weld.environment.servlet.Container, e.g.<br>
&gt;     GrizzlyContainer<br>
&gt;      &nbsp;&nbsp;&nbsp;- Container#touch() should return true if a specific container is<br>
&gt;     detected<br>
&gt;      &nbsp;&nbsp;- Container#initialize() and Container#destroy() can be used to<br>
&gt;     init/cleanup the container<br>
&gt;      &nbsp;&nbsp;- note that ContainerContext#getManager() returns a BeanManager<br>
&gt;     which<br>
&gt;     could be used later, e.g. for dependency injection; you can also obtain<br>
&gt;     a BeanManager from the servlet context - see for example [1]<br>
&gt; <br>
&gt;     2. Implement a container specific "injection support"<br>
&gt;     - each servlet container should provide its own SPI - you should<br>
&gt;     implement this SPI so that injection into servlets, listeners and<br>
&gt;     filters is supported; see for example [2] how undertow support is<br>
&gt;     implemented<br>
&gt; <br>
&gt;     3. There is no need to "connect" EnhancedListener in any way. It should<br>
&gt;     be registeded automatically. However, if you're trying to run an<br>
&gt;     embedded servlet container you will need to register<br>
&gt;     org.jboss.weld.environment.servlet.Listener manually.<br>
&gt; <br>
&gt;     Martin<br>
&gt; <br>
&gt; <br>
&gt;     [1]<br>
&gt;     <a href="https://github.com/weld/core/blob/master/environments/servlet/core/src/main/java/org/jboss/weld/environment/undertow/WeldInstanceFactory.java#L56" target="_blank">https://github.com/weld/core/blob/master/environments/servlet/core/src/main/java/org/jboss/weld/environment/undertow/WeldInstanceFactory.java#L56</a><br>
&gt; <br>
&gt;     [2]<br>
&gt;     <a href="https://github.com/weld/core/blob/master/environments/servlet/core/src/main/java/org/jboss/weld/environment/undertow/WeldServletExtension.java" target="_blank">https://github.com/weld/core/blob/master/environments/servlet/core/src/main/java/org/jboss/weld/environment/undertow/WeldServletExtension.java</a><br>
&gt; <br>
&gt;     Dne 18.5.2018 v 19:52 Alex Sviridov napsal(a):<br>
&gt;      &gt; Hi all<br>
&gt;      &gt;<br>
&gt;      &gt; Could anyone explain how to connect WebappContext that implements<br>
&gt;      &gt; ServletContext, to<br>
&gt;      &gt; Weld servlet env? I've read the code, but still can't understand<br>
&gt;     how to<br>
&gt;      &gt; connect SomeContainer,<br>
&gt;      &gt; that implements servlet.Container, EnhancedListener and Grizzly<br>
&gt;      &gt; WebappContext? Could anyone<br>
&gt;      &gt; describe main principles how to do it? I would be very thankful.<br>
&gt;      &gt;<br>
&gt;      &gt; --<br>
&gt;      &gt; Best regards, Alex Sviridov<br>
&gt;      &gt;<br>
&gt;      &gt;<br>
&gt;      &gt; _______________________________________________<br>
&gt;      &gt; weld-dev mailing list<br>
&gt;      &gt; <a href="mailto:weld-dev@lists.jboss.org">weld-dev@lists.jboss.org</a> &lt;mailto:weld-dev@lists.jboss.org&gt;<br>
&gt;      &gt; <a href="https://lists.jboss.org/mailman/listinfo/weld-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/weld-dev</a><br>
&gt;      &gt;<br>
&gt; <br>
&gt;     -- <br>
&gt;     Martin Kouba<br>
&gt;     Senior Software Engineer<br>
&gt;     Red Hat, Czech Republic<br>
&gt; <br>
&gt; <br>
&gt; <br>
&gt; -- <br>
&gt; Alex Sviridov<br>
<br>
-- <br>
Martin Kouba<br>
Senior Software Engineer<br>
Red Hat, Czech Republic<br>
</div>
            
        
                <base target="_self" href="https://e.mail.ru/">
        </div>

        
</div>


</div>
</blockquote>
<br>
<br>-- <br>Alex Sviridov<br></BODY></HTML>