You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Eric Le Goff <er...@babelgum.com> on 2007/12/19 12:32:48 UTC

Restful web services usage [WAS : JAXB Unmarshalling]

Sergey,

I must admit my question was badly asked. Actually I am wondering how
I could use restful web-services if clients only get an XML
representation of the Object they request ?
I am not using SOAP, nor any WSDL description.

I expected to be able to get a kind of "stub" object on client side
(may be thanks to a sort of "unmarshalling" of this XML I get from the
server)

The CXF Jaxrs demo piece of code I have shown in my previous mail only
shows how to display an XML representation of Customer with Id 123
which is fine. But in my case, I would like to manipulate an actual
Customer stub instance, so that I can call methods on it and do
interesting things with what the server has sent to me.

I might be confused because so far I was using Hessian
(http://hessian.caucho.com/) where their binary protocol allow a web
service client to get an actual instance of the object they request.

I might be totally wrong about Restful web services, and I realize
that it may totally absurd to have the same behaviour with REST as
what I had  with Hessian.

My question is more general :
How do Clients of Restful webservices get a concrete use of the XML
content they receive from the server ?
(I guess people just don't print out this XML on console :) but I
suppose they have to parse it/ unmarshall it  in some way ?)



PS :I don't know about WADL , so please excuse my ignorance.

Thanks for helping anyway ;)

Eric






On Dec 19, 2007 11:54 AM, Sergey Beryozkin <se...@iona.com> wrote:
> Hi
>
> I'm wondering, are you actually asking for a code generation be done on a client side with the help of a description language like WSDL 2.0 or WADL ?
>
> Cheers, Sergey
>
>
>
> ----- Original Message -----
> From: "Eric Le Goff" <el...@gmail.com>
> To: <cx...@incubator.apache.org>
> Sent: Tuesday, December 18, 2007 4:34 PM
> Subject: JAXB Unmarshalling
>
>
> >I am going on playing with the restful_jaxrs sample demo
> >
> >
> > In the Client.java there are these lines
> >
> > ...
> > URL url = new URL("http://localhost:9000/customerservice/customers/123");
> >        InputStream in = url.openStream();
> >        System.out.println(getStringFromInputStream(in));
> > ....
> >
> >
> > What if I did not want to display the XML content (ie the XML
> > representation of customer whose Id is 123)
> > But rather I would like to get the actual instance of Customer with id is 123
> >
> > Is there some Unmarshalling method to do that , something like
> >
> > ...
> > URL url = new URL("http://localhost:9000/customerservice/customers/123");
> >        InputStream in = url.openStream();
> >
> > // Hypothetic code
> > Customer customer = (Customer) getObjectFromInputStream(in);
> > ...
> >
> > How would I implement this
> >
> > Object getObjectFromInputStream(InputStream in)
> >
> > method ?
> >
> > I guess I would have to get a JaxbContext before I can get an Unmarshaller ?
> >
> >
> > Thanks for your help
> >
> > Eric
> >
> >
> >
> >
> > --
> > Eric Le Goff
>
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
>



-- 
Eric Le Goff

Re: Restful web services usage [WAS : JAXB Unmarshalling]

Posted by Sergey Beryozkin <se...@iona.com>.
Hi Eric

You asked a very good question.
It's always a choice. 

If you take XML out of the wire and handle it directly, perhaps
by providing some STAX/SAX handler which will populate a Customer class you created yourself (thus non necessarily even matching the actual data on the wire), then your client code in general is likely to be more robust when dealing with some changes on the server side.

I appreciate you're not using SOAP :-) but RESTful services may have their own machine-processible documents (WSDL 2.0/WADL). If you prefer to deal with more statically-typed artifacts, like Customer which is automatically populated for you by an underlying JAXB runtime, then one way or another you need to tell to the client runtime how to do it for you. I'm not aware of Hessian, but generally, providing some sort of description should do the trick. I personally don't see using description languages as a total evil :-). IMHO, it's much more important to make the actual schema for the data extensible and try to make the runtime ignore unknown elements when possible/realistic. AFAIK JAXB can be configured to ignore unrecognized elements.

Cheers, Sergey



----- Original Message ----- 
From: "Eric Le Goff" <er...@babelgum.com>
To: <cx...@incubator.apache.org>
Sent: Wednesday, December 19, 2007 11:32 AM
Subject: Restful web services usage [WAS : JAXB Unmarshalling]


