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()) ); } } }
/** * 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; }
@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; }
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); }
private Request generateRequest(org.glassfish.jersey.server.model.Resource parentResource, final org.glassfish.jersey.server.model.ResourceMethod resourceMethod, Map<String, Param> wadlResourceParams) { try { final List<Parameter> requestParams = new LinkedList<>(resourceMethod.getInvocable().getParameters()); // Adding handler instance parameters to the list of potential request parameters. requestParams.addAll(resourceMethod.getInvocable().getHandler().getParameters()); if (requestParams.isEmpty()) { return null; } Request wadlRequest = _wadlGenerator.createRequest(parentResource, resourceMethod); processRequestParameters(parentResource, resourceMethod, wadlResourceParams, requestParams, wadlRequest); if (wadlRequest.getRepresentation().size() + wadlRequest.getParam().size() == 0) { return null; } else { return wadlRequest; } } catch (Exception e) { throw new ProcessingException(LocalizationMessages.ERROR_WADL_BUILDER_GENERATION_REQUEST( resourceMethod, parentResource), e); } }
private Request generateRequest(org.glassfish.jersey.server.model.Resource parentResource, final org.glassfish.jersey.server.model.ResourceMethod resourceMethod, Map<String, Param> wadlResourceParams) { try { final List<Parameter> requestParams = new LinkedList<>(resourceMethod.getInvocable().getParameters()); // Adding handler instance parameters to the list of potential request parameters. requestParams.addAll(resourceMethod.getInvocable().getHandler().getParameters()); if (requestParams.isEmpty()) { return null; } Request wadlRequest = _wadlGenerator.createRequest(parentResource, resourceMethod); processRequestParameters(parentResource, resourceMethod, wadlResourceParams, requestParams, wadlRequest); if (wadlRequest.getRepresentation().size() + wadlRequest.getParam().size() == 0) { return null; } else { return wadlRequest; } } catch (Exception e) { throw new ProcessingException(LocalizationMessages.ERROR_WADL_BUILDER_GENERATION_REQUEST( resourceMethod, parentResource), e); } }
/** * 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()); }
final MethodHandler methodHandler = methodData.getInvocable().getHandler(); if (methodHandler.isClassBased()) { handlerClasses.add(methodHandler.getHandlerClass());
final MethodHandler methodHandler = methodData.getInvocable().getHandler(); if (methodHandler.isClassBased()) { handlerClasses.add(methodHandler.getHandlerClass());
private Router createMethodRouter(final ResourceMethod resourceMethod) { Router methodAcceptor = null; switch (resourceMethod.getType()) { case RESOURCE_METHOD: case SUB_RESOURCE_METHOD: methodAcceptor = Routers.endpoint(createInflector(resourceMethod)); break; case SUB_RESOURCE_LOCATOR: methodAcceptor = locatorBuilder.get().getRouter(resourceMethod); break; } return new PushMethodHandlerRouter(resourceMethod.getInvocable().getHandler(), methodAcceptor); }
private Router createMethodRouter(final ResourceMethod resourceMethod) { Router methodAcceptor = null; switch (resourceMethod.getType()) { case RESOURCE_METHOD: case SUB_RESOURCE_METHOD: methodAcceptor = Routers.endpoint(createInflector(resourceMethod)); break; case SUB_RESOURCE_LOCATOR: methodAcceptor = locatorBuilder.get().getRouter(resourceMethod); break; } return new PushMethodHandlerRouter(resourceMethod.getInvocable().getHandler(), methodAcceptor); }
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); } }