Dong Liu wrote:
> Hi Paul,
>
> This is exactly the problem I found. I got 307 instead of 201.
If you create a @GET method, and type the URI (minus the end '/') into
the go field of a browser you will notice that it will perform a
redirect. Sometimes it is possible to configure a client to perform
redirection.
> 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?
>
I tried to follow the same rules as that performed on common web sites
like the W3C web sites. Users sometimes type URIs and when URIs are
passed around '/' gets added or dropped.
I think there are 3 options for a URI not-ending and a URI ending in a '/'.
1) treat both URIs as different where one returns a 404
2) treat both URIs as different but internally map them to the same
resource state
3) redirect one URI to the other.
I think it also depends on whether the URI corresponds to a resource
that has links to related resources (like a directory) or is a leaf
(like a file). For the former 3) is nice because the client is informed
of the canonical URI. For the latter 1) makes more sense.
2) can result in caches duplicating information. Thus i think it best to
try and support canonical URIs.
Thats the logic behind it. But it can trip up developers, perhaps i
should disable redirection by default?
> 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.
Great!
> For
> function testing, I found rest-client
> (http://code.google.com/p/rest-client/) is a little easier to handle
> than curl.
>
Thanks for the pointer, it looks interesting and useful.
BTW the NetBeans RESTful Web services plugin comes with a browser-based
client that can test the services, it uses WADL from the resources to
help drive it.
Note that Jersey is using it's own client side API for unit testing that
reuses some of the concepts from the server side. I will be making this
a public API for the 0.6 release.
Paul.
> Thank you,
>
> Dong
>
> On Jan 31, 2008 3:19 AM, Paul Sandoz <Paul.Sandoz_at_sun.com
> <mailto: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
> <mailto:users-unsubscribe_at_jersey.dev.java.net>
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
> <mailto:users-help_at_jersey.dev.java.net>
>
>
>
>
> --
> Dong Liu
> http://blogs.usask.ca/dong_notes/
--
| ? + ? = To question
----------------\
Paul Sandoz
x38109
+33-4-76188109