Hi Paul,
This is exactly the problem I found. I got 307 instead of 201. A trivial
question is how to treat a uri with "/" at the end the same as without one?
And what are the scenarios when a "/" is critical for resources?
BTW: I read the tutorials written by you (I guess) to use netbean and curl
as basic tools. I tried to use eclipse to create wars, and it is not that
difficult as I thought. I will write a page on that. For function testing, I
found rest-client (
http://code.google.com/p/rest-client/) is a little easier
to handle than curl.
Thank you,
Dong
On Jan 31, 2008 3:19 AM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
> Hi Dong,
>
> Dong Liu wrote:
> > Hi,
> >
> > Is it possible to have a method that has two parameters like the
> following?
> >
> > @Path("{user}/")
> > @PUT
> > @ConsumeMime("application/json")
> > public Response updateAddress(@UriParam("user") String user,
> > JSONObject address) throws JSONException{
> > ...
> > }
> >
> >
>
> Yes, this is supported. A single non-annotated method parameter is the
> Java type of the request entity.
>
>
> > I tried, but it did not work. It seems that the JSONObject from request
> > is not passed.
>
> When you say "not passed" is the 'updateAddress' method called but the
> 'address' field is null?
>
>
> > Is there any other way to do this besides creating a new
> > resource/class for @Path("{user}/")?
> >
>
> Note that the @Path("{user}/") as a '/' at the end so if a the client
> request URI does not have a slash then Jersey will send a 307 redirect
> response to a URI that has a slash. If you remove the '/' redirection
> will not be supported.
>
> I created a very simple root resource:
>
> import javax.ws.rs.ConsumeMime;
> import javax.ws.rs.PUT;
> import javax.ws.rs.Path;
> import javax.ws.rs.ProduceMime;
> import javax.ws.rs.UriParam;
> import org.codehaus.jettison.json.JSONObject;
>
> @Path("users")
> public class HelloWorldResource {
>
> @Path("{user}")
> @PUT
> @ConsumeMime("application/json")
> @ProdiceMime("application/json")
> public String updateAddress(@UriParam("user") String user,
> JSONObject address) {
> System.out.println(user);
> return address.toString();
> }
> }
>
> deployed it then ran a simple curl command:
>
> curl -v -T a.json http://localhost:8080/Users/users/sdsdsd
>
> where 'a.json' is a file containing the following json:
>
> {"menu":"abc"}
>
> and curl will PUT this file to the above URL. I got the following output:
>
> > PUT /Users/users/sdsdsd 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: */*
> > Content-Length: 14
> > Expect: 100-continue
> >
> < HTTP/1.1 100 Continue
> < HTTP/1.1 200 OK
> < X-Powered-By: Servlet/2.5
> < Server: Sun Java System Application Server 9.1
> < Content-Type: application/json
> < Content-Length: 14
> < Date: Thu, 31 Jan 2008 09:12:22 GMT
> Connection #0 to host localhost left intact
> * Closing connection #0
> {"menu":"abc"}
>
> Hope this helps,
> Paul.
>
> --
> | ? + ? = To question
> ----------------\
> Paul Sandoz
> x38109
> +33-4-76188109
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>
--
Dong Liu
http://blogs.usask.ca/dong_notes/