users@glassfish.java.net

Re: JAX RS / Jersey Question

From: emiddio-verizon <emiddio_at_verizon.net>
Date: Thu, 18 Feb 2010 09:06:04 -0800

i subscribe to the jersey list also -- jersey.dev.java.net

gary

----- Original Message -----
From: <glassfish_at_javadesktop.org>
To: <users_at_glassfish.dev.java.net>
Sent: Wednesday, February 17, 2010 3:49 PM
Subject: JAX RS / Jersey Question


If i'm posting this in the incorrect forum please let me know.

I have a few simple web methods exposed over Glassfish V3 using Jersey / JAX
RS.
Basically, these are @GET methods and a single @POST method. My client
implementation follows the pattern listed in the Jersey Documentation here:

https://jersey.dev.java.net/nonav/documentation/latest/user-guide.html

Client test methods are similar to this:
[code]
    Client c = Client.create();
    WebResource r = c.resource(“http://localhost:8080/...”);
    String response = r.accept("text/plain").post(String.class, request);
[/code]


I'm running into an issue on one of my server methods which performs a Post,
and does some more meaniningful work. I was under the impression that I
could ask for a JSONObject from the client, and receive this on the server
so I did the following on the server:

[code]
@POST
@Path("submit")
@Consumes("application/json")
@Produces("text/plain")
public String doSubmit ( JSONObject object ) {

    // stuff
    return id;
}
[/code]


The corresponding test client method for the post is listed as such:
[code]
    Client c = Client.create();
    WebResource r = c.resource(“http://localhost:8080/submit”);

    JSONObject object = new JSONObject ();
    /* cofigure the object (code not shown) */
    String response =
r.accept("text/plain").type("application/json").post(String.class, request);
[/code]

How does one send a JSONObject over post from the client to the server? Or
is it the client's responsibility to only send strings? I see that there is
low-level support included for JSON Objects according to the Jersey manual,
I would think that they could be serialized somehow?

thanks
[Message sent by forum member 'hoffman462' (HoffmanDanielG_at_gmail.com)]

http://forums.java.net/jive/thread.jspa?messageID=387280

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
For additional commands, e-mail: users-help_at_glassfish.dev.java.net