I am trying to call the below url from Feign client(org.springframework.cloud.openfeign.FeignClient
) here:
http://localhost:8085/test/send/S.MV00.S0.CAL_EXAMP/KWX0.GAT0.REPLY___EXCHANGE_WITH_OTHER_ONE__.SO/KWX0.GAT0.REPLY___EXCHANGE_WITH_OTHER_ONE__.AI/
I get 404 error in Feign client but in Postman the url works fine.
FeignClient Kotlin code:
import org.springframework.cloud.openfeign.FeignClient
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.http.ResponseEntity
import javax.validation.Valid
@FeignClient(
value = "CalculatorClient",
url = "http://localhost:8085/test/send/S.MV00.S0.CAL_EXAMP/KWX0.GAT0.REPLY___EXCHANGE_WITH_OTHER_ONE__.SO/KWX0.GAT0.REPLY___EXCHANGE_WITH_OTHER_ONE__.AI/"
)
interface CalculatorClient {
@PostMapping
fun calculateInformation(@RequestBody request: @Valid String): ResponseEntity<String?>
}
Provider Java code:
@RestController
@RequestMapping("/test")
public class TestController {
@PostMapping("/send/{destination:.+}/{calculate:.+}/{process:.+}/")
public ResponseEntity<String> sendAndReceive(
@PathVariable final String destination,
@PathVariable final String calculate,
@PathVariable final String process) {
return ResponseEntity.ok("endpoint called");
}
}
How can I fix this in Feign client? Looks like the trailing slash is being removed by Feign Client which is not the case when using RestTemplate.
I cannot change provider code because it is from some other company.
when moving from RestTemplate to FeignClient, please note that trailing slash is removed in FeignClient but not in RestTemplate.
This could cause 404 error in some cases, like the one mentioned in the question. So if the slash at the end is needed then use 2 slash at the end of the URL so that when one slash is removed the endpoint will work https://github.com/OpenFeign/feign/issues/623
Usually when we get 404 error then we never think about trailing slash being the problem.