スプリングクラウド装うコールマイクロ配信サービス要求ヘッダヘッダ

パッケージcom.chitic.module.core.config。

輸入feign.RequestInterceptor;
輸入org.springframework.context.annotation.Bean;
輸入org.springframework.context.annotation.Configuration。
輸入org.springframework.web.context.request.RequestContextHolder。
輸入org.springframework.web.context.request.ServletRequestAttributes。

インポートのjavax.servlet.http.HttpServletRequest;
インポートのjava.util.Enumeration; 

 
@Configuration 
パブリック クラスFeignConfig { 

    @Bean 
    公共RequestInterceptor headerInterceptor(){
         戻りテンプレート- >{ 
            ServletRequestAttributes属性は = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
            もしヌル!= 属性){ 
                HttpServletRequestのリクエスト = attributes.getRequest(); 
                列挙の<string> headerNames = request.getHeaderNames()。
                もし(!headerNames = NULL ){
                     一方(headerNames.hasMoreElements()){ 
                        文字列名 = headerNames.nextElement()。
                        文字列値 =request.getHeader(名); 
                        template.header(名前、値); 
                    } 
                } 
            } 
        }。
    } 

}

それは注意すべきで、呼び出しはHttpServletResponseのパラメータ(例えば、共通のデータエクスポートなど)が含まれていないことができ、リモート装うコールは今解決策を見つけることができなかったとき、次のようにコールすることはできません。

 

おすすめ

転載: www.cnblogs.com/gaomanito/p/12515526.html