org.springframework.cloud.openfeign.AnnotatedParameterProcessor Java Examples

The following examples show how to use org.springframework.cloud.openfeign.AnnotatedParameterProcessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenFeignSpringMvcContract.java    From summerframework with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean processAnnotationsOnParameter(MethodMetadata data, Annotation[] annotations, int paramIndex) {
    boolean isHttpAnnotation = false;

    AnnotatedParameterProcessor.AnnotatedParameterContext context =
        new OpenFeignSpringMvcContract.SimpleAnnotatedParameterContext(data, paramIndex);
    Method method = this.processedMethods.get(data.configKey());
    for (Annotation parameterAnnotation : annotations) {
        AnnotatedParameterProcessor processor =
            this.annotatedArgumentProcessors.get(parameterAnnotation.annotationType());
        if (processor != null) {
            Annotation processParameterAnnotation;

            processParameterAnnotation =
                synthesizeWithMethodParameterNameAsFallbackValue(parameterAnnotation, method, paramIndex);
            isHttpAnnotation |= processor.processArgument(context, processParameterAnnotation, method);
        }
    }
    if (isHttpAnnotation && data.indexToExpander().get(paramIndex) == null
        && this.conversionService.canConvert(method.getParameterTypes()[paramIndex], String.class)) {
        data.indexToExpander().put(paramIndex, this.expander);
    }
    return isHttpAnnotation;
}
 
Example #2
Source File: OpenFeignAutoConfiguration.java    From summerframework with Apache License 2.0 6 votes vote down vote up
@Bean
public OpenFeignSpringMvcContract feignSpringMvcContract(
    @Autowired(required = false) List<AnnotatedParameterProcessor> parameterProcessors,
    List<ConversionService> conversionServices) {
    if (conversionServices.size() == 0) {
        throw new IllegalStateException("ConversionService can not be NULL");
    }
    ConversionService conversionService = null;
    if (conversionServices.size() == 1) {
        conversionService = conversionServices.get(0);
    } else {
        // 如果有多个实例,优先使用找到的第一个DefaultFormattingConversionService,如果没有,则使用FormattingConversionService
        conversionService = conversionServices.stream().filter(c -> c instanceof DefaultFormattingConversionService)
            .findFirst().orElseGet(() -> conversionServices.stream()
                .filter(c -> c instanceof FormattingConversionService).findFirst().get());
    }
    if (null == parameterProcessors) {
        parameterProcessors = new ArrayList<>();
    }
    return new OpenFeignSpringMvcContract(parameterProcessors, conversionService);
}
 
Example #3
Source File: VenusSpringMvcContract.java    From venus-cloud-feign with Apache License 2.0 6 votes vote down vote up
public VenusSpringMvcContract(
        List<AnnotatedParameterProcessor> annotatedParameterProcessors,
        ConversionService conversionService) {
    Assert.notNull(annotatedParameterProcessors,
            "Parameter processors can not be null.");
    Assert.notNull(conversionService, "ConversionService can not be null.");

    List<AnnotatedParameterProcessor> processors;
    if (!annotatedParameterProcessors.isEmpty()) {
        processors = new ArrayList<>(annotatedParameterProcessors);
    }
    else {
        processors = getDefaultAnnotatedArgumentsProcessors();
    }
    this.annotatedArgumentProcessors = toAnnotatedArgumentProcessorMap(processors);
    this.conversionService = conversionService;
    this.expander = new org.springframework.cloud.openfeign.support.SpringMvcContract.ConvertingExpander(conversionService);
}
 
Example #4
Source File: OpenFeignSpringMvcContract.java    From summerframework with Apache License 2.0 5 votes vote down vote up
public OpenFeignSpringMvcContract(List<AnnotatedParameterProcessor> annotatedParameterProcessors,
    ConversionService conversionService) {
    Assert.notNull(annotatedParameterProcessors, "Parameter processors can not be null.");
    Assert.notNull(conversionService, "ConversionService can not be null.");

    List<AnnotatedParameterProcessor> processors;
    if (!annotatedParameterProcessors.isEmpty()) {
        processors = new ArrayList<>(annotatedParameterProcessors);
    } else {
        processors = getDefaultAnnotatedArgumentsProcessors();
    }
    this.annotatedArgumentProcessors = toAnnotatedArgumentProcessorMap(processors);
    this.conversionService = conversionService;
    this.expander = new SpringMvcContract.ConvertingExpander(conversionService);
}
 
