I have a client working fine in Micronaut 3, but when I tried to upgrade to Micronaut 4 I get a persistent error on the response. The output is confusing because I can see the JSON response, but then it says Full HTTP response received an empty body
.
I can call the server (wiremock) with an http client (insomnia) and get the expected the response.
I moved my code into the micronaut 4 example (https://guides.micronaut.io/latest/micronaut-http-client-gradle-kotlin.html) and I still get similar results, so I don't think it is a build issue. Happy to provide this example on request. I have a similar error in multiple clients, so I don't think it is specific to this example.
15:00:13.595 [default-nioEventLoopGroup-1-1] DEBUG i.m.h.client.netty.DefaultHttpClient - Sending HTTP POST to http://localhost:8888/auth/oauth/v2/token
15:00:13.596 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - x-api-key: *MASKED*
15:00:13.596 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - Accept: application/json
15:00:13.596 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - content-type: application/x-www-form-urlencoded
15:00:13.596 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - host: localhost:8888
15:00:13.596 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - connection: keep-alive
15:00:13.596 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - content-length: 84
15:00:13.596 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - Request Body
15:00:13.596 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - ----
15:00:13.596 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - username=svSomething1&password=svitem&grant_type=password&scope=profile+email+openid
15:00:13.596 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - ----
15:00:13.664 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - HTTP Client Response Received (200 OK) for Request: POST http://localhost:8888/auth/oauth/v2/token
15:00:13.664 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - Content-Type: application/json
15:00:13.664 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - Matched-Stub-Id: 8aea6d83-9948-4e30-809f-2e869f9d629c
15:00:13.664 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - content-length: 1055
15:00:13.664 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - Response Body
15:00:13.664 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - ----
15:00:13.664 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - {
"access_token": "eyJraWQiOiJFLlNURy4wMUgyOVdTWkI4NDFQOCIsImFsZyI6IlJTMjU2IiwidHlwIjoiSldUIn0.eyJzdWIiOiJTVk5PREVET09SVVNSMSIsImlzcyI6Imh0dHBzOi8vb2F1dGguaWFtLnBlcmYudGFyZ2V0LmNvbSIsImV4cCI6MTY4NzE0ODA4MCwiaWF0IjoxNjg2ODg4ODgwLCJqdGkiOiJFTlQuYTNlNzI0YzI1ZTgyNGFjMzhmZDdmOTY1NjFjODk4MzUtbCIsInNreSI6IkUuU1RHLjAxSDI5V1NaQjg0MVA4Iiwic3V0IjoiUiIsInNjbyI6Im9wZW5pZCxwcm9maWxlLGVtYWlsIiwiY2xpIjoibm9kZV9kb29yc19yb3BjIiwiYXNsIjoiTCIsInVzZXJuYW1lIjoiU1ZOT0RFRE9PUlVTUjEiLCJraWQiOiJFLlNURy4wMUgyOVdTWkI4NDFQOCIsInNjb3BlIjpbImVtYWlsIiwib3BlbmlkIiwicHJvZmlsZSJdLCJhYWwiOiIxIiwiY2xpZW50X2lkIjoibm9kZV9kb29yc19yb3BjIiwiZGlyIjoiYWQifQ.rWSbDADxQVayUHzi4fAg2iW9_6fbChlyM9alroZuoeZbdLma7GOpzAbfJYe6ObsTkB-ImQqDenrUvDbFuyDsUrXuJJUDVySSoM6D3leLF-rFlH_8fMyIMoRJaAeP7E-_mcswHoZerIlfEUu8ExguN8J8QaqLUNgcJ72G9mjjN4uNAr9-uWxR-freM2FEJTqRBSdZoAM1sg25c42he5MBcYJyUuq73mqvgH5GzgfEqLOF6H1EkhQ09eSZOb_JXRN4qm-S4LszZs8rGWE7-rXXpAdFwqqdztYrg1dNZW34JOG7xc8mXZatTeXdySIUKbWN0Rwql9GtnaXiSONblaBGug",
"expires_in": 259200,
"token_type": "Bearer",
"scope": "email openid profile"
}
15:00:13.664 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - ----
15:00:13.683 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - Full HTTP response received an empty body
15:00:13.683 [default-nioEventLoopGroup-1-1] TRACE i.m.h.client.netty.DefaultHttpClient - Unable to convert response body to target type class java.lang.String
io.micronaut.http.client.exceptions.HttpClientResponseException: Client 'id2': Error decoding HTTP response body: Error decoding JSON stream for type [id2TokenResponse]: Unable to deserialize type [com.tgt.warehouse.loadship.Id2TokenResponse]. Required constructor parameter [String accessToken] at index [0] is not present or is null in the supplied data
at io.micronaut.http.client.netty.DefaultHttpClient$FullHttpResponseHandler.makeNormalBodyParseError(DefaultHttpClient.java:2254)
at io.micronaut.http.client.netty.DefaultHttpClient$FullHttpResponseHandler.forwardResponseToPromise(DefaultHttpClient.java:2184)
at io.micronaut.http.client.netty.DefaultHttpClient$FullHttpResponseHandler.channelReadInstrumented(DefaultHttpClient.java:2140)
at io.micronaut.http.client.netty.DefaultHttpClient$FullHttpResponseHandler.channelReadInstrumented(DefaultHttpClient.java:2108)
at io.micronaut.http.client.netty.SimpleChannelInboundHandlerInstrumented.channelRead0(SimpleChannelInboundHandlerInstrumented.java:46)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
Reponse object:
@Serdeable
data class Id2TokenResponse(
val accessToken: String,
val expiresIn: Long,
val tokenType: String,
val scope: String
)
@Client("id2")
@Requires(property = "id2.enabled", value = "true")
interface OauthClient {
@Post("/auth/oauth/v2/token")
@Header(name = HttpHeaders.CONTENT_TYPE, value = MediaType.APPLICATION_FORM_URLENCODED)
fun fetchToken(
@Header("x-api-key") apiKey: String,
@Body request: Map<String, String>
): Id2TokenResponse?
}