On Fri, Jan 21, 2011 at 4:34 PM, Dan King<[email protected]>  wrote:

2. Where can I find examples of custom
message body reader/writer implementation examples? I've searched
everywhere and
found nothing that helps in understanding how to implement a custom one.

If you need to go that route, Example 6-02 of the JAX-RS book examples[1] has a rather complex MessageBodyReader/Writer example. Note this example had uncovered a bug that was quickly fixed in CXF 2.3.2 which should be released very shortly[2] -- however most other MBR/MBW implementations will work in CXF 2.3.1.


[1] http://www.jroller.com/gmazza/date/20110117
[2] http://cxf.547215.n5.nabble.com/VOTE-Apache-CXF-2-3-2-tp3345633p3350807.html

3. I checked the example Glenn suggested, however that example does NOT use
"ResponseReader". The method "useSimpleProxy" in "RESTClient.java", creates
a
client proxy from which it retrieves a collection of person objects; it
never
deals with a "Response" object. Did I miss something in the example?


I apologize, the code I mentioned above will be in the *next* release of the Talend examples, it actually uses brand new functionality put in by Sergey in CXF 2.3.2. An example of ResponseReader (from the upcoming Talend samples) is below:

public void useSimpleProxy() {
System.out.println("Using a simple JAX-RS proxy to get all the persons...");
ResponseReader reader = new ResponseReader();
reader.setEntityClass(PersonCollection.class);

String webAppAddress = "http://localhost:"; + port + "/services/personservice"; PersonService proxy = JAXRSClientFactory.create(webAppAddress, PersonService.class,
Collections.singletonList(reader));

// getPersons(a, b): a is zero-based start index, b is number of records
// to return (-1 for all)
Response resp = proxy.getPersons(0, -1);
if (resp.getStatus() == 200) {
PersonCollection personColl = (PersonCollection)resp.getEntity();
List<Person> persons = personColl.getList();
for (Iterator<Person> it = persons.iterator(); it.hasNext();) {
Person person = it.next();
System.out.println("ID " + person.getId() + " : " + person.getName() + ", age : "
+ person.getAge());
}
}
}

Again, though, this will unfortunately need to wait until CXF 2.3.2 is out.

HTH,
Glen




Thanks.

-Dan

----- Original Message ----

From: Sergey Beryozkin<[email protected]>
To: [email protected]
Sent: Fri, January 21, 2011 6:37:54 AM
Subject: Re: How to convert response input stream to java object

ResponseReader is a custom MessageBodyReader<Response>  handler which  is
registered on the client side, it allows to do a safe type casting, such
  as
Response response = webClient.get();
Book book =  (Book)Response.getEntity();

It's possibe to write your own custom  Response reader with any CXF
version
supporting the client api, but using the  ResponseReader makes it
simpler...
Please check the demo Glen linked  to.

Sergey

On Fri, Jan 21, 2011 at 4:08 AM, Glen Mazza<[email protected]>  wrote:

I  think ResponseReader, recently introduced in CXF 2.3.1, is your
  friend.
If you go to the Talend Service Factory (CXF wrap)  Examples[1], under
examples/jaxrs-advanced/client/..../RESTClient.java,  method
useSimpleProxy()
has it.

Glen

[1]  http://www.talend.com/resources/documentation.php#SF


  --
Glen Mazza
Software Engineer, Talend  (http://www.talend.com)
blog:  http://www.jroller.com/gmazza








--
Glen Mazza
Software Engineer, Talend (http://www.talend.com)
blog: http://www.jroller.com/gmazza


Reply via email to