@Override public boolean requiresEntity() { for (Parameter p : getParameters()) { if (Parameter.Source.ENTITY == p.getSource()) { return true; } } return false; }
@Override public boolean requiresEntity() { for (Parameter p : getParameters()) { if (Parameter.Source.ENTITY == p.getSource()) { return true; } } return false; }
private boolean isSseInjected(final Invocable invocable) { return invocable.getParameters().stream().anyMatch(parameter -> SseEventSink.class.equals(parameter.getRawType())); }
private boolean isSseInjected(final Invocable invocable) { return invocable.getParameters().stream().anyMatch(parameter -> SseEventSink.class.equals(parameter.getRawType())); }
private Parameter getEntityParam(final Invocable invocable) { for (final Parameter parameter : invocable.getParameters()) { if (parameter.getSource() == Parameter.Source.ENTITY && !ContainerRequestContext.class.isAssignableFrom(parameter.getRawType())) { // there's at most one entity parameter return parameter; } } return null; }
private Parameter getEntityParam(final Invocable invocable) { for (final Parameter parameter : invocable.getParameters()) { if (parameter.getSource() == Parameter.Source.ENTITY && !ContainerRequestContext.class.isAssignableFrom(parameter.getRawType())) { // there's at most one entity parameter return parameter; } } return null; }
@Override public ResourceMethodDispatcher create(final Invocable resourceMethod, final InvocationHandler handler, final ConfiguredValidator validator) { if (resourceMethod.getHandlingMethod().getReturnType() != void.class || !resourceMethod.getParameters().isEmpty()) { return null; } return resourceContext.initResource(new VoidToVoidDispatcher(resourceMethod, handler, validator)); } }
for (Parameter parameter : invocable.getParameters()) { if (parameter.isAnnotationPresent(Validated.class)) { groups.add(parameter.getAnnotation(Validated.class).value());
/** * Determines if constraint violation occurred in the request entity. If it did, return a client * friendly string representation of where the error occurred (eg. "patient.name") */ public static Optional<String> isRequestEntity(ConstraintViolation<?> violation, Invocable invocable) { final Collection<Path.Node> propertyPath = Lists.of(violation.getPropertyPath()); final Path.Node parent = propertyPath.stream() .skip(1L) .findFirst() .orElse(null); if (parent == null) { return Optional.empty(); } final List<Parameter> parameters = invocable.getParameters(); if (parent.getKind() == ElementKind.PARAMETER) { final Parameter param = parameters.get(parent.as(Path.ParameterNode.class).getParameterIndex()); if (param.getSource().equals(Parameter.Source.UNKNOWN)) { final String path = propertyPath.stream() .skip(2L) .map(Path.Node::toString) .collect(Collectors.joining(".")); return Optional.of(path); } } return Optional.empty(); }
@Override public ResourceMethodDispatcher create(final Invocable resourceMethod, final InvocationHandler handler, final ConfiguredValidator validator) { if (resourceMethod.getHandlingMethod().getReturnType() != void.class || !resourceMethod.getParameters().isEmpty()) { return null; } return resourceContext.initResource(new VoidToVoidDispatcher(resourceMethod, handler, validator)); } }
private void fillInputTypesFromWorkers(final Set<MediaType> effectiveInputTypes, final Invocable invocableMethod) { for (Parameter p : invocableMethod.getParameters()) { if (p.getSource() == Parameter.Source.ENTITY) { effectiveInputTypes.addAll(workers.getMessageBodyReaderMediaTypesByType(p.getRawType())); // there's at most one entity parameter break; } } }
private void fillInputTypesFromWorkers(final Set<MediaType> effectiveInputTypes, final Invocable invocableMethod) { for (Parameter p : invocableMethod.getParameters()) { if (p.getSource() == Parameter.Source.ENTITY) { effectiveInputTypes.addAll(workers.getMessageBodyReaderMediaTypesByType(p.getRawType())); // there's at most one entity parameter break; } } }
/** * Given a set of constraint violations and a Jersey {@link Invocable} where the constraint * occurred, determine the HTTP Status code for the response. A return value violation is an * internal server error, an invalid request body is unprocessable entity, and any params that * are invalid means a bad request */ public static <T extends ConstraintViolation<?>> int determineStatus(Set<T> violations, Invocable invocable) { if (violations.size() > 0) { final ConstraintViolation<?> violation = violations.iterator().next(); for (Path.Node node : violation.getPropertyPath()) { switch (node.getKind()) { case RETURN_VALUE: return 500; case PARAMETER: // Now determine if the parameter is the request entity final int index = node.as(Path.ParameterNode.class).getParameterIndex(); final Parameter parameter = invocable.getParameters().get(index); return parameter.getSource().equals(Parameter.Source.UNKNOWN) ? 422 : 400; default: continue; } } } // This shouldn't hit, but if it does, we'll return a unprocessable entity return 422; } }
/** * Gets a method parameter (or a parameter field) name, if the violation raised in it. */ private static Optional<String> getMemberName(ConstraintViolation<?> violation, Invocable invocable) { final List<Path.Node> propertyPath = Lists.of(violation.getPropertyPath()); final int size = propertyPath.size(); if (size < 2) { return Optional.empty(); } final Path.Node parent = propertyPath.get(size - 2); final Path.Node member = propertyPath.get(size - 1); switch (parent.getKind()) { case PARAMETER: // Constraint violation most likely failed with a BeanParam final List<Parameter> parameters = invocable.getParameters(); final Parameter param = parameters.get(parent.as(Path.ParameterNode.class).getParameterIndex()); // Extract the failing *Param annotation inside the Bean Param if (param.getSource().equals(Parameter.Source.BEAN_PARAM)) { final Field field = FieldUtils.getField(param.getRawType(), member.getName(), true); return JerseyParameterNameProvider.getParameterNameFromAnnotations(field.getDeclaredAnnotations()); } break; case METHOD: return Optional.of(member.getName()); default: break; } return Optional.empty(); }
private List<MediaType> getEffectiveInputTypes(final ResourceMethod resourceMethod) { if (!resourceMethod.getConsumedTypes().isEmpty()) { return resourceMethod.getConsumedTypes(); } List<MediaType> result = new LinkedList<>(); if (workers != null) { for (Parameter p : resourceMethod.getInvocable().getParameters()) { if (p.getSource() == Parameter.Source.ENTITY) { result.addAll(workers.getMessageBodyReaderMediaTypes( p.getRawType(), p.getType(), p.getDeclaredAnnotations())); } } } return result.isEmpty() ? StarTypeList : result; }
private List<MediaType> getEffectiveInputTypes(final ResourceMethod resourceMethod) { if (!resourceMethod.getConsumedTypes().isEmpty()) { return resourceMethod.getConsumedTypes(); } List<MediaType> result = new LinkedList<>(); if (workers != null) { for (Parameter p : resourceMethod.getInvocable().getParameters()) { if (p.getSource() == Parameter.Source.ENTITY) { result.addAll(workers.getMessageBodyReaderMediaTypes( p.getRawType(), p.getType(), p.getDeclaredAnnotations())); } } } return result.isEmpty() ? StarTypeList : result; }
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); } }
private void checkParameters(ResourceMethod method) { final Invocable invocable = method.getInvocable(); final Method handlingMethod = invocable.getHandlingMethod(); int paramCount = 0; int nonAnnotatedParameters = 0; for (Parameter p : invocable.getParameters()) { validateParameter(p, handlingMethod, handlingMethod.toGenericString(), Integer.toString(++paramCount), false); if (method.getType() == ResourceMethod.JaxrsType.SUB_RESOURCE_LOCATOR && Parameter.Source.ENTITY == p.getSource()) { Errors.fatal(method, LocalizationMessages.SUBRES_LOC_HAS_ENTITY_PARAM(invocable.getHandlingMethod())); } else if (p.getAnnotations().length == 0) { nonAnnotatedParameters++; if (nonAnnotatedParameters > 1) { Errors.fatal(method, LocalizationMessages.AMBIGUOUS_NON_ANNOTATED_PARAMETER(invocable.getHandlingMethod(), invocable.getHandlingMethod().getDeclaringClass())); } } } }
private void checkParameters(ResourceMethod method) { final Invocable invocable = method.getInvocable(); final Method handlingMethod = invocable.getHandlingMethod(); int paramCount = 0; int nonAnnotatedParameters = 0; for (Parameter p : invocable.getParameters()) { validateParameter(p, handlingMethod, handlingMethod.toGenericString(), Integer.toString(++paramCount), false); if (method.getType() == ResourceMethod.JaxrsType.SUB_RESOURCE_LOCATOR && Parameter.Source.ENTITY == p.getSource()) { Errors.fatal(method, LocalizationMessages.SUBRES_LOC_HAS_ENTITY_PARAM(invocable.getHandlingMethod())); } else if (p.getAnnotations().length == 0) { nonAnnotatedParameters++; if (nonAnnotatedParameters > 1) { Errors.fatal(method, LocalizationMessages.AMBIGUOUS_NON_ANNOTATED_PARAMETER(invocable.getHandlingMethod(), invocable.getHandlingMethod().getDeclaringClass())); } } } }