英文:
Springboot API returns null response
问题
This API works fine; I can see it hits the server and returns 200. But the response captured in the client code is null. I have checked the response via postman and I can see the status code. Not Sure why the client is not able to decode the response
API interface
Implementation
@Test
fun test() {
try {
val response = client.submit(request)
if (response.statusCodeValue == 200) {
logger.info("Success")
return
} else {
throw Exception("Internal Server Error")
}
} catch (e: Exception) {
throw Exception("Exception occurred while calling the submit API", e)
}
}
英文:
This API works fine; I can see it hits the server and returns 200. But the response captured in the client code is null. I have checked the response via postman and I can see the status code. Not Sure why client is not able to decode the response
@Bean
fun buildClient(
objectMapper: ObjectMapper,
@Value("${cbase-uri}") url: String
): Client {
return FeignApiBuilder.builder(Client::class.java, url) { it }
.build()
}
API interface
@Headers(
"Accept: ${MimeTypeUtils.APPLICATION_JSON_VALUE}",
"Content-Type: ${MimeTypeUtils.APPLICATION_JSON_VALUE}"
)
interface Client {
@RequestLine("POST /v1/test")
fun submit(
request: body
): ResponseEntity<Unit>
}
Implementation
override fun test(request: body) {
try {
val response = client.submit(request)
if (response.statusCodeValue == 200) {
logger.info("Success")
return
} else {
throw Exception("Internal Server Error")
}
} catch (e: Exception) {
throw Exception("Exception occurred while calling submit api", e)
}
}
答案1
得分: 1
问题似乎是由API接口方法的返回类型引起的。您正在返回"ResponseEntity<Unit>",您可以将返回类型更改为预期的类型,然后检查是否解决了问题。
英文:
Looks like the issue is due to return type of API interface method. You are returning "ResponseEntity<Unit>", can you change the return type to the expected type and check if that fixes the issue
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论