-
Notifications
You must be signed in to change notification settings - Fork 40.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TestRestTemplate replaces custom HttpClients #8697
Comments
Yeah, that's a bit nasty. You might be able to change it back afterwards until we can find a better fix: RestTemplate rt = new RestTemplate();
TestRestTemplate trt = new TestRestTemplate(rt);
rt.setRequestFactory(...); |
That's true! I did not think of that way to undo it. Thanks a lot. |
It really is tricky and I think the current code is a bit wrong but I can't see a way to fix it without breaking backward compat. So one thing we could do is check if there are any If we do that, I don't know at this point if those inconsistencies are made on purpose but surely deviating from |
Along these lines, I'm having difficulty with redirects in I hunted for some way to customize the injected The current docs say An example: (See https://github.com/binkley/sproingk/blob/49456e50eb3c855ea6b284b9565337d593b63994/src/test/kotlin/hm/binkley/labs/GreetingControllerIT.kt#L140 and remove the |
@binkley That sounds like a separate problem. Can you please open a new issue? AFAIK, both 1.5.3.RELEASE and 2.0.0.M1 will not follow a redirect as long as you have Apache's HTTP client on the class path. |
@wilkinsona OK, filed #9410. I do not explicitly ask for Apache HTTP client in my classpath, relying on Spring Boot starter to handle this. |
Maybe I'm missing something here, but #11872 removed all |
No, it's still there. The private constructor will clobber any request factory that was configured via a |
So, the TL;DR; is to use a new builder in the new release? |
Yes, we've removed all constructors accepting a |
This commit fixes two issues in `TestRestTemplate`: * it improves the detection of the underlying request factory, using reflection to look inside the intercepting request factory if interceptors were configured * it avoids reusing the same request factory when creating a new `TestRestTemplate` with `withBasicAuth`. Sharing the same instance would result in sharing authentication state (HTTP cookies). Since the original request factory can't be detected consistently, a new one is selected automatically See gh-8697
Am I right in assuming this issue was not resolved for 1.5.X? Autowiring |
@bvulaj Unfortunately we needed to introduce a breaking change so 2.0 was the only option. |
@philwebb Understood. Will use the workaround for now. Thanks for the response. |
Spring-Boot version 1.5.2.RELEASE
Problem:
When apache httpclient jar is in the classpath, TestRestTemplate replaces any HttpClient set by the user in a RestTemplate. Alseo, since the field is final there's no way to change that, even with reflection.
See this https://github.com/spring-projects/spring-boot/blob/master/spring-boot-test/src/main/java/org/springframework/boot/test/web/client/TestRestTemplate.java#L127-L130.
In my case, I am building a client for mutual authentication and some headers. However, the same applications uses httpclient for other integrations, not only that, previous tests were written in RestAssured which also includes that dependency.
Is it possible to remove that validation, make it optional or just apply it if there's no
requestFactory
set?The text was updated successfully, but these errors were encountered: