grails / grails-core

The Grails Web Application Framework
http://grails.org
Apache License 2.0
2.79k stars 950 forks source link

micronaut-http-client not configuration properties not working #12659

Open akiesh22 opened 2 years ago

akiesh22 commented 2 years ago

Issue description

I am new to the concept of micronaut-http-client and it's inner working. I have been following https://guides.grails.org/grails-micronaut-http/guide/index.html and https://docs.micronaut.io/latest/guide/#clientConfiguration. With these I am able to make a blocking http request to my service. However, I have tirelessly tried and failed to inject configuration via application.yml

micronaut:
    codec:
        json:
            additionalTypes:
                - text/javascript
    http:
        client:
            read-idle-timeout: 1m
            max-content-length: 10m
            read-timeout: 30s 
build.gradle
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    compileOnly "io.micronaut:micronaut-inject-groovy"
    console "org.grails:grails-console"
    implementation "org.springframework.boot:spring-boot-starter-logging"
    implementation "org.springframework.boot:spring-boot-starter-validation"
    implementation "org.springframework.boot:spring-boot-autoconfigure"
    implementation "org.grails:grails-core"
    implementation "org.springframework.boot:spring-boot-starter-actuator"
    implementation "org.springframework.boot:spring-boot-starter-tomcat"
    implementation "org.grails:grails-web-boot"
    implementation "org.grails:grails-logging"
    implementation "org.grails:grails-plugin-rest"
    implementation "org.grails:grails-plugin-codecs"
    implementation "org.grails:grails-plugin-databinding"
    implementation "org.grails:grails-plugin-i18n"
    implementation "org.grails:grails-plugin-services"
    implementation "org.grails:grails-plugin-url-mappings"
    implementation "org.grails:grails-plugin-interceptors"
//    implementation "org.grails:grails-plugin-services"
//    implementation "org.grails:grails-plugin-datasource"
//    implementation "org.grails:grails-plugin-databinding"
//    implementation "org.grails:grails-web-boot"
//    implementation "org.grails:grails-logging"
    implementation "org.grails.plugins:cache"
    implementation "org.grails.plugins:async"
    implementation "org.grails.plugins:scaffolding"
    implementation "org.grails.plugins:hibernate5"
    implementation "org.hibernate:hibernate-core:5.6.5.Final"
    implementation "org.grails.plugins:views-json"
    implementation "org.grails.plugins:views-json-templates"
//    profile "org.grails.profiles:react"
    implementation "org.grails.plugins:events"
    implementation "org.grails.plugins:gsp"
    profile "org.grails.profiles:web"
    runtimeOnly "org.glassfish.web:el-impl:2.2.1-b05"
    runtimeOnly "com.h2database:h2"
    runtimeOnly "org.apache.tomcat:tomcat-jdbc"
    runtimeOnly "javax.xml.bind:jaxb-api:2.3.1"
    runtimeOnly "com.bertramlabs.plugins:asset-pipeline-grails:3.3.4"
    testImplementation "org.grails:grails-gorm-testing-support"
    testImplementation "org.mockito:mockito-core"

    implementation("io.micronaut:micronaut-http-client")
    implementation("io.projectreactor:reactor-core:3.4.14")

code to make http blocking call

 def makeBlockingCall(requestFormat) {
        String baseUrl = Holders.config.grails.url
        HttpClient client = HttpClient.create(baseUrl.toURL())
        HttpRequest request = HttpRequest.POST(UriBuilder.of('/')
                .build(), requestFormat)
                .contentType(MediaType.APPLICATION_JSON)
                .header("client-id","xxx")
                .header("client-name","xxx")
                .header("ticket","xxx")

        def response = Mono.from(client.exchange(request, String))
                .block()
                .body()
        ObjectMapper objectMapper = new ObjectMapper()
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true)
        return objectMapper.readValue(response, ResponseFormat)
    }

When I make an http request as per the configuration the request doesn't wait until 30s before timing out but resorts to default always.

puneetbehl commented 2 years ago

Please mention the version of Grails with steps to replicate and details of the error. Thank you!

akiesh22 commented 2 years ago

grails-micronaut-http-master.zip

Please find the attachment, this is reproduced from https://guides.grails.org/grails-micronaut-http/guide/index.html.

As per the micronaut-http-document: https://docs.micronaut.io/latest/guide/#clientConfiguration, adding following configuration in application.yml file should load these configuration to http client. However the client is not respecting the configuration and always defaults to 10s.

The http client is defined in grails-micronaut-http-master/complete/grails-app/services/example/grails/ItuneSearchService.groovy.

Currently I am making request via url: http://localhost:8080/api/search?searchTerm=c. The end point in this case is just another grails app running in http://localhost:8090/. To replicate the behavior where the end point takes longer time to response I used intellij debugger.

micronaut:
  http:
    client:
      read-timeout: 5s

Please let me know if I can provide further information here.

akiesh22 commented 1 year ago

Is there any update on this? Am I missing something ?

puneetbehl commented 1 year ago

Thank you for sharing the sample application. I will look into this soon.