【发布时间】:2015-06-08 23:37:18
【问题描述】:
我正在尝试实现 Feign Clients 以从用户的服务中获取我的用户信息,目前我正在使用 oAuth2RestTemplate 进行请求,它可以工作。但是现在我希望更改为 Feign,但我收到错误代码 401 可能是因为它不携带用户令牌,所以有一种方法可以自定义,如果 Spring 对 Feign 的支持正在使用,我可以使用 RestTemplate我自己的豆子?
今天我就是这样实现的
客户的服务
@Retryable({RestClientException.class, TimeoutException.class, InterruptedException.class})
@HystrixCommand(fallbackMethod = "getFallback")
public Promise<ResponseEntity<UserProtos.User>> get() {
logger.debug("Requiring discovery of user");
Promise<ResponseEntity<UserProtos.User>> promise = Broadcaster.<ResponseEntity<UserProtos.User>>create(reactorEnv, DISPATCHER)
.observe(Promises::success)
.observeError(Exception.class, (o, e) -> Promises.error(reactorEnv, ERROR_DISPATCHER, e))
.filter(entity -> entity.getStatusCode().is2xxSuccessful())
.next();
promise.onNext(this.client.getUserInfo());
return promise;
}
还有客户
@FeignClient("account")
public interface UserInfoClient {
@RequestMapping(value = "/uaa/user",consumes = MediaTypes.PROTOBUF,method = RequestMethod.GET)
ResponseEntity<UserProtos.User> getUserInfo();
}
【问题讨论】:
标签: spring-security-oauth2 spring-cloud