0
In my code where I search a list of clients of a particular company, however according to the name of the client I must do the search in a certain third party Endpoint. In my example (below) come on get the client name = "company-A" I have to search in Endpoint "https://companiaA" if it comes client name = "company-B" I must search in Endpoint "https://companiaB" and so on, the change occurs only in the domain. I would like to thank you in advance for your attention. Thank you
NOTE: If necessary I can receive the client url as a parameter in the controller
FEIGN CLIENT INTERFACE
import org.springframework.cloud.openfeign.FeignClient
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
@FeignClient(url = "https://clienteA", name = "TrazLista")
interface ListaClienteExt {
@GetMapping("/lista-cliente")
fun getListaCliente(@RequestParam(required = true) nomeCliente: String): ResponseEntity<Any>
}
CONTROLLER
fun getListaCliente(
@RequestParam(required = true) nomeCliente: String
): ResponseEntity<Any> {
try {
val list = ListaClienteExt.getListaCliente(nomeCliente).body
return ResponseEntity(list, HttpStatus.OK)
} catch (e: FeignException) {
return ResponseEntity(MessageJson(e.contentUTF8() ?: "Erro externo"), HttpStatus.NOT_FOUND)
} catch (e: ExceptionMessage) {
return ResponseEntity(MessageJson(e.message ?: "Erro get"), HttpStatus.NOT_FOUND)
}
}