micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.05k stars 1.06k forks source link

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

Closed someshrathi02 closed 4 years ago

someshrathi02 commented 4 years ago

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

Task List

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<HttpResponse<List>> , 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

Example Application

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

@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>
}
someshrathi02 commented 4 years ago

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

someshrathi02 commented 4 years ago

@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.

graemerocher commented 4 years ago

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

someshrathi02 commented 4 years ago

@graemerocher / @ilopmar Any updates on this please .

someshrathi02 commented 4 years ago

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.

jameskleeh commented 4 years ago

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

someshrathi02 commented 4 years ago

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.