我在弹簧安全的春天运行时调用端点,然后调用使用假装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();
}
当我在调用端点时使用spring安全性时,我必须添加一个auth标头,但似乎feign保留标头并将其发送到目标因为它没有正确响应,这是什么那可以避免吗?