users@jersey.java.net

Re: [Jersey] Jersey UriInfo /Jersey _at_Path

From: António Mota <amsmota_at_gmail.com>
Date: Tue, 18 Nov 2008 11:56:10 +0000

Hi, thanks for your quick reply.

1) If I understood correctly, it will be responsibility of the AS to
somehow inject some instance of UriInfo into the application (or at
least some kind of container like Spring), so that will only work with
a AS/Container that is JAX-RS aware, or am I wrong? I tried to inject
it with Spring, but of course complains that UriInfo is not a class.

2) We're using Jersey 0.8, and planning to upgrade to 1.0 only if
necessary cause we're close to our deadline and don't want to risk
changes.

But I don't understand exactly your explanation. What I'm doing
basically is looping to the abstractResource.getSubResourceMethods(),
get the UriPath of each and using a UriTemplate to match it, something
like

        for (AbstractSubResourceMethod subMethod :
abstractResource.getSubResourceMethods()) {
                        uriPath = subMethod.getUriPath().getValue();
                        uriTemplate = new UriTemplateRS(uriPath);
                        if (uriTemplate.matchExact(uri, map)) {
                               //do some more checks here
                               return subMethod;
                        }
                }

and the order they appear is precisely the contrary of what the spec
says. Nevertheless, the problem still arises because a URI to be
matched to the second path will be matched by the first anyhow.

Is there a more "jersyan" way to do this?

3) Yes, I'm using Matrix params. First, let me tell you that I
searched the net for a good explanation of Matrix params and the only
good source of information I've found were your answers in a thread on
this mailing list archives. Thank you for that.

Now, from what you just said, that is starnge because I'm getting
exactly what I want, for instance, for

        @GET
        @Path("/data/query/{queryname}")
        Object getQuery(@PathParam("queryname")String queryName,
 @MatrixParam("queryparams")Map<String, String> params);

and

/data/query/countriesBy2LetterCodeOrByNumCode;2letterCode=PT;numCode=620

in my params Map I get the two entries.

And I can't use PathSegment because I'm really only writing the
service infrastructure, not the services themselves, and the services
are supposed to be "business" methods from a interface extracted from
a "business" class with just a bunch of rs annotations added, so I
can't be bound to anything rs-specific.

Once again, thanks for your input.



2008/11/18 Paul Sandoz <Paul.Sandoz_at_sun.com>:
>
> On Nov 18, 2008, at 11:43 AM, António Mota wrote:
>
>> Hello:
>>
>> I'm new in here, I'm developing a REST infrastructure for our internal
>> applications based basically on Spring Integration. I only
>> "discovered" Jersey in the middle of the project and started using
>> parts of it, so now my project is a mix of SI and Jersey. Basically,
>> SI for the communication and server-side handling and Jersey for the
>> connectors/resources side.
>>
>> So in this context I have some questions:
>>
>> 1) It seems that Jersey is tightly coupled with Glassfish, in a way
>> hat is only partially usable on other platforms, like in my case
>> JBoss. For instance, UriInfo being a "injectable interface" will not
>> work anywhere besides Glassfish, or am I wrong?
>>
>
> The annotations and injection rules are specified by JAX-RS so it should be
> portable across JAX-RS implementations. Thus Jersey should work in this
> respect with any app server.
>
>
>> 2) I'm relying heavily on the Jersey annotations
>
> Those are JAX-RS annotations, so again they are portable.
>
>
>> and the
>> AbtractResource and SubResources to match the templates with my
>> resource's methods. I have a problem with this situation:
>>
>> @GET
>> @Path("/data/{entity}/{key}")
>> Object read(@PathParam("entity")String entity,
>> @PathParam("key")String key);
>>
>> @GET
>> @Path("/data/query/{queryname}")
>> Object getQuery(@PathParam("queryname")String queryName,
>> @MatrixParam("queryparams")Map<String, String> params);
>>
>>
>> From what I saw until now, the same URI will always be matched by
>> these two paths, is there any way to distinguish between a "fixed"
>> part of the uri and a "variable" one?
>>
>
> It should work, what version of Jersey have you tried?
>
> The spec states:
>
> Sort E using the number of literal characters in each member as the primary
> key (descending order), the number of
> capturing groups as a secondary key (descending order) and the number of
> capturing groups with non-default regular
> expressions (i.e. not '([^ /]+?)') as the tertiary key (descending order).
>
> Thus the path template of "/data/query/{queryname}" will be sorted before
> "/data/{entity}/{key}" in terms of matching, because the former contains
> more literal characters than the latter. And therefore a path consisting of
> "<base>/data/query/params" will match the former template.
>
> I notice you want to use matrix params. A Map is not supported for
> @MatrixParam [1]. If you want to get all matrix params associated with a
> path parameter you can do:
>
> @GET
> @Path("/data/query/{queryname}")
> Object getQuery(
> @PathParam("queryname") PathSegment ps);
>
> Paul.
>
> [1] https://jsr311.dev.java.net/nonav/javadoc/javax/ws/rs/MatrixParam.html
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>