Random CDI JAX-RS Tomcat TomEE frustration
The injection of a CDI bean into a JAX-RS service does not seem to work when using CDI-Weld and Resteasy as correspondent implementations. This sucks, since I wanted to inject a self implemented and session scoped security manager into my restful services to implement role based access restrictions. The desire to do so actually feels quite natural and various posts on stackoverflow suggest that other people have tried this before. I read it should (by specification) work when using EJB and I also read some guys got it to work using just OpenWebBeans and Jersey as CDI / JAX-RS implementations (though it is not clear, if this is actually covered by the CDI specs). The first thing I tried was using TomEE, which is basically Tomcat plus EJB and some other of the “heavier” stuff that we know from full blown Java EE servers such as JBoss and Glassfish. I love the idea of having access to some of the advanced features of Java EE, while still sticking with good old Tomcat. It’s stable, it’s well documented, you don’t need a specialized guru to do the configuration stuff and it starts within 5 seconds with my app (JSF, JPA, CDI, JAX-RS) already deployed. So I downloaded TomEE, added the MySQL JDBC driver and configured a runtime in Eclipse. Result: My app didn’t start, the error message was of little use and I got frustrated right away. It seemed like it had something to do with CDI, so I googled what implementation TomEE was using: OpenWebBeans. Haha, okay. So instead of fixing whatever had to be fixed in my app to make it work with TomEE, I tried to replace Weld by OpenWebBeans in my old Tomcat environment. This should be easier and a good point to start from when moving towards TomEE. But as it turned out, there is no single OpenWebBeans Maven dependency for Tomcat, but rather a dozen that you can pick up from a few blogs. And why is that? BECAUSE THERE IS NO FUCKING DOCUMENTATION FOR OPENWEBBEANS, NOT EVEN A SINGLE PIECE. How is this even possible? I mean, it’s an Apache project, it has been there for over three years now. This is ridiculous. So, why not use TomEE right away? BECAUSE I WOULD NEED THE SAME FUCKING MAVEN DEPENDENCIES AS WITH TOMCAT. The only difference would be, that for TomEE all dependencies would have a scope of “provided”, to indicate that they don’t have to be downloaded, because TomEE already provides them. Sure, maybe I could cobble this together, SOMEHOW. And after all, there are like … uhm … three blogs that have done this before. But to be honest, I just can’t move to a different CDI implementation, when there is no documentation at all. Never ever. And I still hope it’s just a matter of days. Hope that maybe the OpenWebBeans guys are just busy refactoring their already existing docs and therefore fucked up most of their project website…