I'm building a simple API framework on top of Weld CDI and Undertow, to get familiar with the CDI Portable Extension programming model. It's a strict subset of JAX-RS:
@Default
@Path("/dogs")
public class Dogs {
@Inject
private MyService service;
@GET
public Response get(@HeaderParam("DogDebug") String debugParam, @Inject DebugService debugger) { return BLAH; }
@Path("/{id}")
@GET
public Response getById(@PathParam("id") String param) { return BLAH; }
}
My CDI Portable Extension collects up all the AnnotatedTypes that have the Path annotation. When CDI finishes booting, an Undertow webserver starts and all the collected types (and their paths) are registered with an Undertow RoutingHandler.
The Extension is responsible for building HttpHandlers for each method that's annotated with @GET/@POST etc...
public HttpHandler getHandler(AnnotatedMethod<?> producer) {
Object contextualHandler = manager.createInstance()
.select(producer.getDeclaringType().getJavaClass()).get();
Preconditions.checkNotNull(contextualHandler, "Could not obtain a contextual reference to a handler for this");
Object result = producer.getJavaMember().invoke(contextualHandler);
Response response;
if(!(result instanceof Response)) {
response = Response.ok(result).build();
} else {
response = (Response) result;
}
response.write(exchange);
}
As you can see, right now the handler is using plain-ol Java Reflection to call the resource method.
I'd like to make method parameter injection work, as shown in my example above. I can use the BeanManager and metadata to grab the right parameters when actually running the handler, but ...
How can I validate the injection point? i.e. with an AnnotatedType I got from a ProcessAnnotatedType event, how can I validate an arbitrary method as if it were a producer or Constructor or event observer?
Update: So far, I've gotten pretty far with the InjectableMethod class from Deltaspike. It inspects the method and creates an InjectionPoint that can be passed to BeanManager.validate. However, it doesn't have much usage in the publicly Googleable code of the world.