Hi Rohan,
i have just tried it out and it works fine for me:
%curl -i
http://localhost:8084/JsonFromJaxb/resources/flights/
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json
Transfer-Encoding: chunked
Date: Tue, 17 Jun 2008 09:10:06 GMT
{"flights":{"flight":[{"flightId":{"$":"OK123"},"company":{"$":"Czech Airlines"},"number":{"$":"123"},"aircraft":{"$":"B737"}},{"flightId":{"$":"OK124"},"company":{"$":"Czech Airlines"},"number":{"$":"124"},"aircraft":{"$":"AB115"}}]}}% %curl -HAccept:application/xml -i
http://localhost:8084/JsonFromJaxb/resources/flights/
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/xml
Content-Length: 317
Date: Tue, 17 Jun 2008 09:10:19 GMT
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><flights><flight><flightId>OK123</flightId><company>Czech Airlines</company><number>123</number><aircraft>B737</aircraft></flight><flight><flightId>OK124</flightId><company>Czech Airlines</company><number>124</number><aircraft>AB115</aircraft></flight></flights>%
Tested with solaris nevada, jdk1.6u10, tomcat-6.0.16, jersey-0.7
I do not have any clue what is wrong in your case.
Do you see anything strange in your log files?
~Jakub
On Tue, Jun 17, 2008 at 01:33:55AM -0700, 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?
>
> On Tue, Jun 17, 2008 at 1:20 AM, Paul Sandoz <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) 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) 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
> >
--
http://blogs.sun.com/japod