Using @Headers with dynamic values in Feign client + Spring Cloud (Brixton RC2)
I have this example, and I use @HeaderParam instead @RequestHeader :
import rx.Single;
import javax.ws.rs.Consumes;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
@Consumes(MediaType.APPLICATION_JSON)
public interface FeignRepository {
@POST
@Path("/Vehicles")
Single<CarAddResponse> add(@HeaderParam(HttpHeaders.AUTHORIZATION) String authorizationHeader, VehicleDto vehicleDto);
}
@HeaderMap,@Header and @Param didn't worked for me, below is the solution to use @RequestHeader when there are multiple header parameters to pass using FeignClient
@PostMapping("/api/channelUpdate")
EmployeeDTO updateRecord(
@RequestHeader Map<String, String> headerMap,
@RequestBody RequestDTO request);
code to call the proxy is as below:
Map<String, String> headers = new HashMap<>();
headers.put("channelID", "NET");
headers.put("msgUID", "1234567889");
ResponseDTO response = proxy.updateRecord(headers,requestDTO.getTxnRequest());
The @RequestHeader did not work for me. What did work was:
@Headers("X-Auth-Token: {access_token}")
@RequestLine("GET /orders/{id}")
Order get(@Param("id") String id, @Param("access_token") String accessToken);
The solution is to use @RequestHeader annotation instead of feign specific annotations
@FeignClient(name="Simple-Gateway")
interface GatewayClient {
@RequestMapping(method = RequestMethod.GET, value = "/gateway/test")
String getSessionId(@RequestHeader("X-Auth-Token") String token);
}