package com.dhcc.finance.config;

import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.dhcc.common.config.bean.FeignBasicAuthRequestInterceptor;
import com.dhcc.common.config.bean.FeignHystrixConcurrencyStrategy;
import com.dhcc.common.config.bean.ResponseErrorDecoder;

import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;

@Configuration
public class FeignClientConfig {

	
	@Autowired
    private ObjectFactory<HttpMessageConverters> messageConverters;
	
	/**
	 * 
	 * @Title: feignFormEncoder
	 * @Description: 创建一个form编码器，实现支持form表单提交
	 * @return Encoder
	 * @author chenrui
	 * @date 2018年12月7日 下午11:54:58
	 * @modifyLog：
	 */
    @Bean
    public Encoder feignFormEncoder() {
        return new SpringFormEncoder(new SpringEncoder(messageConverters));
    }
	
	@Bean
    public ResponseErrorDecoder responseErrorDecoder() {
        return new ResponseErrorDecoder();
    }
	
	@Bean
    public FeignBasicAuthRequestInterceptor basicAuthRequestInterceptor() {
        return new FeignBasicAuthRequestInterceptor();
    }
	
	@Bean
	public FeignHystrixConcurrencyStrategy feignHystrixConcurrencyStrategy() {
		return new FeignHystrixConcurrencyStrategy();
	}
}
