private boolean hasEmptyProducibleMediaTypeSet(final ResourceMethod method) { return method.getProducedTypes().isEmpty(); }
private boolean hasEmptyProducibleMediaTypeSet(final ResourceMethod method) { return method.getProducedTypes().isEmpty(); }
private static boolean usePreSelectedMediaType(final RequestSpecificConsumesProducesAcceptor selectedMethod, final List<AcceptableMediaType> acceptableMediaTypes) { // Resource method is annotated with @Produces and this annotation contains only one MediaType. if (!selectedMethod.producesFromProviders && selectedMethod.methodRouting.method.getProducedTypes().size() == 1) { return true; } // There is only one (non-wildcard) acceptable media type - at this point the pre-selected method has to be chosen so // there are compatible writers (not necessarily writeable ones). return acceptableMediaTypes.size() == 1 && !MediaTypes.isWildcard(acceptableMediaTypes.get(0)); }
private static boolean usePreSelectedMediaType(final RequestSpecificConsumesProducesAcceptor selectedMethod, final List<AcceptableMediaType> acceptableMediaTypes) { // Resource method is annotated with @Produces and this annotation contains only one MediaType. if (!selectedMethod.producesFromProviders && selectedMethod.methodRouting.method.getProducedTypes().size() == 1) { return true; } // There is only one (non-wildcard) acceptable media type - at this point the pre-selected method has to be chosen so // there are compatible writers (not necessarily writeable ones). return acceptableMediaTypes.size() == 1 && !MediaTypes.isWildcard(acceptableMediaTypes.get(0)); }
@Override public String getProducesMediaType() { return MediaTypes.convertToString(resourceMethod.getProducedTypes()); }
@Override public String getProducesMediaType() { return MediaTypes.convertToString(resourceMethod.getProducedTypes()); }
/** * Return a list of producible media types of the last matched resource method. * * @param extendedUriInfo uri info to obtain resource method from. * @return list of producible media types of the last matched resource method. */ private static List<MediaType> getResourceMethodProducibleTypes(final ExtendedUriInfo extendedUriInfo) { if (extendedUriInfo.getMatchedResourceMethod() != null && !extendedUriInfo.getMatchedResourceMethod().getProducedTypes().isEmpty()) { return extendedUriInfo.getMatchedResourceMethod().getProducedTypes(); } return Arrays.asList(MediaType.WILDCARD_TYPE); }
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 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 static boolean isMethodOverridden(ResourceMethod resourceMethod, String httpMethod, MediaType consumes, MediaType produces) { if (!resourceMethod.getHttpMethod().equals(httpMethod)) { return false; } final boolean consumesMatch = overrides(resourceMethod.getConsumedTypes(), consumes); final boolean producesMatch = overrides(resourceMethod.getProducedTypes(), produces); return consumesMatch && producesMatch; }
private static boolean isMethodOverridden(ResourceMethod resourceMethod, String httpMethod, MediaType consumes, MediaType produces) { if (!resourceMethod.getHttpMethod().equals(httpMethod)) { return false; } final boolean consumesMatch = overrides(resourceMethod.getConsumedTypes(), consumes); final boolean producesMatch = overrides(resourceMethod.getProducedTypes(), produces); return consumesMatch && producesMatch; }
@Override public List<Response> createResponses(org.glassfish.jersey.server.model.Resource r, ResourceMethod m) { final Response response = new Response(); // add mediaType="*/*" in case that no mediaType was specified if (hasEmptyProducibleMediaTypeSet(m)) { Representation wadlRepresentation = createResponseRepresentation(r, m, MediaType.WILDCARD_TYPE); response.getRepresentation().add(wadlRepresentation); } else { for (MediaType mediaType : m.getProducedTypes()) { Representation wadlRepresentation = createResponseRepresentation(r, m, mediaType); response.getRepresentation().add(wadlRepresentation); } } List<Response> responses = new ArrayList<Response>(); responses.add(response); return responses; }
@Override public List<Response> createResponses(org.glassfish.jersey.server.model.Resource r, ResourceMethod m) { final Response response = new Response(); // add mediaType="*/*" in case that no mediaType was specified if (hasEmptyProducibleMediaTypeSet(m)) { Representation wadlRepresentation = createResponseRepresentation(r, m, MediaType.WILDCARD_TYPE); response.getRepresentation().add(wadlRepresentation); } else { for (MediaType mediaType : m.getProducedTypes()) { Representation wadlRepresentation = createResponseRepresentation(r, m, mediaType); response.getRepresentation().add(wadlRepresentation); } } List<Response> responses = new ArrayList<Response>(); responses.add(response); return responses; }
private void addAllConsumesProducesCombinations(final List<ConsumesProducesAcceptor> acceptors, final MethodRouting methodRouting) { final ResourceMethod resourceMethod = methodRouting.method; final Set<MediaType> effectiveInputTypes = new LinkedHashSet<>(); boolean consumesFromWorkers = fillMediaTypes(effectiveInputTypes, resourceMethod, resourceMethod.getConsumedTypes(), true); final Set<MediaType> effectiveOutputTypes = new LinkedHashSet<>(); boolean producesFromWorkers = fillMediaTypes(effectiveOutputTypes, resourceMethod, resourceMethod.getProducedTypes(), false); final Set<ConsumesProducesAcceptor> acceptorSet = new HashSet<>(); for (MediaType consumes : effectiveInputTypes) { for (MediaType produces : effectiveOutputTypes) { acceptorSet.add(new ConsumesProducesAcceptor( new CombinedMediaType.EffectiveMediaType(consumes, consumesFromWorkers), new CombinedMediaType.EffectiveMediaType(produces, producesFromWorkers), methodRouting)); } } acceptors.addAll(acceptorSet); }
/** * Get the method unique string ID. The ID is constructed from method attributes separated * by pipe '|'. The attributes are used in the following order: * method-produces|method-consumes|http-method|method-path|method-java-name * <p> * If any of the attributes is not defined, "null" is used for such an attribute. * <p/> * * @param method Resource method. * @return String constructed from resource method parameters. */ public static String getMethodUniqueId(final ResourceMethod method) { final String path = method.getParent() != null ? createPath(method.getParent()) : "null"; return method.getProducedTypes().toString() + "|" + method.getConsumedTypes().toString() + "|" + method.getHttpMethod() + "|" + path + "|" + method.getInvocable().getHandlingMethod().getName(); }
private void addAllConsumesProducesCombinations(final List<ConsumesProducesAcceptor> acceptors, final MethodRouting methodRouting) { final ResourceMethod resourceMethod = methodRouting.method; final Set<MediaType> effectiveInputTypes = new LinkedHashSet<>(); boolean consumesFromWorkers = fillMediaTypes(effectiveInputTypes, resourceMethod, resourceMethod.getConsumedTypes(), true); final Set<MediaType> effectiveOutputTypes = new LinkedHashSet<>(); boolean producesFromWorkers = fillMediaTypes(effectiveOutputTypes, resourceMethod, resourceMethod.getProducedTypes(), false); final Set<ConsumesProducesAcceptor> acceptorSet = new HashSet<>(); for (MediaType consumes : effectiveInputTypes) { for (MediaType produces : effectiveOutputTypes) { acceptorSet.add(new ConsumesProducesAcceptor( new CombinedMediaType.EffectiveMediaType(consumes, consumesFromWorkers), new CombinedMediaType.EffectiveMediaType(produces, producesFromWorkers), methodRouting)); } } acceptors.addAll(acceptorSet); }
@Override public int compare(final ConsumesProducesAcceptor o1, final ConsumesProducesAcceptor o2) { // Make sure that annotated (@Consumes, @Produces) goes first. final ResourceMethod model1 = o1.methodRouting.method; final ResourceMethod model2 = o2.methodRouting.method; // @Consumes on method. int compared = compare(model1.getConsumedTypes(), model2.getConsumedTypes()); if (compared != 0) { return compared; } compared = compare(model1.getProducedTypes(), model2.getProducedTypes()); if (compared != 0) { return compared; } compared = MediaTypes.PARTIAL_ORDER_COMPARATOR.compare(o1.consumes.getMediaType(), o2.consumes.getMediaType()); if (compared != 0) { return compared; } return MediaTypes.PARTIAL_ORDER_COMPARATOR.compare(o1.produces.getMediaType(), o2.produces.getMediaType()); }
@Override public int compare(final ConsumesProducesAcceptor o1, final ConsumesProducesAcceptor o2) { // Make sure that annotated (@Consumes, @Produces) goes first. final ResourceMethod model1 = o1.methodRouting.method; final ResourceMethod model2 = o2.methodRouting.method; // @Consumes on method. int compared = compare(model1.getConsumedTypes(), model2.getConsumedTypes()); if (compared != 0) { return compared; } compared = compare(model1.getProducedTypes(), model2.getProducedTypes()); if (compared != 0) { return compared; } compared = MediaTypes.PARTIAL_ORDER_COMPARATOR.compare(o1.consumes.getMediaType(), o2.consumes.getMediaType()); if (compared != 0) { return compared; } return MediaTypes.PARTIAL_ORDER_COMPARATOR.compare(o1.produces.getMediaType(), o2.produces.getMediaType()); }
/** * Get the method unique string ID. The ID is constructed from method attributes separated * by pipe '|'. The attributes are used in the following order: * method-produces|method-consumes|http-method|method-path|method-java-name * <p> * If any of the attributes is not defined, "null" is used for such an attribute. * <p/> * * @param method Resource method. * @return String constructed from resource method parameters. */ public static String getMethodUniqueId(final ResourceMethod method) { final String path = method.getParent() != null ? createPath(method.getParent()) : "null"; return method.getProducedTypes().toString() + "|" + method.getConsumedTypes().toString() + "|" + method.getHttpMethod() + "|" + path + "|" + method.getInvocable().getHandlingMethod().getName(); }
/** * 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); } }