package com.bp.feign;
import com.alibaba.fastjson.JSONObject;
import com.bp.entity.dpt.UnifiedDataReq;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
@FeignClient(name = "unifiedData",url = "${unifiedDataService.newUrl}")
public interface UnifiedDataGatewayClient {
@PostMapping(value = "/organization/organizations/search")
JSONObject getDptData(@RequestBody UnifiedDataReq unifiedDataReq, @RequestHeader("Authorization") String accessToken, @RequestHeader("Content-Type") String contentType);
}
@PostMapping(value = “/organization/organizations/search”, consumes = “application/json”, produces = “application/json”)
package com.bp.feign;
import com.alibaba.fastjson.JSONObject;
import com.bp.entity.dpt.UnifiedDataReq;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
@FeignClient(name = "unifiedData",url = "${unifiedDataService.newUrl}")
public interface UnifiedDataGatewayClient {
@PostMapping(value = "/organization/organizations/search", consumes = "application/json", produces = "application/json")
JSONObject getDptData(@RequestBody UnifiedDataReq unifiedDataReq, @RequestHeader("Authorization") String accessToken, @RequestHeader("Content-Type") String contentType);
}
@Bean("requestInterceptor")
public RequestInterceptor requestInterceptor(){
return template -> {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
if(attributes!=null){
HttpServletRequest request = attributes.getRequest();
if (null == request){
return;
}
log.info(request.getHeaderNames().toString());
template.header("token", request.getHeader("token"));
}else {
log.warn("requestInterceptor获取Header空指针异常");
}
};
}