Tag Archives: JEE 6

CDI Conversations for JAX-RS with JEE 6

RESTful services are a great basis for client sided JavaScript WebApps whether written in jQuery UI or AngularJS among others. However browsers can only associate server responses to the correct tab if the request is unique, otherwise if the site is open in multiple tabs the response may be routed to any one of the open tabs.

The routing issue can be solved by simply adding an arbitrary tab specific unique parameter to the request that allows the browser to route the response to the correct tab.

[html]
../resources/stuff?tabUniqueId=1
[/html]

This works as long as we don’t want to maintain any tab specific server sided state. CDI Conversations offer and easy and ready made solution to this problem. When dealing with JSF applications it is a simple matter of dealing with conversations, since the entire handling is performed by the respective CDI and JSF implementation.
Continue reading CDI Conversations for JAX-RS with JEE 6

Synchronizing access to CDI Conversations

If you are using CDI’s conversations you will most likely have come across the dreaded BusyConversationException. The CDI 1.0 specification states that the container must ensure that only one request at a time may be associated with the conversation by blocking or rejecting subsequent requests.

OpenWebBeans will immediately reassign and throw a BusyConversationException if the conversation is currently held by another request. Weld on the other hand uses a 1 second timeout to obtain a lock on the conversation before reassigning the request and throwing a BusyConversationException. Although this makes it less likely to occur, if you are dealing with multiple waiting requests or long running processes, you will still encounter them.
Continue reading Synchronizing access to CDI Conversations

Push notifications with JEE 6

For most modern webapps push notifications have become a standard requirement. WebSockets would be my first choice, however it has only become available with JEE 7. It will take some time until JEE 7 compliant servers reach main stream production environments.

In the mean time we can achieve similar behavior with Servlet 3.0, which has become part of the JEE 6 specification, either by polling or long polling.

Polling relies on the client repeatedly sending requests to the server, polling for new messages. This will often result in empty responses, to avoid this unnecessary traffic we can hold on to the request until a new message is available or time-out is reached (long polling).

Effectively long polling requires the client to send a request, which is kept alive by the server until a response is available or a time out occurs. It is up to the client to initiate another request in both cases.

To do this we have to accept incoming GET requests and set asyncSupported to true. This stops the response object from being committed on method exit.
Continue reading Push notifications with JEE 6