private boolean isReadable(final RequestSpecificConsumesProducesAcceptor candidate) { final Invocable invocable = candidate.methodRouting.method.getInvocable(); final Method handlingMethod = invocable.getHandlingMethod(); final Parameter entityParam = getEntityParam(invocable); if (entityParam == null) { return true; } else { final Class<?> entityType = entityParam.getRawType(); for (final ReaderModel model : workers.getReaderModelsForType(entityType)) { if (model.isReadable( entityType, entityParam.getType(), handlingMethod.getDeclaredAnnotations(), candidate.consumes.combinedType)) { return true; } } } return false; }
private static Optional<UnitOfWork> registerUnitOfWorkAnnotations(ResourceMethod method) { UnitOfWork annotation = method.getInvocable().getDefinitionMethod().getAnnotation(UnitOfWork.class); if (annotation == null) { annotation = method.getInvocable().getHandlingMethod().getAnnotation(UnitOfWork.class); } return Optional.ofNullable(annotation); } }
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 List<MediaType> getEffectiveOutputTypes(final ResourceMethod resourceMethod) { if (!resourceMethod.getProducedTypes().isEmpty()) { return resourceMethod.getProducedTypes(); } List<MediaType> result = new LinkedList<>(); if (workers != null) { final Invocable invocable = resourceMethod.getInvocable(); result.addAll(workers.getMessageBodyWriterMediaTypes( invocable.getRawResponseType(), invocable.getResponseType(), invocable.getHandlingMethod().getAnnotations())); } return result.isEmpty() ? StarTypeList : result; }
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()) ); } } }
if ("GET".equals(method.getHttpMethod())) { final long eventSinkCount = invocable.getParameters() .stream() .filter(parameter -> SseEventSink.class.equals(parameter.getRawType())) .count(); Errors.warning(method, LocalizationMessages.MULTIPLE_EVENT_SINK_INJECTION(invocable.getHandlingMethod())); if (void.class == invocable.getHandlingMethod().getReturnType() && !method.isSuspendDeclared() && !isSse) { Errors.hint(method, LocalizationMessages.GET_RETURNS_VOID(invocable.getHandlingMethod())); if (invocable.requiresEntity() && !invocable.isInflector()) { Errors.warning(method, LocalizationMessages.GET_CONSUMES_ENTITY(invocable.getHandlingMethod())); for (Parameter p : invocable.getParameters()) { if (p.isAnnotationPresent(FormParam.class)) { Errors.fatal(method, LocalizationMessages.GET_CONSUMES_FORM_PARAM(invocable.getHandlingMethod())); break; if (isSse && void.class != invocable.getHandlingMethod().getReturnType()) { Errors.fatal(method, LocalizationMessages.EVENT_SINK_RETURNS_TYPE(invocable.getHandlingMethod())); for (Annotation a : invocable.getHandlingMethod().getDeclaredAnnotations()) { if (null != a.annotationType().getAnnotation(HttpMethod.class)) { httpMethodAnnotations.add(a.toString()); Errors.fatal(method, LocalizationMessages.MULTIPLE_HTTP_METHOD_DESIGNATORS(invocable.getHandlingMethod(), httpMethodAnnotations.toString()));
private List<Response> generateResponses(org.glassfish.jersey.server.model.Resource r, final ResourceMethod m) { try { if (m.getInvocable().getRawResponseType() == void.class) { return null; } return _wadlGenerator.createResponses(r, m); } catch (Exception e) { throw new ProcessingException(LocalizationMessages.ERROR_WADL_BUILDER_GENERATION_RESPONSE(m, r), e); } } }
try { org.glassfish.jersey.server.model.Resource.Builder builder = org.glassfish.jersey.server.model.Resource .builder(locator.getInvocable().getRawResponseType()); if (builder == null) { return null; if (locator.isExtended()) { wadlSubResource.getAny().add(WadlApplicationContextImpl.EXTENDED_ELEMENT); for (Parameter param : locator.getInvocable().getParameters()) { Param wadlParam = generateParam(resource, locator, param); if (wadlParam != null && wadlParam.getStyle() == ParamStyle.TEMPLATE) { wadlSubResource.getParam().add(wadlParam); throw new ProcessingException(LocalizationMessages.ERROR_WADL_BUILDER_GENERATION_RESOURCE_LOCATOR(locator, resource), e); throw new ProcessingException(LocalizationMessages.ERROR_WADL_BUILDER_GENERATION_RESOURCE_PATH(resource, path), e);
private Object getResource(final RequestProcessingContext context) { final Object resource = context.routingContext().peekMatchedResource(); final Method handlingMethod = locatorModel.getInvocable().getHandlingMethod(); final Object[] parameterValues = ParameterValueHelper.getParameterValues(valueProviders, context.request()); return handlingMethod.invoke(resource, parameterValues); } catch (IllegalAccessException | IllegalArgumentException | UndeclaredThrowableException ex) { throw new ProcessingException(LocalizationMessages.ERROR_RESOURCE_JAVA_METHOD_INVOCATION(), ex); } catch (final InvocationTargetException ex) { final Throwable cause = ex.getCause(); throw new ProcessingException(t);
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 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())); } } } }
/** * @param r Jersey resource component. * @param m resource method. * @param p method parameter. * @return the enhanced {@link Param}. * @see org.glassfish.jersey.server.wadl.WadlGenerator#createParam(org.glassfish.jersey.server.model.Resource, * org.glassfish.jersey.server.model.ResourceMethod, org.glassfish.jersey.server.model.Parameter) */ public Param createParam(final org.glassfish.jersey.server.model.Resource r, final org.glassfish.jersey.server.model.ResourceMethod m, final Parameter p) { final Param result = delegate.createParam(r, m, p); if (result != null) { final ParamDocType paramDoc = resourceDoc.getParamDoc(m.getInvocable().getDefinitionMethod().getDeclaringClass(), m.getInvocable().getDefinitionMethod(), p); if (paramDoc != null && !isEmpty(paramDoc.getCommentText())) { final Doc doc = new Doc(); doc.getContent().add(paramDoc.getCommentText()); result.getDoc().add(doc); } } return result; }
final ResponseDocType responseDoc = resourceDoc.getResponse(m.getInvocable().getDefinitionMethod().getDeclaringClass(), m.getInvocable().getDefinitionMethod()); List<Response> responses = new ArrayList<Response>(); if (responseDoc != null && responseDoc.hasRepresentations()) { final Param param = new Param(); param.setName(wadlParamType.getName()); param.setStyle(ParamStyle.fromValue(wadlParamType.getStyle())); param.setType(wadlParamType.getType()); addDoc(param.getDoc(), wadlParamType.getDoc());
@Override public String toString() { return method.getInvocable().getHandlingMethod().toString(); } }
private void visitSubResourceLocator(ResourceMethod locator) { checkParameters(locator); checkValueProviders(locator); final Invocable invocable = locator.getInvocable(); if (void.class == invocable.getRawResponseType()) { Errors.fatal(locator, LocalizationMessages.SUBRES_LOC_RETURNS_VOID(invocable.getHandlingMethod())); } // Prevent PARAM_ANNOTATION_SET annotations on a resource locator if (invocable.getHandlingMethod().getAnnotation(Path.class) != null) { checkUnexpectedAnnotations(locator); } }
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; } } }
/** * The term 'definition method' used by the Jersey model means the method that contains JAX-RS/Jersey annotations. */ private Method getDefinitionMethod(ContainerRequestContext requestContext) { if (!(requestContext.getUriInfo() instanceof ExtendedUriInfo)) { throw new IllegalStateException("Could not get Extended Uri Info. Incompatible version of Jersey?"); } ExtendedUriInfo uriInfo = (ExtendedUriInfo) requestContext.getUriInfo(); ResourceMethod matchedResourceMethod = uriInfo.getMatchedResourceMethod(); Invocable invocable = matchedResourceMethod.getInvocable(); return invocable.getDefinitionMethod(); }
final Invocable invocable = resourceMethod.getInvocable(); final Class<?> responseEntityClass = entityClass == null ? invocable.getRawRoutingResponseType() : entityClass; final Method handlingMethod = invocable.getHandlingMethod(); final List<MediaType> methodProducesTypes = !resourceMethod.getProducedTypes().isEmpty() ? resourceMethod.getProducedTypes() : Collections.singletonList(MediaType.WILDCARD_TYPE); final List<WriterModel> writersForEntityType = workers.getWritersModelsForType(responseEntityClass);
final Invocable invocable = method.getInvocable(); this.dispatcher = dispatcherProvider.create(invocable, invocationHandlerProvider.create(invocable), validator); this.resourceMethod = invocable.getHandlingMethod(); this.resourceClass = invocable.getHandler().getHandlerClass(); this.methodAnnotations = invocable.getHandlingMethod().getDeclaredAnnotations(); this.invocableResponseType = invocable.getResponseType(); this.canUseInvocableResponseType = invocableResponseType != null && Void.TYPE != invocableResponseType
/** * @param ar abstract resource * @param arm abstract resource method * @param mt media type * @return respresentation type * @see org.glassfish.jersey.server.wadl.WadlGenerator#createRequestRepresentation(org.glassfish.jersey.server.model.Resource, * org.glassfish.jersey.server.model.ResourceMethod, javax.ws.rs.core.MediaType) */ public Representation createRequestRepresentation( final org.glassfish.jersey.server.model.Resource ar, final org.glassfish.jersey.server.model.ResourceMethod arm, final MediaType mt) { final Representation rt = wadlGeneratorDelegate.createRequestRepresentation(ar, arm, mt); for (final Parameter p : arm.getInvocable().getParameters()) { if (p.getSource() == Parameter.Source.ENTITY) { nameCallbacks.add(new TypeCallbackPair( new GenericType(p.getType()), new NameCallbackSetter() { @Override public void setName(final QName name) { rt.setElement(name); } })); } } return rt; }