-
Notifications
You must be signed in to change notification settings - Fork 38.5k
Support dynamic default uri variables for RestClient #34190
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
Conversation
I'm declining this PR because I don't think we should take this approach to solve this problem. The I think this use case should be supported by |
It's safe for
Could you reopen #34189 or create new issue to address it officially? |
Another thought, introduce a subclass of UriComponentsBuilder ucb = UriComponentsBuilder.fromUriString("http://{partition}.163.com").acceptFunctions();
DefaultUriBuilderFactory uriBuilderFactory = new DefaultUriBuilderFactory(ucb);
uriBuilderFactory.setDefaultUriVariables(defaultUriVariables);
RestClient restClient = RestClient.builder().uriBuilderFactory(uriBuilderFactory).build(); WDYT @bclozel |
I meant that this should be already possible with an interceptor and a better for for this use case. |
I tried with RestClient restClient = RestClient.builder().baseUrl("http://{partition}.example.com")
.requestInterceptor(new ClientHttpRequestInterceptor() {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
ClientHttpRequestExecution execution) throws IOException {
return execution.execute(new HttpRequestWrapper(request) {
@Override
public URI getURI() {
return UriComponentsBuilder.fromUri(request.getURI())
.buildAndExpand(Map.of("partition", MDC.get("partition"))).toUri();
}
}, body);
}
}).build();
restClient.get().uri("/index.html").retrieve().body(String.class) It's not working, and not elegant, please rethink the solution I proposed.
|
I don't think the uri template should leave a path variable in. The interceptor should change the host instead. |
OK, it will works, but not elegant. @Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
return execution.execute(new HttpRequestWrapper(request) {
@Override
public URI getURI() {
return UriComponentsBuilder.fromUri(request.getURI()).host(MDC.get("partition") + "." + request.getURI().getHost()).build().toUri();
}
}, body);
} |
I'll discuss #34189 with the team. |
Sorry to disturb, any updates? |
Closes GH-34189