假装客户端连接



Heloo 每个身体,我正在尝试通过假客户端连接到 API,我在 jhipster 网关中使用假客户端.. 我已经在微服务中使用相同的代码,并且工作正常,这是我编写的代码:


@FeignClient( name = "berrycord" ,url = "https://dev1.digitalberry.fr/bcs-berrycord-direct/")
/**
* This interface is used to call berryscheduler APIs ,
* using netflix feign client
* @param body  host to manage
*/
public interface TraceClientInterface {
@PostMapping("api/v1/records/")
public JSONObject sendReport(@RequestBody JSONObject report);
// @GetMapping(value="/jokes/count")
// public JSONObject sendReport();
}
@Component
public class UserFeignClientInterceptor implements RequestInterceptor {
private static final String AUTHORIZATION_HEADER = "Authorization";
private static final String BEARER = "Bearer";
@Override
public void apply(RequestTemplate template) {
System.out.println("test ========================" +template.request());
System.out.println("test ========================2" +template.toString());
System.out.println("test ========================3" +new String(template.body()));
SecurityUtils.getCurrentUserJWT()
.ifPresent(s -> template.header(AUTHORIZATION_HEADER,String.format("%s %s", BEARER, s)));

SecurityUtils.getCurrentUserLogin()
.ifPresent(user -> template.header("X-Forwarded-User", user));
SecurityUtils.getCurrentUserAuthorities()
.ifPresent(authorities -> template.header("X-Forwarded-Role", authorities));
}
}
/**
* This service communicates with berryCord to create a send report POST
* /api/v1/report/ endpoint, is called when creating or updating the host
* resource
* 
* @param task
*/
public JSONObject sendReport(JSONObject report) {
log.debug("Request to create log report in berrycord ");
JSONObject rep = new JSONObject() ;
try {
log.info("=========== Request to create log report in berrycord 2 " , report);
rep =  traceClientInterface.sendReport(report);
log.info("=========== Request to create log report in berrycord 3 " , report);
} catch (FeignException e) {
e.getStackTrace();
}
return rep;
}

feign:
hystrix:
enabled: false
client:
url: 
berryCordUrl: https://dev1.digitalberry.fr/bcs-berrycord-direct/

但是两者之间的联系从未完成,我看不到调用的API的结果.. 谁能告诉我我做错了什么..谢谢:) :)

您应该具有如下@Configuration,并将@EnableFeignClients添加到您的Application.java

@Configuration
public class FooConfiguration {
@Bean
public UserFeignClientInterceptor userFeignClientInterceptor() {
return new UserFeignClientInterceptor();
}
}

相关内容

  • 没有找到相关文章

最新更新