Micronaut-core: How to return only the body from HttpResponse while upgrading from Micronaut 1.3.6 to 2.0.0

Created on 28 Jul 2020  Â·  7Comments  Â·  Source: micronaut-projects/micronaut-core

How to return only the body from HttpResponse while upgrading from Micronaut 1.3.6 to 2.0.0

Task List

  • [ :heavy_check_mark:] Steps to reproduce provided
    start the server locally and call http://localhost:8080/bintray/packages
  • [âž– ] Stacktrace (if present) - Not applicable
  • [ :heavy_check_mark: ] Example that reproduces the problem uploaded to Github
    https://github.com/someshrathi02/micronaut_http_client
  • [ :heavy_check_mark:] Full description of the issue provided (see below Issue summary section)

Steps to Reproduce

Run the example Application from the https://github.com/someshrathi02/micronaut_http_client ( Sample example created using guide provided https://guides.micronaut.io/micronaut-http-client-kotlin/guide/index.html )

Expected Behaviour

In Micronaut 1.3.6 , when declarative client returns Single>> , REST Api's (defined in controller ) response only contains the json (as per below json ) which contains bintray api response.

[{"name":"base","linked":false},{"name":"federation","linked":false},{"name":"function","linked":false},{"name":"function-aws","linked":false},{"name":"service","linked":false},{"name":"cli","linked":false},{"name":"kafka","linked":false},{"name":"profile","linked":false},{"name":"function-aws-alexa","linked":false},{"name":"grpc","linked":false},{"name":"configuration","linked":false},{"name":"rabbitmq","linked":false}]

So same is expected when upgraded to 2.0.0 , i.e.

Actual Behaviour

After upgrading to micronaut 2.0.0 , i'm getting json response from service as below , which contains the 'status' , 'headers', 'body','nativeResponse' etc

{"status":"OK","headers":{"Server":"nginx","Date":"Tue, 28 Jul 2020 14:12:23 GMT","Content-Type":"application/json","Content-Length":"424","Connection":"close","Strict-Transport-Security":"max-age=0","X-Xss-Protection":"1; mode=block","X-Content-Type-Options":"nosniff","Referrer-Policy":"strict-origin-when-cross-origin","Content-Security-Policy":"default-src https: 'unsafe-inline' 'unsafe-eval'; font-src https: data:; img-src https: http: data:"},"body":[{"name":"base","linked":false},{"name":"federation","linked":false},{"name":"function","linked":false},{"name":"function-aws","linked":false},{"name":"service","linked":false},{"name":"cli","linked":false},{"name":"kafka","linked":false},{"name":"profile","linked":false},{"name":"function-aws-alexa","linked":false},{"name":"grpc","linked":false},{"name":"configuration","linked":false},{"name":"rabbitmq","linked":false}],"stream":false,"nativeResponse":{"protocolVersion":{"keepAliveDefault":true},"decoderResult":{"success":true,"failure":false,"finished":true}},"contentLength":424,"contentType":{"name":"application/json","subtype":"json","type":"application","extension":"json","textBased":true,"qualityAsNumber":1.0,"quality":"1.0"},"characterEncoding":"UTF-8"}

Environment Information

  • Operating System: Windows
  • Micronaut Version: 2.0.0 , kotlin - 1.3.72
  • JDK Version: jdk-11.0.3

Example Application

link to github repository with example that reproduces the issue as below
https://github.com/someshrathi02/micronaut_http_client

  • Issue summary

    • In Micronaut 1.3.6 , currently service response (i.e. HttpResponse) only contains the contents of the body key.
    • After upgrading to micronaut 2.0.0 , i'm getting json response from service as below , which contains the 'status' , 'headers', 'body','nativeResponse' etc.

    • I can get the body from response

    • using the rxjava map operator - just get the body key from complete Http Response
    • Change the signature of Declarative Http client to return Single instead of Single

    • However this need lot of refactoring in existing all the services implemented + unit test. Hence is there any easy option to just return the content of HttpResponse.body as json ? Are there any configurations which can be enabled/changed **

      After upgrading to 2.0.0 , response from service as below

{"status":"OK","headers":{"Server":"nginx","Date":"Tue, 28 Jul 2020 14:12:23 GMT","Content-Type":"application/json","Content-Length":"424","Connection":"close","Strict-Transport-Security":"max-age=0","X-Xss-Protection":"1; mode=block","X-Content-Type-Options":"nosniff","Referrer-Policy":"strict-origin-when-cross-origin","Content-Security-Policy":"default-src https: 'unsafe-inline' 'unsafe-eval'; font-src https: data:; img-src https: http: data:"},"body":[{"name":"base","linked":false},{"name":"federation","linked":false},{"name":"function","linked":false},{"name":"function-aws","linked":false},{"name":"service","linked":false},{"name":"cli","linked":false},{"name":"kafka","linked":false},{"name":"profile","linked":false},{"name":"function-aws-alexa","linked":false},{"name":"grpc","linked":false},{"name":"configuration","linked":false},{"name":"rabbitmq","linked":false}],"stream":false,"nativeResponse":{"protocolVersion":{"keepAliveDefault":true},"decoderResult":{"success":true,"failure":false,"finished":true}},"contentLength":424,"contentType":{"name":"application/json","subtype":"json","type":"application","extension":"json","textBased":true,"qualityAsNumber":1.0,"quality":"1.0"},"characterEncoding":"UTF-8"}
  • I'm using controller and Declarative http client as below :
@Controller("/bintray") // <1>
class BintrayController(private val bintrayLowLevelClient : BintrayLowLevelClient,  // <2>
                        private val bintrayClient: BintrayClient) {


    @Get(uri = "/packages")  // <5>
    internal fun packages(): Single<HttpResponse<List<BintrayPackage>>> {  // <6>
        return bintrayClient.fetchPackages()
    }
}


@Client(BintrayConfiguration.BINTRAY_URL) // <1>
interface BintrayClient {

    @Get("/api/\${bintray.apiversion}/repos/\${bintray.organization}/\${bintray.repository}/packages")  // <2>
    fun fetchPackages(): Single<HttpResponse<List<BintrayPackage>>>  // <3>
}
awaiting validation bug

Most helpful comment

@someshrathi02 You can use the 2.0.2.BUILD-SNAPSHOT build

All 7 comments

@graemerocher - May i request if this issue can be validated by micronaut team ? That will be really helpful.

@graemerocher /Micronaut team - Your help/advise will be very helpful on this issue.
Im facing above issue in project and we are trying to migrate from micronaut 1.3.6 to 2.0.0 and because of this not able to proceed further.

Currently away, will look at this when I get back next week unless @jameskleeh or someone else gets to it first

@graemerocher / @ilopmar Any updates on this please .

Thanks @jameskleeh and @graemerocher for looking into this issue and providing the solution.
When this fix will be available for me to test ?
I think its tagged to 2.0.2. , before that can i get some tag/branch release which I can test locally to see if it fixes my issue.

@someshrathi02 You can use the 2.0.2.BUILD-SNAPSHOT build

Thank you so much @jameskleeh. for providing the solution. I tried with 2.0.2.BUILD-SNAPSHOT and its working now. Thank you for working on it and providing an enhancement. Appreciate your time and attention on it.

Was this page helpful?
0 / 5 - 0 ratings