-
Notifications
You must be signed in to change notification settings - Fork 26.3k
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
[Feature][3.3] Triple rest jaxrs ParamConverter support #14148
base: 3.3
Are you sure you want to change the base?
Conversation
@oxsean PTAL |
@fanlobu Is it ready for review? |
I think it is ok, I did some simple tests in local |
import java.util.Map; | ||
|
||
@SuppressWarnings({"rawtypes"}) | ||
public class JaxrsParamConverter { |
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.
Suggest to rename to ParamConverterFactory, only one method getParamConverter is enough, and use the native java ServiceLoader instead of the reflection call dubbo ExtensionLoader to bypass the limitations
ParamConverter should be instantiated by using the ParamConverterProvider
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.
Need unit test for this.
@SuppressWarnings({"rawtypes"}) | ||
public class JaxrsParamConverter { | ||
|
||
private final Map<Pair<Class<?>, Class<?>>, ParamConverter> cacheConverter = CollectionUtils.newConcurrentHashMap(); |
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.
Rename to cache
Quality Gate passedIssues Measures |
ServiceLoader.load(ParamConverterProvider.class).forEach(providers::add); | ||
} | ||
|
||
public <T> ParamConverter getParamConverter(Class<T> rawType, Type genericType, Annotation[] annotations) { |
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's better use computeIfAbsent, and wrap value with Optional to cache null value
Example: https://github.com/apache/dubbo/blob/3.3/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/message/codec/CodecUtils.java
private final List<ParamConverterProvider> providers = new ArrayList<>(); | ||
|
||
ParamConverterFactory() { | ||
ServiceLoader.load(ParamConverterProvider.class).forEach(providers::add); |
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.
Please use iterator and try catch avoid individual SPI implementation loading failures from break the app, and log the context.
e.g.
ServiceLoader<MyService> loader = ServiceLoader.load(MyService.class);
Iterator<MyService> iterator = loader.iterator();
while (iterator.hasNext()) {
try {
MyService service = iterator.next();
...;
} catch (Throwable t) {
logger.error("Failed to load SPI: " + e.getMessage());
}
}
ParamConverter paramConverter = paramConverterFactory.getParamConverter( | ||
parameter.getType(), parameter.getGenericType(), parameter.getRealAnnotations()); | ||
if (paramConverter != null) { | ||
Class<?> type = TypeUtils.getSuperGenericType(paramConverter.getClass(), 0); |
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.
I think type checking is unnecessary. Matching types ensure by paramConverterFactory. For comparing String.class, you can use ==
directly
value.getClass() == String.class
What is the purpose of the change
Triple rest jaxrs ParamConverter support,related: #14037
Brief changelog
Verifying this change
Checklist