A commuters context framework

During commuting you see a lot if people reading a book or a newspaper. But the geek or nerd that I am keeps on programming.
This led to another ‘invention of the wheel’. I wrote my own CDI ( not or not yet JSR-299 compatible) framework.
Probably nobody is waiting for that and certainly not since it’s not compatible with Spring nor Java EE cdi. But what the heck, I don’t care. I had fun writing it and that’s what it’s all about. Of course it would be even more fun if somebody else finds it usable.

Project info:
License: Apache 2.0 (of course!)
Project on sourceforge here
Wiki and bugtracker here
CI on Cloudbees here
Javadoc here
Maven Site here

Why would I use it?
1. For small applications that don’t do much Java CDI and Spring could be to much overhead. Using a fairly simple look-a-like that is more lightweight will be less overhead while you can still benefit from some kind of CDI. (e.g. for small swing apps )
2. It’s basic framework, easy to understand and extend.
3. It’s in Java 7 ( although it might run under 6, haven’t tried that )

Why did I create it?
I don’t really like the way that Java CDI forces you to create a wildgrow of annotations. I much more prefer the way Spring let you do injections but I’m not fond of the total Spring package. So perhaps the redlab-context project is an answer to both. And I have fun creating it while traveling.

If I use it myself (which I will do), I’ll probably discover some shortcomings and enhance it.

Things that are on the roadmap are to provide support for integration with Spring, Java CDI and your own stuff.
Oh and write some wiki pages with documentation. Not the most fun stuff to write but how would you otherwise know how to use it.

Currently you can’t get it from the Central Maven repository yet but you can download it from sourceforge. If my own usage proves it’s allright for using it, I’ll perhaps upload it to Maven Central

Java EE 6

Java EE 6 Tutorial. Reloaded! by Antonio Goncalves and Alexis Moussine-Pouchkine

In Java EE 6 we get an overview of the EE stuff in Java. Thanks to the fog, traffic and a badge that escaped from my badge holder I was a bit late and missed the general overview. I was just in time to pick up the fact that every container that implements the EE6 spec has to provide a EE6 client. This client allows you to run EE6 code in SE, meaning using for example @Inject in a stand alone application.

They dive into some specs, starting with JPA2.0 which actually we already know because of using Hibernate with JPA 2.0. There are some differences but hey, not so much, the guys from Hibernate worked on the JPA2.0 spec … take a look at @NamedQueries and CriteriaBuilder of you’ve never heard of it before.

The Servlet 3.0 spec is much more interesting, with the annotations introduced and making the web.xml optional. Thanks to @WebServlet, @WebListener etc … There is the new Plugability stuff: what you can now do is create fragmented web.xml that are self contained in their own jar. This is done through <web-fragment> instead of <web-app>. Of course you can override the different jar’s with your main web.xml if you put it in your own WEB-INF . there is also the ServletContainerInitializer API which allows to manipulate the ServletContext at startup. for resources you can put them in META-INF/resources of any jar and the will be served from the root of the web app.

More new stuff is the async (comet like ) communication. Which is of course very cool. With al the fuss about HTML 5 and Websockets. But they did not really show the full power of it.

With EJB 3.1 the remote interface becomes optional. Thanks to the new stuff. ejb’s can now be contained in the war files. For async stuff we can now use @Asynchronous which returns a java.util.concurrent.Future instead of using JMS, however this does not assure that the future will return a result unlike JMS which has more guarantees.

The timer service has been enhanced to act more like the linux/unix cron scheduler. (we can use @schedule )

Another new thing is the @Singleton bean, the name of the annotation speaks for itself of course. You can leave concurrency up to the container or do it yourself in Singleton beans. This is the only part of the spec where you can use synchronized in an EJB. (they are singletons per app container. not clusterwise)

There is more but they didn’t really cover that.

The embedable container

This container can be embedded in your SE application allowing you to use EJB’s in SE applications. Through the EJBContainer you can get the context (this is like spring no? 🙂  ) Will EE6 slowly start to replace Spring everywhere? Maybe. Didn’t the Spring guys worked on the EE6 specification too?

JSF 2.0 I didn’t really listen extensively, I’ve never used it and after watching the overview I don’t think I really will unless it’s required by a customer. ( I would have better skipped this part and go watch the Introducing Wicket, lol, but we’ll see that on parleys).

JSF is a component framework. Which might be cool since you can use different components through out other stuff. Instead of being dependent on the action frameworks where one needs to follow a more specific style of that framework. It seems that in JSF 2.0 it does get easier to create you own components which is a good thing. Maybe it will be used more now. And if I will have to use it, it wont be hard to pick it up and get up to speed. There is ajax functionality in JSF as they demonstrated, but I wonder more what kind of Javascript is being spit out by JSF which wasn’t shown.

Bean Validation is a new specification in EE 6, it”s a nice ‘short’ 50 pages spec which tries to set a standard for bean data validation. It works together with JPA 2.0. You can do it with annotations like @NotNull @Valid @Size(max=1020) etc.. There about 15 standard validation annotations but you can write your own Validation annotations. Would be silly if we couldn’t. (This bean validation reminds me of the hibernate validator, my guess is if you check the JCP, they will have been involved in creating the spec)

JAX-RS 1.1 allows you to create restfull services. Again with annotations (like @GET @POST ). By adding the annotations toa a class & it’s methods you enable them as a restfull webservice. With @Path you can set the url path, with @Produces and @Consumes you set the Mimetype of what the method send/receives. If its xml and your classes are JAXB annotated it works nicely togehter. The same counts for JSON. You can add multiple media types to one method.  JAX-RS is cool since no contract is required unlike a wsdl. You can create a contract file (a wadl) but it is not a standard yet. There are more annotations that you can use like the @MatrixParam, @PathContext and many more. The best is to look at the spec jsr-311.

CDI in EE6. In EE5 there was already @Resource @PersistenceContext @WebServiceRef which are actually already CDI. The new CDI consist of 2 jsr’s JSR-299 JSR-330. CDI for EE en DI for SE. The SE version is minimalistic with @Inject. For EE there is more to it.

For CDI to work you need a beans.xml file in your WEB-INF. The beans.xml can be completely empty. @Named makes the bean available in EL (expression language), rather use @Named then @ManagedBean (JSF annotation). @Inject is for injecting stuff, @Resource is still hanging around but you can use @Inject for that.

You can create your own annotations where you group different other annotations into one (through @StereoType). Like @Model which is actually an @Named and @RequestScoped. Injections can be qualified with self defined annotations that are @Qualifiers. Then you get something like @Inject @Myqualifier MyDao dao; .

But it might be better to do this in beans.xml and then you can have @Alternative for multiple implementers. In the beans.xml you can add them through <alternative>. A new scope is @ConversationScoped, @Dependent or you can build your own @ScopeType. For @ConversationScoped it is demarcated and thus it can be associated with individual browser tabs. It also is accesible from any JSF scope.

(seems like JSF was a main component of the talk thoughout al the demos)

Other interesting annotations are @Consumer and @Producer but the speakers didn’t go into these.

There is a whole set of Portable Extension to allow the user to extend the CDI framework.

The status of EE 6 in application servers. At the moment there is glassfish and jboss which have a Java EE 6 enabled server. TmaxSoft does EE 6. Websphere beta 8 maybe. WebLogic almost. Caucho only does the web profile part of EE6 so no jms etc.. Geronimo uses the open (openESB, openJPA …) stuff to try and implement EE 6.