[weld-dev] How to use Weld servlet Env with Grizzly?
Alex Sviridov
ooo_saturn7 at mail.ru
Wed May 23 10:59:22 EDT 2018
Hi all,
I found out that in order to control instance creating in Grizzly it is necessary
to override some methods in WebappContext. So I created these two classes:
https://github.com/PavelKastornyy/weld-core/tree/master/environments/servlet/core/src/main/java/org/jboss/weld/environment/grizzly
However, objects are not injected in servlets as expected. Could anyone of Weld developers comment my code?
Best regards, Alex
>Понедельник, 21 мая 2018, 17:49 +03:00 от Martin Kouba <mkouba at redhat.com>:
>
>Dne 21.5.2018 v 16:44 Alex Sviridov napsal(a):
>> Hi Martin,
>>
>> Thank you for your answer. I implemented half of container -
>> https://github.com/PashaTurok/core/blob/master/environments/servlet/core/src/main/java/org/jboss/weld/environment/grizzly/GrizzlyContainer.java
>>
>> and changed WeldServletLifecycle
>> https://github.com/PashaTurok/core/blob/20398c204f4e24d2a6f1c1ea3bc1d9381ff8f25f/environments/servlet/core/src/main/java/org/jboss/weld/environment/servlet/WeldServletLifecycle.java#L363
>>
>>
>> To use my Context I do:
>> WebappContext webContext = new WebappContext("WebappContext", "");
>> Listener listener = new Listener();
>> webContext.addListener(listener);
>> webContext.deploy(server);
>>
>> to add some servlet/filter to Grizzly WITHOUT CDI I do :
>> ServletRegistration registration =
>> webContext.addServlet("ServletContainer", (Class<Servlet>)
>> Class.forName("org.temp.TestServlet"));
>> registration.addMapping("/");
>>
>> I've looked through undertow WeldServletExtension but can't understand
>> when and where this extension is called.
>
>In undertow an extension is a service provider of
>io.undertow.servlet.ServletExtension, loaded automatically during
>startup (see also java.util.ServiceLoader). You need to find out how and
>where Grizzly allows to customize the instantiation/injection of
>components.
>
>> As I understand I need to make Grizzly webContext use CDI, so I need to
>> make some factory for every
>> servlet/filter/listener that will create instances of them using
>> BeanManager and make Grizzly to use
>> these factories. But where is the point where these factories will be
>> used? Could you show me the direction?
>>
>> Best regards, Alex
>>
>> Понедельник, 21 мая 2018, 15:23 +03:00 от Martin Kouba
>> < mkouba at redhat.com >:
>>
>> Hi Alex,
>>
>> do you have some publicly available project so that we can discuss a
>> real code?
>>
>> In general, if you want to integrate Weld servlet with a custom servlet
>> container:
>>
>> 1. Implement org.jboss.weld.environment.servlet.Container, e.g.
>> GrizzlyContainer
>> - Container#touch() should return true if a specific container is
>> detected
>> - Container#initialize() and Container#destroy() can be used to
>> init/cleanup the container
>> - note that ContainerContext#getManager() returns a BeanManager
>> which
>> could be used later, e.g. for dependency injection; you can also obtain
>> a BeanManager from the servlet context - see for example [1]
>>
>> 2. Implement a container specific "injection support"
>> - each servlet container should provide its own SPI - you should
>> implement this SPI so that injection into servlets, listeners and
>> filters is supported; see for example [2] how undertow support is
>> implemented
>>
>> 3. There is no need to "connect" EnhancedListener in any way. It should
>> be registeded automatically. However, if you're trying to run an
>> embedded servlet container you will need to register
>> org.jboss.weld.environment.servlet.Listener manually.
>>
>> Martin
>>
>>
>> [1]
>> https://github.com/weld/core/blob/master/environments/servlet/core/src/main/java/org/jboss/weld/environment/undertow/WeldInstanceFactory.java#L56
>>
>> [2]
>> https://github.com/weld/core/blob/master/environments/servlet/core/src/main/java/org/jboss/weld/environment/undertow/WeldServletExtension.java
>>
>> Dne 18.5.2018 v 19:52 Alex Sviridov napsal(a):
>> > Hi all
>> >
>> > Could anyone explain how to connect WebappContext that implements
>> > ServletContext, to
>> > Weld servlet env? I've read the code, but still can't understand
>> how to
>> > connect SomeContainer,
>> > that implements servlet.Container, EnhancedListener and Grizzly
>> > WebappContext? Could anyone
>> > describe main principles how to do it? I would be very thankful.
>> >
>> > --
>> > Best regards, Alex Sviridov
>> >
>> >
>> > _______________________________________________
>> > weld-dev mailing list
>> > weld-dev at lists.jboss.org <mailto:weld-dev at lists.jboss.org>
>> > https://lists.jboss.org/mailman/listinfo/weld-dev
>> >
>>
>> --
>> Martin Kouba
>> Senior Software Engineer
>> Red Hat, Czech Republic
>>
>>
>>
>> --
>> Alex Sviridov
>
>--
>Martin Kouba
>Senior Software Engineer
>Red Hat, Czech Republic
--
Alex Sviridov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/weld-dev/attachments/20180523/551f53bf/attachment.html
More information about the weld-dev
mailing list