On Feb 25, 2009, at 1:01 AM, Rabick, Mark A (MS) wrote:
> I was just looking at the article referenced from the Jersey Wiki
>
> http://www.javarants.com/2008/12/25/using-jax-rs-jersey-to-build-a-
> jpajaxb-backed-json-rest-api/
>
> @GET
> @Produces("application/json")
> @Path("/network/{id: [0-9]+}/{nid}")
> public User getUserByNetworkId(@PathParam("id") int id,
> @PathParam("nid") String networkId)
> {
> Query q = em.createQuery("SELECT u FROM User u WHERE
> u.networkId = :id AND
> u.networkUserId = :nid");
> q.setParameter("id", id);
> q.setParameter("nid", networkId);
> return (User) q.getSingleResult();
> }
>
> Is the {id: [0-9]+} notation in the @Path statement a regex? Will
> it only 'accept' or bind the resource if the id parameter is all
> digits?
>
The resource method will only be *matched* if the URI path matches
the @Path. In this case where one path segment has one or more digits.
> What happens if the uri requested is /network/99AAAA/someNid?
>
A 404 will be returned because the URI path does not match, if no
other @Paths match as well.
>
> Will it cause an error in the URI parser because the @PathParam id
> is an 'int'?
>
No. If the @Path was "network/{id}/{nid}" then there would be an
error converting a path segment "99AAAA". A 404 will be returned but
no other @Path matching will be attempted.
> Is there some documentation that describes the available filtering
> at the URI fragment or
> Query parameter level?
>
No matching occurs for query parameters as it encourages an RPC-based
approach to the development of the Web services. Only the URI path
component is taken into account.
See the JavaDoc for @Path:
https://jsr311.dev.java.net/nonav/javadoc/javax/ws/rs/Path.html
and also the JAX-RS overview document:
http://wikis.sun.com/display/Jersey/Overview+of+JAX-RS+1.0+Features
I highly recommend you develop a very simple example, perhaps
modifying the hello world web app sample [1], to experiment with path
matching.
Paul.
[1]
http://download.java.net/maven/2/com/sun/jersey/samples/
helloworld-webapp/1.0.2/helloworld-webapp-1.0.2-project.zip
> --mark
> _______________________________________________
> Mark A. Rabick
> Software Engineer
> Northrop Grumman - C2 Systems (MS/C2SD/IIS)
> 3200 Samson Way
> Bellevue, NE 68123
> Ph: (402) 293-7091
> Em: mark.rabick_at_ngc.com
> Remember PFC Ross A. McGinnis...
> http://www.army.mil/medalofhonor/McGinnis/index.html
> ... MA2 Michael A. Monsoor, Lt. Michael P. Murphy, Cpl. Jason
> Dunham, SFC Paul Ray Smith and the rest...
> http://www.cmohs.org/recipients/most_recent.htm
>