> Sergey,
> 
> I must admit my question was badly asked. Actually I am wondering how
> I could use restful web-services if clients only get an XML
> representation of the Object they request ?
> I am not using SOAP, nor any WSDL description.
> 
> I expected to be able to get a kind of "stub" object on client side
> (may be thanks to a sort of "unmarshalling" of this XML I get from the
> server)
> 
> The CXF Jaxrs demo piece of code I have shown in my previous mail only
> shows how to display an XML representation of Customer with Id 123
> which is fine. But in my case, I would like to manipulate an actual
> Customer stub instance, so that I can call methods on it and do
> interesting things with what the server has sent to me.
> 
> I might be confused because so far I was using Hessian
> (http://hessian.caucho.com/) where their binary protocol allow a web
> service client to get an actual instance of the object they request.
> 
> I might be totally wrong about Restful web services, and I realize
> that it may totally absurd to have the same behaviour with REST as
> what I had  with Hessian.
> 
> My question is more general :
> How do Clients of Restful webservices get a concrete use of the XML
> content they receive from the server ?
> (I guess people just don't print out this XML on console :) but I
> suppose they have to parse it/ unmarshall it  in some way ?)
> 
> 
> 
> PS :I don't know about WADL , so please excuse my ignorance.
> 
> Thanks for helping anyway ;)
> 
> Eric
> 
> 
> 
> 
> 
> 
> On Dec 19, 2007 11:54 AM, Sergey Beryozkin <se...@iona.com> wrote:
>> Hi
>>
>> I'm wondering, are you actually asking for a code generation be done on a client side with the help of a description language like WSDL 2.0 or WADL ?
>>
>> Cheers, Sergey
>>
>>
>>
>> ----- Original Message -----
>> From: "Eric Le Goff" <el...@gmail.com>
>> To: <cx...@incubator.apache.org>
>> Sent: Tuesday, December 18, 2007 4:34 PM
>> Subject: JAXB Unmarshalling
>>
>>
>> >I am going on playing with the restful_jaxrs sample demo
>> >
>> >
>> > In the Client.java there are these lines
>> >
>> > ...
>> > URL url = new URL("http://localhost:9000/customerservice/customers/123");
>> >        InputStream in = url.openStream();
>> >        System.out.println(getStringFromInputStream(in));
>> > ....
>> >
>> >
>> > What if I did not want to display the XML content (ie the XML
>> > representation of customer whose Id is 123)
>> > But rather I would like to get the actual instance of Customer with id is 123
>> >
>> > Is there some Unmarshalling method to do that , something like
>> >
>> > ...
>> > URL url = new URL("http://localhost:9000/customerservice/customers/123");
>> >        InputStream in = url.openStream();
>> >
>> > // Hypothetic code
>> > Customer customer = (Customer) getObjectFromInputStream(in);
>> > ...
>> >
>> > How would I implement this
>> >
>> > Object getObjectFromInputStream(InputStream in)
>> >
>> > method ?
>> >
>> > I guess I would have to get a JaxbContext before I can get an Unmarshaller ?
>> >
>> >
>> > Thanks for your help
>> >
>> > Eric
>> >
>> >
>> >
>> >
>> > --
>> > Eric Le Goff
>>
>> ----------------------------
>> IONA Technologies PLC (registered in Ireland)
>> Registered Number: 171387
>> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
>>
> 
> 
> 
> -- 
> Eric Le Goff

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

Re: Restful web services usage [WAS : JAXB Unmarshalling]

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
Hi Eric

First of all, I must confess that im pretty new to all this webservice 
stuff. I found a blog about restful web services that describes howto 
interact with them:

http://blog.jonudell.net/2007/05/24/restful-web-services/

But you want a kind of client interface for that aswell?

regards Nino

Eric Le Goff wrote:
> Sergey,
>
> I must admit my question was badly asked. Actually I am wondering how
> I could use restful web-services if clients only get an XML
> representation of the Object they request ?
> I am not using SOAP, nor any WSDL description.
>
> I expected to be able to get a kind of "stub" object on client side
> (may be thanks to a sort of "unmarshalling" of this XML I get from the
> server)
>
> The CXF Jaxrs demo piece of code I have shown in my previous mail only
> shows how to display an XML representation of Customer with Id 123
> which is fine. But in my case, I would like to manipulate an actual
> Customer stub instance, so that I can call methods on it and do
> interesting things with what the server has sent to me.
>
> I might be confused because so far I was using Hessian
> (http://hessian.caucho.com/) where their binary protocol allow a web
> service client to get an actual instance of the object they request.
>
> I might be totally wrong about Restful web services, and I realize
> that it may totally absurd to have the same behaviour with REST as
> what I had  with Hessian.
>
> My question is more general :
> How do Clients of Restful webservices get a concrete use of the XML
> content they receive from the server ?
> (I guess people just don't print out this XML on console :) but I
> suppose they have to parse it/ unmarshall it  in some way ?)
>
>
>
> PS :I don't know about WADL , so please excuse my ignorance.
>
> Thanks for helping anyway ;)
>
> Eric
>
>
>
>
>
>
> On Dec 19, 2007 11:54 AM, Sergey Beryozkin <se...@iona.com> wrote:
>   
>> Hi
>>
>> I'm wondering, are you actually asking for a code generation be done on a client side with the help of a description language like WSDL 2.0 or WADL ?
>>
>> Cheers, Sergey
>>
>>
>>
>> ----- Original Message -----
>> From: "Eric Le Goff" <el...@gmail.com>
>> To: <cx...@incubator.apache.org>
>> Sent: Tuesday, December 18, 2007 4:34 PM
>> Subject: JAXB Unmarshalling
>>
>>
>>     
>>> I am going on playing with the restful_jaxrs sample demo
>>>
>>>
>>> In the Client.java there are these lines
>>>
>>> ...
>>> URL url = new URL("http://localhost:9000/customerservice/customers/123");
>>>        InputStream in = url.openStream();
>>>        System.out.println(getStringFromInputStream(in));
>>> ....
>>>
>>>
>>> What if I did not want to display the XML content (ie the XML
>>> representation of customer whose Id is 123)
>>> But rather I would like to get the actual instance of Customer with id is 123
>>>
>>> Is there some Unmarshalling method to do that , something like
>>>
>>> ...
>>> URL url = new URL("http://localhost:9000/customerservice/customers/123");
>>>        InputStream in = url.openStream();
>>>
>>> // Hypothetic code
>>> Customer customer = (Customer) getObjectFromInputStream(in);
>>> ...
>>>
>>> How would I implement this
>>>
>>> Object getObjectFromInputStream(InputStream in)
>>>
>>> method ?
>>>
>>> I guess I would have to get a JaxbContext before I can get an Unmarshaller ?
>>>
>>>
>>> Thanks for your help
>>>
>>> Eric
>>>
>>>
>>>
>>>
>>> --
>>> Eric Le Goff
>>>       
>> ----------------------------
>> IONA Technologies PLC (registered in Ireland)
>> Registered Number: 171387
>> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
>>
>>     
>
>
>
>   

-- 
Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684