Example #5
Source File: VenusFeignAutoConfig.java    From venus-cloud-feign with Apache License 2.0 5 votes vote down vote up
@Bean
public VenusSpringMvcContract feignSpringMvcContract(@Autowired(required = false) List<AnnotatedParameterProcessor> parameterProcessors,
                                                     ConversionService conversionService) {
    if (null == parameterProcessors) {
        parameterProcessors = new ArrayList<>();
    }
    return new VenusSpringMvcContract(parameterProcessors, conversionService);
}
 
Example #6
Source File: VenusSpringMvcContract.java    From venus-cloud-feign with Apache License 2.0 5 votes vote down vote up
private Map<Class<? extends Annotation>, AnnotatedParameterProcessor> toAnnotatedArgumentProcessorMap(
        List<AnnotatedParameterProcessor> processors) {
    Map<Class<? extends Annotation>, AnnotatedParameterProcessor> result = new HashMap<>();
    for (AnnotatedParameterProcessor processor : processors) {
        result.put(processor.getAnnotationType(), processor);
    }
    return result;
}
 
Example #7
Source File: VenusSpringMvcContract.java    From venus-cloud-feign with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean processAnnotationsOnParameter(MethodMetadata data,
                                                Annotation[] annotations, int paramIndex) {
    boolean isHttpAnnotation = false;

    AnnotatedParameterProcessor.AnnotatedParameterContext context = new VenusSpringMvcContract.SimpleAnnotatedParameterContext(
            data, paramIndex);
    Method method = this.processedMethods.get(data.configKey());
    for (Annotation parameterAnnotation : annotations) {
        AnnotatedParameterProcessor processor = this.annotatedArgumentProcessors
                .get(parameterAnnotation.annotationType());
        if (processor != null) {
            Annotation processParameterAnnotation;
            // synthesize, handling @AliasFor, while falling back to parameter name on
            // missing String #value():
            processParameterAnnotation = synthesizeWithMethodParameterNameAsFallbackValue(
                    parameterAnnotation, method, paramIndex);
            isHttpAnnotation |= processor.processArgument(context,
                    processParameterAnnotation, method);
        }
    }
    if (isHttpAnnotation && data.indexToExpander().get(paramIndex) == null
            && this.conversionService.canConvert(
            method.getParameterTypes()[paramIndex], String.class)) {
        data.indexToExpander().put(paramIndex, this.expander);
    }
    return isHttpAnnotation;
}
 
Example #8
Source File: SpringMvcContract.java    From spring-cloud-openfeign with Apache License 2.0 5 votes vote down vote up
private List<AnnotatedParameterProcessor> getDefaultAnnotatedArgumentsProcessors() {

		List<AnnotatedParameterProcessor> annotatedArgumentResolvers = new ArrayList<>();

		annotatedArgumentResolvers.add(new MatrixVariableParameterProcessor());
		annotatedArgumentResolvers.add(new PathVariableParameterProcessor());
		annotatedArgumentResolvers.add(new RequestParamParameterProcessor());
		annotatedArgumentResolvers.add(new RequestHeaderParameterProcessor());
		annotatedArgumentResolvers.add(new QueryMapParameterProcessor());
		annotatedArgumentResolvers.add(new RequestPartParameterProcessor());

		return annotatedArgumentResolvers;
	}
 
Example #9
Source File: SpringMvcContract.java    From spring-cloud-openfeign with Apache License 2.0 5 votes vote down vote up
private Map<Class<? extends Annotation>, AnnotatedParameterProcessor> toAnnotatedArgumentProcessorMap(
		List<AnnotatedParameterProcessor> processors) {
	Map<Class<? extends Annotation>, AnnotatedParameterProcessor> result = new HashMap<>();
	for (AnnotatedParameterProcessor processor : processors) {
		result.put(processor.getAnnotationType(), processor);
	}
	return result;
}
 
Example #10
Source File: SpringMvcContract.java    From spring-cloud-openfeign with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean processAnnotationsOnParameter(MethodMetadata data,
		Annotation[] annotations, int paramIndex) {
	boolean isHttpAnnotation = false;

	AnnotatedParameterProcessor.AnnotatedParameterContext context = new SimpleAnnotatedParameterContext(
			data, paramIndex);
	Method method = this.processedMethods.get(data.configKey());
	for (Annotation parameterAnnotation : annotations) {
		AnnotatedParameterProcessor processor = this.annotatedArgumentProcessors
				.get(parameterAnnotation.annotationType());
		if (processor != null) {
			Annotation processParameterAnnotation;
			// synthesize, handling @AliasFor, while falling back to parameter name on
			// missing String #value():
			processParameterAnnotation = synthesizeWithMethodParameterNameAsFallbackValue(
					parameterAnnotation, method, paramIndex);
			isHttpAnnotation |= processor.processArgument(context,
					processParameterAnnotation, method);
		}
	}

	if (!isMultipartFormData(data) && isHttpAnnotation
			&& data.indexToExpander().get(paramIndex) == null) {
		TypeDescriptor typeDescriptor = createTypeDescriptor(method, paramIndex);
		if (this.conversionService.canConvert(typeDescriptor,
				STRING_TYPE_DESCRIPTOR)) {
			Param.Expander expander = this.convertingExpanderFactory
					.getExpander(typeDescriptor);
			if (expander != null) {
				data.indexToExpander().put(paramIndex, expander);
			}
		}
	}
	return isHttpAnnotation;
}
 
