Thanks, Sergey -- will give that a go!
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" <[email protected]>
> To: <[email protected]>
> 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).
>