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).
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.