0

I need a sample application using vert.x, resteasy and weld-cdi. I am able to use vert.x and resteasy. But i do not know how to integrate weld-cdi.

Please help me.

2 Answers2

0

You might wanna take a look at weld-vertx project.

If you can already work with vertx, this will allow you to weave in Weld. The project contains some examples and you can also check tests to see even more uses.

Siliarus
  • 6,393
  • 1
  • 14
  • 30
0

I use Vertx with Resteasy and Weld. It's not so simple, but I have managed to do it. You will need:

  • the org.jboss.resteasy:resteasy-cdi and org.jboss.resteasy:resteasy-vertx Resteasy integration modules
  • the org.jboss.weld.se:weld-se-core module for Weld on Java SE
  • the org.jboss.weld.vertx:weld-vertx-core for Weld + Vertx integration

You set up CDI with the Weld+Vertx extension:

Weld weld = new Weld();
weld.addExtension(new VertxExtension());
weld.initialize();

When you deploy Resteasy, you want to deploy it with CDI instances:

VertxResteasyDeployment deployment = new VertxResteasyDeployment();
ResteasyCdiExtension cdiExtension = CDI.current().select(ResteasyCdiExtension.class).get();
deployment.setActualResourceClasses(cdiExtension.getResources());
deployment.setInjectorFactoryClass(CdiInjectorFactory.class.getName());
deployment.getActualProviderClasses().addAll(cdiExtension.getProviders());
deployment.start();

And you want to set-up the Vertx-Weld extension by registering consumers in a blocking block:

// Setup the Vertx-CDI integration
VertxExtension vertxExtension = CDI.current().select(VertxExtension.class).get();
BeanManager beanManager = CDI.current().getBeanManager();
// has to be done in a blocking thread
vertx.executeBlocking(future -> {
    vertxExtension.registerConsumers(vertx.getDelegate(), BeanManagerProxy.unwrap(beanManager).event());
    future.complete();
}, res -> {
    // you can now create your HTTP server
});

Note that you still need tweaks for:

  • Creating a CDI request context on Vert.x requests
  • Propagating CDI and Resteasy thread-locals on Vert.x async handlers
  • Setting up Bean Validation with CDI and Resteasy

I can give you code for that too if you need those.

FroMage
  • 5,038
  • 2
  • 20
  • 13