1

当调用端点时,我在 spring 中使用 spring security 运行 feign,而端点又调用使用 feign Gson 的服务

端点:

 @ApiOperation(value = "Cisco 1000v", notes = "Used with Nexus 1000v to Get configuration")
 @RequestMapping(value = "/cisco", method = RequestMethod.GET)
public String getCisco(
         @ApiParam(value = "Function to apply to switch", required = true)   @RequestParam(value="Function") String function,
         @ApiParam(value = "Hostname of device", required = true) @RequestParam(value="host")  String hostname,
         @ApiParam(value = "Username for device login", required = true) @RequestParam(value="user") String username,
         @ApiParam(value = "Password of device", required = true) @RequestParam(value="pass")   String password) throws IOException, SAXException, ParserConfigurationException {

    CiscoNexus service = new CiscoNexus(hostname, username, password);
    if (function.equals("port-profile")) {
        return service.getPort();`

服务:

public class CiscoNexus {

private final String hostname, username, password;

public CiscoNexus(String hostname, String username, String password) {
    this.hostname = hostname;
    this.username = username;
    this.password = password;
}
public String getPort() {
    PortProfiles ports = Feign.builder()
            .decoder(new GsonDecoder())
            .encoder(new GsonEncoder())
            .target(PortProfiles.class, "http://" + username + ":" + password + "@" + hostname);

    System.out.println("Getting Port Profiles...");
    ports.get();
    return ports.get();
}

interface PortProfiles {
    @RequestLine("GET /api/port-profile")
    @Headers("Accept: application/json")
    String get();
}

由于我在调用端点时使用弹簧安全性,因此我必须添加一个 auth 标头,但似乎 feign 保留了标头并将其发送到由于它而无法正确响应的目标,这是可以的吗避免?

4

0 回答 0