users@jersey.java.net

Re: [Jersey] Returning XML in the JsonFromJaxb example

From: Rohan Sahgal <rohansahgal_at_gmail.com>
Date: Tue, 17 Jun 2008 11:00:14 -0700

You are right its probably a bug with the example code. When I tried with
curl it gave me the same behavior. I then wrote my own test client using
HttpClient and that works too.

Thanks,
Rohan

On Tue, Jun 17, 2008 at 2:08 AM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:

> Rohan Sahgal wrote:
>
>> I am using stable 0.7
>> and yes that was a typo, i meant application/xml.
>>
>> Should I not expect the same behavior when I deploy it as a webapp?
>>
>>
> You should observe the same behavior as i do in 0.8 (deployed as a web app)
> as for 0.7, but it could be a bug in the 0.7 example code.
>
> If you use curl as i did in the previous email what do you observe?
>
> BTW we are going to release 0.8 by the end of the week.
>
> Paul.
>
> On Tue, Jun 17, 2008 at 1:20 AM, Paul Sandoz <Paul.Sandoz_at_sun.com<mailto:
>> Paul.Sandoz_at_sun.com>> wrote:
>>
>> Rohan Sahgal wrote:
>>
>> I was just going through the examples in the Jersey distribution.
>>
>>
>> Stable 0.7 or latest 0.8 ?
>>
>>
>>
>> When I run the test client in the JsonFromJaxb example even in
>> the second case when we do a GET after the XML update, i get
>> JSON back, even though we have added Accept = accept/xml.
>>
>>
>> Do you mean:
>>
>> application/xml
>>
>>
>> ?
>>
>> Is there a reason for this behavior? How do I check returning
>> XML then?
>>
>> I compiled the war and deployed it in my tomcat.
>>
>>
>> In 0.8 we merged the test client with the web project and it now
>> uses the Jersey client API.
>>
>> If i modify the code and added the following lines at the end:
>>
>>
>> System.out.println(wr.path("flights/").accept("application/json").get(String.class));
>>
>>
>> System.out.println(wr.path("flights/").accept("application/xml").get(String.class));
>>
>> And the client prints out:
>>
>> {"flight":{"flightId":"OK125","company":"Czech
>> Airlines","number":125,"aircraft":"B737"}}
>>
>> <?xml version="1.0" encoding="UTF-8"
>>
>> standalone="yes"?><flights><flight><flightId>OK125</flightId><company>Czech
>>
>> Airlines</company><number>125</number><aircraft>B737</aircraft></flight></flights>
>>
>> The output from using curl is shown at the end of the email.
>>
>> Hope this helps,
>> Paul.
>>
>>
>> > curl -v -H"Accept: application/xml"
>> http://localhost:8080/JsonFromJaxb/resources/flights/
>> * About to connect() to localhost port 8080
>> * Trying 127.0.0.1... connected
>> * Connected to localhost (127.0.0.1 <http://127.0.0.1>) port 8080
>> > GET /JsonFromJaxb/resources/flights/ HTTP/1.1
>> > User-Agent: curl/7.15.5 (i386-pc-solaris2.11) libcurl/7.15.5
>> OpenSSL/0.9.8a zlib/1.2.3 libidn/0.6.8
>> > Host: localhost:8080
>> > Accept: application/xml
>> >
>> < HTTP/1.1 200 OK
>> < X-Powered-By: Servlet/2.5
>> < Server: Sun Java System Application Server 9.1
>> < Content-Type: application/xml
>> < Content-Length: 195
>> < Date: Tue, 17 Jun 2008 08:16:17 GMT
>> Connection #0 to host localhost left intact
>> * Closing connection #0
>> <?xml version="1.0" encoding="UTF-8"
>>
>> standalone="yes"?><flights><flight><flightId>OK125</flightId><company>Czech
>>
>> Airlines</company><number>125</number><aircraft>B737</aircraft></flight></flights>>
>>
>> >
>> > curl -v -H"Accept: application/json"
>> http://localhost:8080/JsonFromJaxb/resources/flights/
>> * About to connect() to localhost port 8080
>> * Trying 127.0.0.1... connected
>> * Connected to localhost (127.0.0.1 <http://127.0.0.1>) port 8080
>> > GET /JsonFromJaxb/resources/flights/ HTTP/1.1
>> > User-Agent: curl/7.15.5 (i386-pc-solaris2.11) libcurl/7.15.5
>> OpenSSL/0.9.8a zlib/1.2.3 libidn/0.6.8
>> > Host: localhost:8080
>> > Accept: application/json
>> >
>> < HTTP/1.1 200 OK
>> < X-Powered-By: Servlet/2.5
>> < Server: Sun Java System Application Server 9.1
>> < Content-Type: application/json
>> < Transfer-Encoding: chunked
>> < Date: Tue, 17 Jun 2008 08:16:29 GMT
>> * Connection #0 to host localhost left intact
>> * Closing connection #0
>> {"flight":{"flightId":"OK125","company":"Czech
>> Airlines","number":125,"aircraft":"B737"}}>
>>
>> -- | ? + ? = To question
>> ----------------\
>> Paul Sandoz
>> x38109
>> +33-4-76188109
>>
>>
>>
> --
> | ? + ? = To question
> ----------------\
> Paul Sandoz
> x38109
> +33-4-76188109
>