Feign makes empty request

20 views Asked by At

I've use eureka and openfeign and I want to send simple post but it nulls fields in request body.

Below is definition of client

@FeignClient("notification", path = "/api")
interface NotificationClient {

    @RequestMapping(
        method = [RequestMethod.POST],
        path = ["/sms"],
        consumes = [MediaType.APPLICATION_JSON_VALUE],
        name = "sendSms"
    )
    fun sendSms(@RequestBody(required = true) message: Message)
}

Body:

@MarkAsOpen
class Message(
    val phone: String,
    val text: String,
    val uuid: UUID = UUID.randomUUID()
) {

And in other service I've receive error that fields are null

2024-03-19 08:33:00.070 WARN  o.s.w.s.m.s.DefaultHandlerExceptionResolver - Resolved [org.springframework.web.bind.MethodArgumentNotValidException: Validation failed for argument [0] in public void tralalala.notification.sms.control.SmsResource.sendSms(tralalala.sms.Message): [Error in object 'tralalala.sms.Message': codes []; arguments []; default message [Parameter specified as non-null is null: method tralalala.sms.Message.<init>, parameter phone]] ]

When I've call this endpoint via external tool it works. Looks like Feign client nulls body.

1

There are 1 answers

0
Kacper On

I've resolved this. Due to conflict with soap endpoints I had to mark @RequestBody also on Rest endpoint, and now deserialization works fine

    @PostMapping("$API_URI/sms")
    fun sendSms(@RequestBody message: Message) {
        //logic
    }