use of org.glassfish.jersey.uri.UriTemplate in project brave by openzipkin.
the class SpanCustomizingApplicationEventListener method route.
/**
* This returns the matched template as defined by a base URL and path expressions.
*
* <p>Matched templates are pairs of (resource path, method path) added with
* {@link org.glassfish.jersey.server.internal.routing.RoutingContext#pushTemplates(UriTemplate,
* UriTemplate)}. This code skips redundant slashes from either source caused by Path("/") or
* Path("").
*/
@Nullable
static String route(ContainerRequest request) {
ExtendedUriInfo uriInfo = request.getUriInfo();
List<UriTemplate> templates = uriInfo.getMatchedTemplates();
int templateCount = templates.size();
if (templateCount == 0)
return "";
// don't allocate unless you need it!
StringBuilder builder = null;
String basePath = uriInfo.getBaseUri().getPath();
String result = null;
if (!"/".equals(basePath)) {
// skip empty base paths
result = basePath;
}
for (int i = templateCount - 1; i >= 0; i--) {
String template = templates.get(i).getTemplate();
// skip allocation
if ("/".equals(template))
continue;
if (builder != null) {
builder.append(template);
} else if (result != null) {
builder = new StringBuilder(result).append(template);
result = null;
} else {
result = template;
}
}
return result != null ? result : builder != null ? builder.toString() : "";
}
Aggregations