Monday December 01, 2008
TOTD #58: Jersey and GlassFish - how to process POST requests ?
Lets extend the Jersey endpoint (TOTD#
56) and client (TOTD#
57) such that it can accept a POST request and then invoke it.
| @POST @Consumes("application/json") @Produces("application/json") public Greeting postIt(Greeting greeting) { System.out.println("In POST: " + greeting.greeting); return greeting; } |
| public void
testPost() { Greeting result = createResource(). type("application/json"). post(Greeting.class, new Greeting("yo!")); assertTrue(result.greeting.equals("yo!")); } |
| Running org.glassfish.samples.AppTest 1 * Out-bound request 1 > GET http://localhost:8080/helloworld-webapp/webresources/myresource 1 > 1 < 200 1 < X-Powered-By: Servlet/2.5 1 < Transfer-Encoding: chunked 1 < Content-Type: text/plain 1 < Server: GlassFish/v3 1 < Date: Tue, 25 Nov 2008 20:19:34 GMT 1 < <?xml version="1.0" encoding="UTF-8" standalone="yes"?><greeting><greeting>Hi there!</greeting></greeting> 1 * In-bound response 1 * Out-bound request 1 > POST http://localhost:8080/helloworld-webapp/webresources/myresource 1 > Content-Type: application/json 1 > {"greeting":"yo!"} 1 < 200 1 < X-Powered-By: Servlet/2.5 1 < Transfer-Encoding: chunked 1 < Content-Type: application/json 1 < Server: GlassFish/v3 1 < Date: Tue, 25 Nov 2008 20:19:34 GMT 1 < {"greeting":"yo!"} 1 * In-bound response Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.191 sec |
Posted by Arun Gupta in webservices | Comments[6]
|
|
|
|
|
Today's Page Hits: 2887
Total # blog entries: 1002
| « December 2008 » | ||||||
| Sun | Mon | Tue | Wed | Thu | Fri | Sat |
|---|---|---|---|---|---|---|
2 | 5 | 6 | ||||
7 | 8 | 9 | 10 | 12 | 13 | |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 | |||
| Today | ||||||