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