You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by John Klassa <jo...@klassa.com> on 2009/12/15 21:03:58 UTC
Re: URI parsing (for fun and profit)
Hi Sergey,
I'm finally getting back to this... From a logging interceptor, I don't have access to, e.g., UriInfo. All I have is a Message object... With respect to:
>> In addition, a CXF specific UriTemplate, available from the current ClassResorceInfo or OperationResourceInfo, can return a list of variable names for a given resource or method @Path value.
is there a way to query CXF to see which resource is a match, and then further drill down to use this template-based approach?
Thanks!
On Nov 23, 2009, at 10:57 AM, Sergey Beryozkin wrote:
> Hi John
>
> You might want to try UriInfo.getPathParameters(false) which will return the multivalued map of path template variables to the list of values pairs...Unless you have the same template variable used in multiple path annotations (probably not a good idea), every list will contain a single value only.
>
> So for ex you may have
>
> @Path("/foo/{var1}")
> public class Resource {
>
> @GET
> @Path("/bar/{var2}")
> public ResourceInfo get() {...}
> }
>
> now, given /foo/1/bar/2
>
> UriInfo.getPathParameters(false) will return a (linked list) map containing
> var1: {1}
> var2: {2}
>
> So, given these values and UriInfo.getPath(), you might be able to get to the static parts only, ex, get a substring till the first value like "1" occurs, then the next after "1" but before "2". But it might be brittle if static parts can contain 1 or 2, etc...
>
> In addition, a CXF specific UriTemplate, available from the current ClassResorceInfo or OperationResourceInfo, can return a list of variable names for a given resource or method @Path value.
>
> cheers, Sergey
>
>
>
>
> ----- Original Message ----- From: "John Klassa" <jo...@klassa.com>
> To: <us...@cxf.apache.org>
> Sent: Monday, November 23, 2009 3:09 PM
> Subject: URI parsing (for fun and profit)
>
>
>
> I managed to hook into our departmental logging infrastructure by building inbound and outbound logging interceptors... Cool stuff! I'm using JAX-RS, by the way.
>
> Anyway, on that note, I'd like to record an event like:
>
> GET /fooapi/v1/myresource/TCAS81121/subresource/EenieMeenie?a=b&c=d
>
> as, say:
>
> GET-/myresource/subresource
>
> Basically, I want to suck out the HTTP method name, plus any part of the URI that's static... Anywhere that I'd use the {WHATEVER} construct in a JSR-311 path annotation, I'd want to ignore that spot in the URI.
>
> Fetching the URI and method name are easy, in a logging interceptor:
>
> String uri = (String)message.get(Message.REQUEST_URI);
> String method = (String)message.get(Message.HTTP_REQUEST_METHOD);
>
> What I'd like to know, though, is whether I can hook into any existing functionality to extract the static parts of the URI, to build up an "event name" (if you will). I can do this by hand, but then there's a maintenance problem waiting to happen (as I'm maintaining URI info in two places -- here, and then also in the code-level annotations).
>
Re: URI parsing (for fun and profit)
Posted by Sergey Beryozkin <sb...@progress.com>.
Hi John
See comments prefixed with S.B. below,
cheers, Sergey
Hi Sergey,
I'm finally getting back to this... From a logging interceptor, I don't have access to, e.g., UriInfo. All I have is a Message
object...
If it is a custom RequestHandler filter then you can have UriInfo injected as a context, same way you can do it with a regular JAXRS
resource class
With respect to:
>> In addition, a CXF specific UriTemplate, available from the current ClassResorceInfo or OperationResourceInfo, can return a list
>> of variable names for a given resource or method @Path value.
is there a way to query CXF to see which resource is a match, and then further drill down to use this template-based approach?
> S.B ClassResourceInfo available to RequestHandler represents the selected resource; you can get the current resource method by
> doing
message.getExchange().getContent(OperationResourceInfo.class)
Thanks!
On Nov 23, 2009, at 10:57 AM, Sergey Beryozkin wrote:
> Hi John
>
> You might want to try UriInfo.getPathParameters(false) which will return the multivalued map of path template variables to the
> list of values pairs...Unless you have the same template variable used in multiple path annotations (probably not a good idea),
> every list will contain a single value only.
>
> So for ex you may have
>
> @Path("/foo/{var1}")
> public class Resource {
>
> @GET
> @Path("/bar/{var2}")
> public ResourceInfo get() {...}
> }
>
> now, given /foo/1/bar/2
>
> UriInfo.getPathParameters(false) will return a (linked list) map containing
> var1: {1}
> var2: {2}
>
> So, given these values and UriInfo.getPath(), you might be able to get to the static parts only, ex, get a substring till the
> first value like "1" occurs, then the next after "1" but before "2". But it might be brittle if static parts can contain 1 or 2,
> etc...
>
> In addition, a CXF specific UriTemplate, available from the current ClassResorceInfo or OperationResourceInfo, can return a list
> of variable names for a given resource or method @Path value.
>
> cheers, Sergey
>
>
>
>
> ----- Original Message ----- From: "John Klassa" <jo...@klassa.com>
> To: <us...@cxf.apache.org>
> Sent: Monday, November 23, 2009 3:09 PM
> Subject: URI parsing (for fun and profit)
>
>
>
> I managed to hook into our departmental logging infrastructure by building inbound and outbound logging interceptors... Cool
> stuff! I'm using JAX-RS, by the way.
>
> Anyway, on that note, I'd like to record an event like:
>
> GET /fooapi/v1/myresource/TCAS81121/subresource/EenieMeenie?a=b&c=d
>
> as, say:
>
> GET-/myresource/subresource
>
> Basically, I want to suck out the HTTP method name, plus any part of the URI that's static... Anywhere that I'd use the
> {WHATEVER} construct in a JSR-311 path annotation, I'd want to ignore that spot in the URI.
>
> Fetching the URI and method name are easy, in a logging interceptor:
>
> String uri = (String)message.get(Message.REQUEST_URI);
> String method = (String)message.get(Message.HTTP_REQUEST_METHOD);
>
> What I'd like to know, though, is whether I can hook into any existing functionality to extract the static parts of the URI, to
> build up an "event name" (if you will). I can do this by hand, but then there's a maintenance problem waiting to happen (as I'm
> maintaining URI info in two places -- here, and then also in the code-level annotations).
>