@Override public String getConsumesMediaType() { return MediaTypes.convertToString(resourceMethod.getConsumedTypes()); }
@Override public String getConsumesMediaType() { return MediaTypes.convertToString(resourceMethod.getConsumedTypes()); }
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 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; }
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); }
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(); }
@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(); }
for (Parameter parameter : requestParameters) { if (parameter.getSource() == Parameter.Source.ENTITY || parameter.getSource() == Parameter.Source.UNKNOWN) { for (MediaType mediaType : resourceMethod.getConsumedTypes()) { setRepresentationForMediaType(parentResource, resourceMethod, mediaType, wadlRequest); List<MediaType> supportedInputTypes = resourceMethod.getConsumedTypes(); if (supportedInputTypes.isEmpty() || (supportedInputTypes.size() == 1 && supportedInputTypes.get(0).isWildcardType())) { List<MediaType> supportedInputTypes = resourceMethod.getConsumedTypes(); if (supportedInputTypes.isEmpty() || (supportedInputTypes.size() == 1 && supportedInputTypes.get(0).isWildcardType())) {
for (Parameter parameter : requestParameters) { if (parameter.getSource() == Parameter.Source.ENTITY || parameter.getSource() == Parameter.Source.UNKNOWN) { for (MediaType mediaType : resourceMethod.getConsumedTypes()) { setRepresentationForMediaType(parentResource, resourceMethod, mediaType, wadlRequest); List<MediaType> supportedInputTypes = resourceMethod.getConsumedTypes(); if (supportedInputTypes.isEmpty() || (supportedInputTypes.size() == 1 && supportedInputTypes.get(0).isWildcardType())) { List<MediaType> supportedInputTypes = resourceMethod.getConsumedTypes(); if (supportedInputTypes.isEmpty() || (supportedInputTypes.size() == 1 && supportedInputTypes.get(0).isWildcardType())) {
if (m1.getConsumedTypes().isEmpty() || m2.getConsumedTypes().isEmpty()) { consumesFails = inputTypes1.equals(inputTypes2); if (!consumesFails) {
if (m1.getConsumedTypes().isEmpty() || m2.getConsumedTypes().isEmpty()) { consumesFails = inputTypes1.equals(inputTypes2); if (!consumesFails) {
/** * 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); } }
@Override public String getConsumesMediaType() { return MediaTypes.convertToString(resourceMethod.getConsumedTypes()); }
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; }