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.

iText In Action

In the session iText in action Bruno Lowagie talks about his new edition of the book.

Bruno started with pointing out that he knows PDF better then he knows Java.
In the first part Bruno show in a hands on session how he created the devoxx programme guide using the devoxx rest interface for retrieving the data and the iText library to create the pdf version.

During the creation of the guide the viewer learned how to keep track of the page count to insert the page numbers next to the speakers bio. Also how to use acro-forms as some kind of a template engine. Together with this Bruno demonstrated that it’s best to use factories for your redundant data and styling.

During the whole session Bruno used a tool he created to view the pdf document structure (iText RUPS), where you can really see the internal document build up of a pdf. Here you can see that pdf is built up with objects, and that redundant objects can better be avoided to reduce the file size. When copying content from one pdf to another you can use the fast PdfCopy class or PdfSmartCopy. PdfSmartCopy keeps track of the objects hashes and when equal objects are found it will insert a reference rather then inserting the object twice.

A note about RUPS: it’s not yet officially released since RU stands for read and update, but the update functionality is not yet there.

In the second part we got an in depth overview of the books second edition with Bruno explaining the purpose of each chapter. With a focus on the chapter about XFA-forms. These forms allow pdf’s to be populated through xml documents that contain your data with an example. Another focus on was chapter 12 which goes about protecting your data and adding signatures to your documents, like timestamped signatures that are used to certify and validate documents.

For the second edition Bruno started to write the book from scratch. Manning demands that books can be read from back to back. Bruno chose to follow this rule throughout most of the book, but he made an exception for chapter 14. That chapter consists of a series of tables mapping all the graphical and text operators and operands available in PDF to the corresponding methods in iText. Such a chapter is weird for a Manning book, but Bruno convinced his publisher that it would be very useful for developers.

A really nice chapter is 13, going though the pdf spec itself and was reviewed by pdf guru Jim King.

We get an example of how to read and create pdf’s with iText (chapter 15) allowing you to recreate layout and data from from e.g. xml documents or other pdfs by using PDF Tags. You can parse an XML file to convert its content to ‘ordinary’ PDF, but if you also parse the XML for its structure to create a ‘Tagged PDF’, you allow more accessibility for readers for e.g. blind people. iText can also convert Tagged PDFs to XML which initially wasn’t in the iText 5 release but made it into the release when Bruno was creating a demo and wrote that code.

Of course a demonstration of adding flash components to a pdf for non static data could not be left out. This enhances pdf with variable date allowing a pdf reader to fetch data from e.g. the internet. Naturally this is secured, the reader will ask the user if a connection can be made. With embedding flash (which can call javascript from inside the pdf and vice versa) into pdfs, the documents become really interactive.

As an end note, we get Joachim Van der Auwera who’s giving a demo about using iText in geomajas, a webmapping framework built with java and gwt, that uses iText to output high resolution maps in pdfs. (On the funny side, Bruno himself also showed off a pdf like that. But his layers could be enabled/disabled. Geomajas can learn from that.)

What do we remember? euh.. this session is worth looking at on parleys.com once it’s there and you want to know what iText is about. And more: BUY the Book if you have any plans using iText. It’s a good reference !!

Thanks Bruno for this interesting session.

A new picture

Received a new picture today.

From now on I can call myself Oracle Certified Master, Java SE 6 Developer …

ugly logo !

OCM_JavaSE6Developer
OCM_JavaSE6Developer