-
Notifications
You must be signed in to change notification settings - Fork 827
[JAV-147]RestTemplate支持扩展 #57
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
*/ | ||
public class RestTemplateWrapper extends RestTemplate { | ||
private static RestTemplate cseRestTemplate = new CseRestTemplate(); | ||
private static List<AcceptableRestTemplate> acceptableRestTemplates = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a better design is to declare default rest template and avoid null checking all together
class RestTemplateWrapper implements RestOperations {
private static final RestTemplate defaultTemplate = new RestTemplate();
private static List<AcceptableRestTemplate> acceptableRestTemplates = asList(new CseRestTemplate());
private RestTemplate getRestTemplate(String url) {
for (AcceptableRestTemplate template : acceptableRestTemplates) {
if (template.isAcceptable(url)) {
return template;
}
}
return defaultTemplate;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and i don't understand why these methods need to be static. we have way too many static classes/methods. this kind of programming model creates tons of tight coupling.
RestTemplate template = RestTemplateBuilder.create(); | ||
try { | ||
template.delete("http://test"); | ||
Assert.assertFalse(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test only covers the happy path. what about no acceptable rest template found?
try { | ||
template.delete("cse://test/a/b/c"); | ||
Assert.assertFalse(true); | ||
} catch (NullPointerException e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be better if we can wrap the NPE with some kind of Runtime exception.
No description provided.