Tag Archives: JEE

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.

../resources/stuff?tabUniqueId=1

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

Using JCache in JEE 6/7

I can’t count the number of times I have come across yet another mostly buggy custom caching solution. Be it a HashMap stuck into a random DAO, a service or an annotation driven solution with interceptors of one flavor or another. I guess this is partially to blame on the long pending JCache specification (JSR-107), which has now been finalized last year some 13 years on from when it was first conceived.

Although JSR-107 missed the deadline for inclusion in the JEE 7 specification, it is still fairly easy to provide the required dependencies with your application to get full JSR-107 support in any JEE 6 or 7 compliant application server.

If you wanted, you could use the JSR-107 reference implementation, however it is strongly advised not to use the reference caching provider implementation since there is neither support nor an active community backing it.
Continue reading Using JCache in JEE 6/7

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