Search in sources :

Example 1 with ExtendedUriInfo

use of org.glassfish.jersey.server.ExtendedUriInfo in project jersey by jersey.

the class ServerScopeProvider method getFilteringScopes.

@Override
public Set<String> getFilteringScopes(final Annotation[] entityAnnotations, final boolean defaultIfNotFound) {
    Set<String> filteringScope = super.getFilteringScopes(entityAnnotations, false);
    if (filteringScope.isEmpty()) {
        final ExtendedUriInfo uriInfo = uriInfoProvider.get();
        final String path = uriInfo.getPath();
        if (uriToContexts.containsKey(path)) {
            return uriToContexts.get(path);
        }
        for (final ResourceMethod method : ServerScopeProvider.getMatchedMethods(uriInfo)) {
            final Invocable invocable = method.getInvocable();
            mergeFilteringScopes(filteringScope, getFilteringScopes(invocable.getHandlingMethod(), invocable.getHandler().getHandlerClass()));
            if (!filteringScope.isEmpty()) {
                uriToContexts.putIfAbsent(path, filteringScope);
                return filteringScope;
            }
        }
    }
    // Use default scope if not in other scope.
    return returnFilteringScopes(filteringScope, defaultIfNotFound);
}
Also used : Invocable(org.glassfish.jersey.server.model.Invocable) ResourceMethod(org.glassfish.jersey.server.model.ResourceMethod) ExtendedUriInfo(org.glassfish.jersey.server.ExtendedUriInfo)

Example 2 with ExtendedUriInfo

use of org.glassfish.jersey.server.ExtendedUriInfo in project jersey by jersey.

the class AbstractErrorTemplateMapper method getErrorTemplate.

/**
     * Get an {@link ErrorTemplate} annotation from resource method / class the throwable was raised from.
     *
     * @return an error template annotation or {@code null} if the method is not annotated.
     */
private ErrorTemplate getErrorTemplate() {
    final ExtendedUriInfo uriInfo = uriInfoProvider.get();
    final ResourceMethod matchedResourceMethod = uriInfo.getMatchedResourceMethod();
    if (matchedResourceMethod != null) {
        final Invocable invocable = matchedResourceMethod.getInvocable();
        ErrorTemplate errorTemplate = invocable.getHandlingMethod().getAnnotation(ErrorTemplate.class);
        if (errorTemplate == null) {
            Class<?> handlerClass = invocable.getHandler().getHandlerClass();
            if (invocable.isInflector() && TemplateInflector.class.isAssignableFrom(invocable.getHandler().getHandlerClass())) {
                handlerClass = ((TemplateInflector) invocable.getHandler().getInstance(null)).getModelClass();
            }
            errorTemplate = handlerClass.getAnnotation(ErrorTemplate.class);
        }
        return errorTemplate;
    }
    return null;
}
Also used : Invocable(org.glassfish.jersey.server.model.Invocable) ErrorTemplate(org.glassfish.jersey.server.mvc.ErrorTemplate) TemplateInflector(org.glassfish.jersey.server.mvc.internal.TemplateInflector) ResourceMethod(org.glassfish.jersey.server.model.ResourceMethod) ExtendedUriInfo(org.glassfish.jersey.server.ExtendedUriInfo)

Aggregations

ExtendedUriInfo (org.glassfish.jersey.server.ExtendedUriInfo)2 Invocable (org.glassfish.jersey.server.model.Invocable)2 ResourceMethod (org.glassfish.jersey.server.model.ResourceMethod)2 ErrorTemplate (org.glassfish.jersey.server.mvc.ErrorTemplate)1 TemplateInflector (org.glassfish.jersey.server.mvc.internal.TemplateInflector)1