use of org.glassfish.jersey.uri.UriTemplate in project jersey by jersey.
the class UriRoutingContext method getPathParameterBounds.
private int[] getPathParameterBounds(final String name) {
final Iterator<UriTemplate> templatesIterator = templates.iterator();
final Iterator<MatchResult> matchResultsIterator = matchResults.iterator();
while (templatesIterator.hasNext()) {
MatchResult mr = matchResultsIterator.next();
// Find the index of path parameter
final int pIndex = getLastPathParameterIndex(name, templatesIterator.next());
if (pIndex != -1) {
int pathLength = mr.group().length();
int segmentIndex = mr.end(pIndex + 1);
final int groupLength = segmentIndex - mr.start(pIndex + 1);
// capturing group in the request path
while (matchResultsIterator.hasNext()) {
mr = matchResultsIterator.next();
segmentIndex += mr.group().length() - pathLength;
pathLength = mr.group().length();
}
return new int[] { segmentIndex - groupLength, segmentIndex };
}
}
return null;
}
use of org.glassfish.jersey.uri.UriTemplate in project jersey by jersey.
the class RuntimeModelBuilder method createResourceMethodRouters.
private List<MethodRouting> createResourceMethodRouters(final RuntimeResource runtimeResource, final boolean subResourceMode) {
final List<MethodRouting> methodRoutings = new ArrayList<>();
int i = 0;
for (final Resource resource : runtimeResource.getResources()) {
final Resource parentResource = runtimeResource.getParent() == null ? null : runtimeResource.getParentResources().get(i++);
final UriTemplate template = resource.getPathPattern().getTemplate();
final PushMatchedTemplateRouter templateRouter = parentResource == null ? getTemplateRouter(subResourceMode, template, null) : getTemplateRouter(subResourceMode, parentResource.getPathPattern().getTemplate(), template);
for (final ResourceMethod resourceMethod : resource.getResourceMethods()) {
methodRoutings.add(new MethodRouting(resourceMethod, templateRouter, new PushMatchedMethodRouter(resourceMethod), createMethodRouter(resourceMethod)));
}
}
return methodRoutings.isEmpty() ? Collections.<MethodRouting>emptyList() : methodRoutings;
}
use of org.glassfish.jersey.uri.UriTemplate in project jaeger-client-java by jaegertracing.
the class JerseyServerFilter method getPathOperationName.
/**
* Retrieves an operation name that contains the http method and value of the {@link Path} used by
* a Jersey server implementation.
*
* @return the operation name
*/
private String getPathOperationName(ContainerRequestContext containerRequestContext) {
String operationName = "";
try {
if (normalizedTemplate != null && containerRequestContext instanceof ContainerRequest) {
ContainerRequest containerRequest = (ContainerRequest) containerRequestContext;
ExtendedUriInfo uriInfo = containerRequest.getUriInfo();
if (uriInfo instanceof UriRoutingContext) {
UriRoutingContext uriRoutingContext = (UriRoutingContext) uriInfo;
List<UriTemplate> templates = uriRoutingContext.getMatchedTemplates();
String path = "";
for (UriTemplate uriTemplate : templates) {
String template = (String) normalizedTemplate.get(uriTemplate);
path = template + path;
}
operationName = String.format("%s:%s", containerRequest.getMethod(), path);
}
}
} catch (Exception e) {
log.error("Unable to get operation name", e);
}
return operationName;
}
use of org.glassfish.jersey.uri.UriTemplate in project micrometer by micrometer-metrics.
the class DefaultJerseyTagsProviderTest method event.
private static RequestEvent event(Integer status, Exception exception, String baseUri, String... uriTemplateStrings) {
Builder builder = new RequestEventImpl.Builder();
ContainerRequest containerRequest = mock(ContainerRequest.class);
when(containerRequest.getMethod()).thenReturn("GET");
builder.setContainerRequest(containerRequest);
ContainerResponse containerResponse = mock(ContainerResponse.class);
when(containerResponse.getStatus()).thenReturn(status);
builder.setContainerResponse(containerResponse);
builder.setException(exception, null);
ExtendedUriInfo extendedUriInfo = mock(ExtendedUriInfo.class);
when(extendedUriInfo.getBaseUri()).thenReturn(URI.create("http://localhost:8080" + (baseUri == null ? "/" : baseUri)));
List<UriTemplate> uriTemplates = uriTemplateStrings == null ? Collections.emptyList() : Arrays.stream(uriTemplateStrings).map(uri -> new UriTemplate(uri)).collect(Collectors.toList());
// UriTemplate are returned in reverse order
Collections.reverse(uriTemplates);
when(extendedUriInfo.getMatchedTemplates()).thenReturn(uriTemplates);
builder.setExtendedUriInfo(extendedUriInfo);
return builder.build(Type.FINISHED);
}
use of org.glassfish.jersey.uri.UriTemplate in project micrometer by micrometer-metrics.
the class DefaultJerseyTagsProvider method templatedUri.
private static String templatedUri(RequestEvent event) {
final ExtendedUriInfo uriInfo = event.getUriInfo();
final List<UriTemplate> matchedTemplates = new ArrayList<>(uriInfo.getMatchedTemplates());
if (matchedTemplates.size() > 1) {
Collections.reverse(matchedTemplates);
}
final StringBuilder sb = new StringBuilder();
sb.append(uriInfo.getBaseUri().getPath());
for (UriTemplate uriTemplate : matchedTemplates) {
sb.append(uriTemplate.getTemplate());
}
return sb.toString().replaceAll("//+", "/");
}
Aggregations