Giter Site home page Giter Site logo

Comments (5)

scottfrederick avatar scottfrederick commented on May 23, 2024

None of Spring Boot's built-in request factory implementations (HttpComponentsClientHttpRequestFactory, JettyClientHttpRequestFactory, JdkClientHttpRequestFactory, SimpleClientHttpRequestFactory, OkHttp3ClientHttpRequestFactory) use this Reflective class for setting properties. When Jetty is being used for the client connection, the read timeout is set here using the Jetty setReadTimeout method that takes a long:

map.from(settings::readTimeout).asInt(Duration::toMillis).to(requestFactory::setReadTimeout);

If you are somehow jave a ClientHttpRequestFactory implementation with Jetty that goes through the Reflective code path, can you show us an example of what you're doing?

from spring-boot.

fml2 avatar fml2 commented on May 23, 2024

Yes, I do have such a path. We create a RestTemplate using the RestTemplateBuilder. We'd like every request sent by the template to be wrapped by a BufferingRequest (in order to be able to log the request before it's sent), but the nested request should be created as configured by other factories. Hence we use this:

restTemplateBuilder
    .requestFactory(() ->
        new BufferingClientHttpRequestFactory(ClientHttpRequestFactories.get(ClientHttpRequestFactorySettings.DEFAULTS)))

This form of the "requestFactory" method uses Reflective.

from spring-boot.

mhalbritter avatar mhalbritter commented on May 23, 2024

Reproducer here: sb-40635.zip

Works with Boot 3.1.x, fails with 3.2.x and 3.3.x:

java.lang.IllegalStateException: Request factory org.springframework.http.client.JettyClientHttpRequestFactory does not have a suitable setReadTimeout method
	at org.springframework.util.Assert.state(Assert.java:97) ~[spring-core-6.1.6.jar:6.1.6]
	at org.springframework.boot.web.client.ClientHttpRequestFactories$Reflective.findMethod(ClientHttpRequestFactories.java:402) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.springframework.boot.web.client.ClientHttpRequestFactories$Reflective.setReadTimeout(ClientHttpRequestFactories.java:394) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.springframework.boot.web.client.ClientHttpRequestFactories$Reflective.lambda$configure$1(ClientHttpRequestFactories.java:369) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.springframework.boot.context.properties.PropertyMapper$Source.to(PropertyMapper.java:294) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.springframework.boot.web.client.ClientHttpRequestFactories$Reflective.configure(ClientHttpRequestFactories.java:369) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.springframework.boot.web.client.ClientHttpRequestFactories$Reflective.get(ClientHttpRequestFactories.java:360) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.springframework.boot.web.client.ClientHttpRequestFactories.get(ClientHttpRequestFactories.java:168) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.springframework.boot.web.client.RestTemplateBuilder.lambda$requestFactory$1(RestTemplateBuilder.java:320) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.springframework.boot.web.client.RestTemplateBuilder.buildRequestFactory(RestTemplateBuilder.java:659) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.springframework.boot.web.client.RestTemplateBuilder.configure(RestTemplateBuilder.java:625) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.springframework.boot.web.client.RestTemplateBuilder.build(RestTemplateBuilder.java:600) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.example.sb40635.CLR.run(CLR.java:31) ~[main/:na]
	at org.springframework.boot.SpringApplication.lambda$callRunner$5(SpringApplication.java:790) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.springframework.util.function.ThrowingConsumer$1.acceptWithException(ThrowingConsumer.java:83) ~[spring-core-6.1.6.jar:6.1.6]
	at org.springframework.util.function.ThrowingConsumer.accept(ThrowingConsumer.java:60) ~[spring-core-6.1.6.jar:6.1.6]
	at org.springframework.util.function.ThrowingConsumer$1.accept(ThrowingConsumer.java:88) ~[spring-core-6.1.6.jar:6.1.6]
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:798) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:789) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.springframework.boot.SpringApplication.lambda$callRunners$3(SpringApplication.java:774) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) ~[na:na]
	at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:357) ~[na:na]
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510) ~[na:na]
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[na:na]
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) ~[na:na]
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) ~[na:na]
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:na]
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596) ~[na:na]
	at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:774) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:341) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1354) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-3.3.0-RC1.jar:3.3.0-RC1]
	at org.example.sb40635.Sb40635Application.main(Sb40635Application.java:10) ~[main/:na]

from spring-boot.

mhalbritter avatar mhalbritter commented on May 23, 2024

The ClientHttpRequestFactory we support have the following signatures:

HttpComponentsClientHttpRequestFactory

  • setConnectTimeout int
  • setConnectTimeout Duration
  • no setReadTimeout

JettyClientHttpRequestFactory

  • setConnectTimeout int
  • setConnectTimeout Duration
  • setReadTimeout Duration
  • setReadTimeout long

JdkClientHttpRequestFactory

  • no setConnectTimeout
  • setReadTimeout Duration
  • setReadTimeout int

SimpleClientHttpRequestFactory

  • setConnectTimeout int
  • setConnectTimeout Duration
  • setReadTimeout Duration
  • setReadTimeout int

OkHttp3ClientHttpRequestFactory

  • setConnectTimeout int
  • setConnectTimeout Duration
  • setReadTimeout Duration
  • setReadTimeout int

We can fix this bei either preferring the Duration accepting methods or by getting the setReadTimeout fixed in JettyClientHttpRequestFactory to also accept an integer.

We currently assume in the Reflective class that the int methods accept milliseconds:

int timeout = Math.toIntExact(readTimeout.toMillis());

I think preferring the Duration accepting methods would be the better fix.

from spring-boot.

fml2 avatar fml2 commented on May 23, 2024

We currently assume in the Reflective class that the int methods accept milliseconds

I'd also search for a method with a long parameter since this type is often used for expressing periods in milliseconds.

from spring-boot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.