private ResourceStatisticsImpl.Builder getOrCreateResourceBuilder(final ResourceMethod resourceMethod) { final Class<?> clazz = resourceMethod.getInvocable().getHandler().getHandlerClass(); ResourceStatisticsImpl.Builder builder = resourceClassStatistics.get(clazz); if (builder == null) { builder = new ResourceStatisticsImpl.Builder(methodFactory); resourceClassStatistics.put(clazz, builder); } return builder; }
private ResourceStatisticsImpl.Builder getOrCreateResourceBuilder(final ResourceMethod resourceMethod) { final Class<?> clazz = resourceMethod.getInvocable().getHandler().getHandlerClass(); ResourceStatisticsImpl.Builder builder = resourceClassStatistics.get(clazz); if (builder == null) { builder = new ResourceStatisticsImpl.Builder(methodFactory); resourceClassStatistics.put(clazz, builder); } return builder; }
private void checkUnexpectedAnnotations(ResourceMethod resourceMethod) { Invocable invocable = resourceMethod.getInvocable(); for (Annotation annotation : invocable.getHandlingMethod().getDeclaredAnnotations()) { if (PARAM_ANNOTATION_SET.contains(annotation.annotationType())) { Errors.fatal(resourceMethod, LocalizationMessages.METHOD_UNEXPECTED_ANNOTATION( invocable.getHandlingMethod().getName(), invocable.getHandler().getHandlerClass().getName(), annotation.annotationType().getName()) ); } } }
private void checkUnexpectedAnnotations(ResourceMethod resourceMethod) { Invocable invocable = resourceMethod.getInvocable(); for (Annotation annotation : invocable.getHandlingMethod().getDeclaredAnnotations()) { if (PARAM_ANNOTATION_SET.contains(annotation.annotationType())) { Errors.fatal(resourceMethod, LocalizationMessages.METHOD_UNEXPECTED_ANNOTATION( invocable.getHandlingMethod().getName(), invocable.getHandler().getHandlerClass().getName(), annotation.annotationType().getName()) ); } } }
@Override public Continuation apply(final RequestProcessingContext context) { final RoutingContext routingContext = context.routingContext(); final Object storedResource = routingContext.peekMatchedResource(); if (storedResource == null || !storedResource.getClass().equals(methodHandler.getHandlerClass())) { Object handlerInstance = methodHandler.getInstance(context.injectionManager()); routingContext.pushMatchedResource(handlerInstance); } return Continuation.of(context, next); } }
@Override public Continuation apply(final RequestProcessingContext context) { final RoutingContext routingContext = context.routingContext(); final Object storedResource = routingContext.peekMatchedResource(); if (storedResource == null || !storedResource.getClass().equals(methodHandler.getHandlerClass())) { Object handlerInstance = methodHandler.getInstance(context.injectionManager()); routingContext.pushMatchedResource(handlerInstance); } return Continuation.of(context, next); } }
@Override public void visitInvocable(final Invocable invocable) { // TODO: check invocable. Class resClass = invocable.getHandler().getHandlerClass(); if (resClass != null && !checkedClasses.contains(resClass)) { checkedClasses.add(resClass); final boolean provider = Providers.isProvider(resClass); int counter = 0; for (Annotation annotation : resClass.getAnnotations()) { if (SCOPE_ANNOTATIONS.contains(annotation.annotationType())) { counter++; } } if (counter == 0 && provider) { Errors.warning(resClass, LocalizationMessages.RESOURCE_IMPLEMENTS_PROVIDER(resClass, Providers.getProviderContracts(resClass))); } else if (counter > 1) { Errors.fatal(resClass, LocalizationMessages.RESOURCE_MULTIPLE_SCOPE_ANNOTATIONS(resClass)); } } }
@Override public void visitInvocable(final Invocable invocable) { // TODO: check invocable. Class resClass = invocable.getHandler().getHandlerClass(); if (resClass != null && !checkedClasses.contains(resClass)) { checkedClasses.add(resClass); final boolean provider = Providers.isProvider(resClass); int counter = 0; for (Annotation annotation : resClass.getAnnotations()) { if (SCOPE_ANNOTATIONS.contains(annotation.annotationType())) { counter++; } } if (counter == 0 && provider) { Errors.warning(resClass, LocalizationMessages.RESOURCE_IMPLEMENTS_PROVIDER(resClass, Providers.getProviderContracts(resClass))); } else if (counter > 1) { Errors.fatal(resClass, LocalizationMessages.RESOURCE_MULTIPLE_SCOPE_ANNOTATIONS(resClass)); } } }
@Override public InvocationHandler create(Invocable method) { final Class<?> resourceClass = method.getHandler().getHandlerClass(); if (resourceClass == null || !isEjbComponent(resourceClass)) { return null; } final Method handlingMethod = method.getDefinitionMethod(); for (Class iFace : remoteAndLocalIfaces(resourceClass)) { try { final Method iFaceMethod = iFace.getDeclaredMethod(handlingMethod.getName(), handlingMethod.getParameterTypes()); if (iFaceMethod != null) { return new InvocationHandler() { @Override public Object invoke(Object target, Method ignored, Object[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException { return iFaceMethod.invoke(target, args); } }; } } catch (NoSuchMethodException | SecurityException ex) { logLookupException(handlingMethod, resourceClass, iFace, ex); } } return null; }
/** * 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; }
public String getLinkTemplate(ResourceMappingContext rmc) { String template = null; ResourceMappingContext.Mapping map = rmc.getMapping(resource.getInvocable().getHandler().getHandlerClass()); if (map != null) { template = map.getTemplate().getTemplate(); } else { Path path = resource.getInvocable().getHandler().getHandlerClass().getAnnotation(Path.class); template = path == null ? "" : path.value();
@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); }
this.definitionMethod = definitionMethod; this.handlingMethod = handlingMethod == null ? ReflectionHelper .findOverridingMethodOnClass(handler.getHandlerClass(), definitionMethod) : handlingMethod; final Class<?> handlerClass = handler.getHandlerClass(); final Class<?> definitionClass = definitionMethod.getDeclaringClass(); final ClassTypePair handlingCtPair = ReflectionHelper.resolveGenericType(
this.definitionMethod = definitionMethod; this.handlingMethod = handlingMethod == null ? ReflectionHelper .findOverridingMethodOnClass(handler.getHandlerClass(), definitionMethod) : handlingMethod; final Class<?> handlerClass = handler.getHandlerClass(); final Class<?> definitionClass = definitionMethod.getDeclaringClass(); final ClassTypePair handlingCtPair = ReflectionHelper.resolveGenericType(
handlerClasses.add(methodHandler.getHandlerClass()); } else { handlerInstances.add(methodHandler.getHandlerInstance());
/** * Invoked prior to request invocation during {@link RequestEventListener#onEvent(RequestEvent)} * where the event type is {@link RequestEvent.Type#REQUEST_MATCHED} * * <p>Adds the tags {@link #RESOURCE_CLASS} and {@link #RESOURCE_METHOD}. Override or use {@link #NOOP} * to change this behavior. */ protected void requestMatched(RequestEvent event, SpanCustomizer customizer) { Invocable i = event.getContainerRequest().getUriInfo().getMatchedResourceMethod().getInvocable(); customizer.tag(RESOURCE_CLASS, i.getHandler().getHandlerClass().getSimpleName()); customizer.tag(RESOURCE_METHOD, i.getHandlingMethod().getName()); }
handlerClasses.add(methodHandler.getHandlerClass()); } else { handlerInstances.add(methodHandler.getHandlerInstance());
final Class<?> handler = method.getInvocable().getHandler().getHandlerClass(); switch (method.getType()) { case RESOURCE_METHOD:
/** * Create a builder from an existing resource method model. * * @param parent parent resource model builder. * @param originalMethod existing resource method model to create the builder from. */ /* package */ Builder(final Resource.Builder parent, ResourceMethod originalMethod) { this.parent = parent; this.consumedTypes = new LinkedHashSet<>(originalMethod.getConsumedTypes()); this.producedTypes = new LinkedHashSet<>(originalMethod.getProducedTypes()); this.suspended = originalMethod.isSuspendDeclared(); this.suspendTimeout = originalMethod.getSuspendTimeout(); this.suspendTimeoutUnit = originalMethod.getSuspendTimeoutUnit(); this.handlerParameters = new LinkedHashSet<>(originalMethod.getInvocable().getHandler().getParameters()); this.nameBindings = originalMethod.getNameBindings(); this.httpMethod = originalMethod.getHttpMethod(); this.managedAsync = originalMethod.isManagedAsyncDeclared(); Invocable invocable = originalMethod.getInvocable(); this.handlingMethod = invocable.getHandlingMethod(); this.encodedParams = false; this.routingResponseType = invocable.getRoutingResponseType(); this.extended = originalMethod.isExtended(); Method handlerMethod = invocable.getDefinitionMethod(); MethodHandler handler = invocable.getHandler(); if (handler.isClassBased()) { handledBy(handler.getHandlerClass(), handlerMethod); } else { handledBy(handler.getHandlerInstance(), handlerMethod); } }
/** * Create a builder from an existing resource method model. * * @param parent parent resource model builder. * @param originalMethod existing resource method model to create the builder from. */ /* package */ Builder(final Resource.Builder parent, ResourceMethod originalMethod) { this.parent = parent; this.consumedTypes = new LinkedHashSet<>(originalMethod.getConsumedTypes()); this.producedTypes = new LinkedHashSet<>(originalMethod.getProducedTypes()); this.suspended = originalMethod.isSuspendDeclared(); this.suspendTimeout = originalMethod.getSuspendTimeout(); this.suspendTimeoutUnit = originalMethod.getSuspendTimeoutUnit(); this.handlerParameters = new LinkedHashSet<>(originalMethod.getInvocable().getHandler().getParameters()); this.nameBindings = originalMethod.getNameBindings(); this.httpMethod = originalMethod.getHttpMethod(); this.managedAsync = originalMethod.isManagedAsyncDeclared(); Invocable invocable = originalMethod.getInvocable(); this.handlingMethod = invocable.getHandlingMethod(); this.encodedParams = false; this.routingResponseType = invocable.getRoutingResponseType(); this.extended = originalMethod.isExtended(); Method handlerMethod = invocable.getDefinitionMethod(); MethodHandler handler = invocable.getHandler(); if (handler.isClassBased()) { handledBy(handler.getHandlerClass(), handlerMethod); } else { handledBy(handler.getHandlerInstance(), handlerMethod); } }