JAX-RS client support
jervisliu Nov 25, 2008 3:08 AMHi, I recently had a chat with Stefano on WISE IRC regarding the possibilities of supporting JAX-RS client in WISE with a "near to zero-code approach".
One possibility is through WISE GUI. Below is a typical scenario:
User opens WISE GUI, selects the option of "Sending a request to JAX-RS services". On the GUI, user needs to fill in following information.
1. The URI of JAX-RS service resource. Eg, http://localhost:80/bookservice/books/123
2. Http method to use(GET|PUT|POST|DELETE)
3. HTTP headers to use
4. The content of the request: we will probably has a text box to allow users to input the request as plain text or be able to point to a local file then load the file as a stream.
Once information above are collected, WISE will generate a request and sent it out to JAX-RS server. What underlying libraries to use are not relevant to the end users, as long as it is "code-free" from the end users' prospective.
Another possibility is though a programmatic client side API. However design a decent client side API for JAX-RS is never an easy job, that's why JAX-RS spec does not have a plan to address client API in its 1.0 version at all. There are already many projects working on JAX-RS specific areas such as Jersey, Apache CXF, RESTEasy etc, I don't think WISE wants to join this competition which is not what WISE is about to focus on anyway, right? Of course the alternative is to leverage one of these projects then add values by using WISE. I had a quick look into RESTEasy[1], but I do not see how "zero-code" is going to be achieved. RESTEasy client framework requires one to hand write a JAVA interface like below:
public interface SimpleClient
{
@GET
@Path("basic")
@ProduceMime("text/plain")
String getBasic();
@PUT
@Path("basic")
@ConsumeMime("text/plain")
void putBasic(String body);
@GET
@Path("queryParam")
@ProduceMime("text/plain")
String getQueryParam(@QueryParam("param")String param);
@GET
@Path("matrixParam")
@ProduceMime("text/plain")
String getMatrixParam(@MatrixParam("param")String param);
@GET
@Path("uriParam/{param}")
@ProduceMime("text/plain")
int getUriParam(@PathParam("param")int param);
}
All the magic that WISE can do is based on the service contract(WSDL in the case of JAX-WS). From the service contract, the complexity can be hidden by doing the code generation on the fly. If there is no contract available (which is the case for most RESTful services, there is no formal service contract description language) or user has to write a contract manually (in the RESTEasy case, the Java interface serves as the contract of JAX-RS service, from which a client proxy can be generated), I do not see how WISE is going to play its role. Well, I could be wrong though, I am new to both RESTEasy and WISE, so please do correct me if I got it wrong.
Comments are welcome.
Thanks,
Jervis