Sunday, May 3, 2015

Stateful REST : it can be done

Even in the SOA Philosophy, mostly based on SOAP over HTTP, a Service can be Stateful: you just need to enable javax.xml.ws.BindingProvider.SESSION_MAINTAIN_PROPERTY on the BindingProvider

in order to maintain state, you don't necessarily need to implement a Service as a Stateful EJB!

See http://docs.oracle.com/cd/E19226-01/820-7627/6nisfjmk8/index.html :

Stateful interactions through hyperlinks. Every interaction with a resource is stateless; that is, request messages are self-contained. Stateful interactions are based on the concept of explicit state transfer. Several techniques exist to exchange state, such as URI rewriting, cookies, and hidden form fields. State can be embedded in response messages to point to valid future states of the interaction. This topic is discussed somewhat in Using Entity Providers to Map HTTP Response and Request Entity Bodies, is discussed somewhat in the section Building URIs in the JAX-RS Overview document, and may be discussed in more detail in a forthcoming advanced version of this tutorial.

One can achieve this in JAX-RS 2.0 by using the javax.ws.rs.client.ClientResponseFilter for saving the cookie(s) from the HttpRequest and the javax.ws.rs.client.ClientRequestFilter for adding them again in the (subsequent) requests.

If you use WebLogic on the server side, remember that Jersey 2.5.1 is the supported "JAX-RS 2.0 Reference Implementation"



No comments: