Hi all,

I'm working on a project that is meant to bring CDI injections to
server-side JavaScript. There are similarities with Undertow.js [1],
but the project I'm working on has more generic nature, wider scope and
vendor-neutral character. From the very inception it was clear that
TomEE should be among the supported platforms; I am myself a long-time
Tomcat/TomEE user and fan.

You can find the project's write-up here: https://gist.github.com/dtele
guin/c93fe4a4c666234729d8

The cornerstone of the project should be the mechanism that would allow
to resolve JavaEE resource injections (@PersistenceContext, @Resource,
@EJB etc.) dynamically at runtime.

The first attempt was to generate on-the-fly a class with annotated
fields and instantiate it via javax.enterprise.inject.spi.Unmanaged.
This worked perfectly in WildFly, but failed in TomEE and GlassFish.
(However, simple @Inject worked everywhere.) See this StackOverflow
thread [2] for details and code.

I've spent some time studying TomEE/OpenEJB internals just to learn
that probably it wouldn't be that easy to implement the same in TomEE.
Is it correct that TomEE scans web application on deployment, creates
JNDI entries for all the detected injection points, and "injecting" is
simply wiring up the fields to corresponding JNDI entries?

With the said, how can I achieve what I want in TomEE? Is it possible
to trigger an on-demand JNDI resource creation and wiring?

Most likely some TomEE-specific code will be needed, or a privileged
context with ContainerServlet, or a custom valve; I'm OK with all the
above (however, of course, the platform-independent code would be
preferred). In fact, even generating a class may be redundant. Let's
describe it this way, I have a set of injection definitions like this:

@Annotation(param = "value") @Qualifier1 @Qualifier2 ... Type name;

where Annotation is one of Inject, PersistenceContext, Resource, EJB
etc. These definitions become available only at runtime. Finally, for
each definition I want to obtain an instance that would have been
injected if this were happening inside a full-featured CDI managed
bean.

Thanks in advance!
And long live the "technology that kicks ass" (C) :)

Dimitri

[1] http://wildfly.org/news/2015/11/02/Undertow/
[2] http://stackoverflow.com/questions/36239250/injecting-java-ee-resou
rces-into-dynamically-loaded-classes

Reply via email to