cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sergey Beryozkin" <>
Subject Re: JSON-RPC instead of JSON RESTful service
Date Wed, 25 Jun 2008 17:42:28 GMT

> Hello,
> I've seen the examples configuring a application/json RESTful web service.
> However, I'm interested in building a JSON-RPC service which will output
> JSON-RPC packets, example:
> Is this possible?
> (more specifically, the request should support named parameters instead of
> positional parameters)

I'm not sure about CXF in general easily supporting this kind of requests, perhaps it would
be a matter of creating your own custom
binding, not sure really.
That said, looks like it would likely be fairly easily achieved with its JAX-RS implementation
and with its CXF-specific JAX-RS

Consider this class :

public Service {
    public Response sum(int a, int b) { return Response.ok().entity(a+b);}

Now, consider your JSON RPC call :

POST /service HTTP/1.1
Content-Type: application/json
Accept: application/json
    "method"  : "sum",
    "params"  : [ 17, 25 ]

What we'd like to do here is to match this call against sum(int a, int b) above.
For this to happen, we need to have a pre-filter which will modify the request uri a bit,
such that it looks like this :

/service/sum?a=17&b=25 (ignoring the fact for a moment that queiries are not really for
POSTs due to the fact Tpmcat cuts of 
everything after ';' as far as I understand - or something similar)

The next is to update the method sum(int a, int b) like this

public Response sum(@QueryParam("a") int a, @QueryParam("b") int b) { return Response.ok().entity(a+b);}

The request filter I'm referring to is not on mailine yet, but it will be soon. You can register
your own filter and do some JSON
preprocessing of the request and update the incoming message with the updated uri. Perhaps
you can even do it (may be it's a better
solution for this specific task) in a standard Servlet filter by wrapping HttpServletRequest
- in which case you don't need to wait
for the updates to mainline.

> Also, the JSON-equivalent of a WSDL is SMD. Does Apache CXF have support for
> this? Or will a WSDL suffice?

For this to be supported you'd likely need to use a custom pre filter which will introspect
the resource class and return the SMD

Cheers, Sergey

> Thank you,
> Juan

IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

View raw message