Example #11
Source File: SpringMvcContract.java    From spring-cloud-openfeign with Apache License 2.0 5 votes vote down vote up
public SpringMvcContract(
		List<AnnotatedParameterProcessor> annotatedParameterProcessors,
		ConversionService conversionService) {
	Assert.notNull(annotatedParameterProcessors,
			"Parameter processors can not be null.");
	Assert.notNull(conversionService, "ConversionService can not be null.");

	List<AnnotatedParameterProcessor> processors = getDefaultAnnotatedArgumentsProcessors();
	processors.addAll(annotatedParameterProcessors);

	this.annotatedArgumentProcessors = toAnnotatedArgumentProcessorMap(processors);
	this.conversionService = conversionService;
	this.convertingExpanderFactory = new ConvertingExpanderFactory(conversionService);
}
 
Example #12
Source File: OpenFeignSpringMvcContract.java    From summerframework with Apache License 2.0 5 votes vote down vote up
protected Map<Class<? extends Annotation>, AnnotatedParameterProcessor>
    toAnnotatedArgumentProcessorMap(List<AnnotatedParameterProcessor> processors) {
    Map<Class<? extends Annotation>, AnnotatedParameterProcessor> result = new HashMap<>();
    for (AnnotatedParameterProcessor processor : processors) {
        result.put(processor.getAnnotationType(), processor);
    }
    return result;
}
 
Example #13
Source File: VenusSpringMvcContract.java    From venus-cloud-feign with Apache License 2.0 4 votes vote down vote up
public VenusSpringMvcContract(
        List<AnnotatedParameterProcessor> annotatedParameterProcessors) {
    this(annotatedParameterProcessors, new DefaultConversionService());
}
 
Example #14
Source File: SpringMvcContract.java    From spring-cloud-openfeign with Apache License 2.0 4 votes vote down vote up
public SpringMvcContract(
		List<AnnotatedParameterProcessor> annotatedParameterProcessors) {
	this(annotatedParameterProcessors, new DefaultConversionService());
}
 
Example #15
Source File: OpenFeignSpringMvcContract.java    From summerframework with Apache License 2.0 4 votes vote down vote up
public OpenFeignSpringMvcContract(List<AnnotatedParameterProcessor> annotatedParameterProcessors) {
    this(annotatedParameterProcessors, new DefaultConversionService());
}
 
Example #16
Source File: BladeSpringMvcContract.java    From blade-tool with GNU Lesser General Public License v3.0 4 votes vote down vote up
public BladeSpringMvcContract(List<AnnotatedParameterProcessor> annotatedParameterProcessors, ConversionService conversionService) {
	super(annotatedParameterProcessors, conversionService);
}
 
Example #17
Source File: OpenFeignSpringMvcContract.java    From summerframework with Apache License 2.0 3 votes vote down vote up
protected List<AnnotatedParameterProcessor> getDefaultAnnotatedArgumentsProcessors() {

        List<AnnotatedParameterProcessor> annotatedArgumentResolvers = new ArrayList<>();

        annotatedArgumentResolvers.add(new PathVariableParameterProcessor());
        annotatedArgumentResolvers.add(new RequestParamParameterProcessor());
        annotatedArgumentResolvers.add(new RequestHeaderParameterProcessor());

        return annotatedArgumentResolvers;
    }
 
Example #18
Source File: VenusSpringMvcContract.java    From venus-cloud-feign with Apache License 2.0 3 votes vote down vote up
private List<AnnotatedParameterProcessor> getDefaultAnnotatedArgumentsProcessors() {

        List<AnnotatedParameterProcessor> annotatedArgumentResolvers = new ArrayList<>();

        annotatedArgumentResolvers.add(new PathVariableParameterProcessor());
        annotatedArgumentResolvers.add(new RequestParamParameterProcessor());
        annotatedArgumentResolvers.add(new RequestHeaderParameterProcessor());

        return annotatedArgumentResolvers;
    }