@SuppressWarnings("unchecked")
public void register(final Class<?> c) {
if (MessageBodyReader.class.isAssignableFrom(c)) {
readers.add((Class<MessageBodyReader<?>>) c, MediaTypeUtils.parseMediaTypes(c.getAnnotation(Consumes.class)));
}
if (MessageBodyWriter.class.isAssignableFrom(c)) {
writers.add((Class<MessageBodyWriter<?>>) c, MediaTypeUtils.parseMediaTypes(c.getAnnotation(Produces.class)));
}
if (ExceptionMapper.class.isAssignableFrom(c)) {
exceptionMappers.add((Class<ExceptionMapper<?>>) c, MediaTypeUtils.parseMediaTypes(c.getAnnotation(Produces.class)));
}
if (ParamConverterProvider.class.isAssignableFrom(c)) {
paramConverterProviders.add((ParamConverterProvider) application.get(c));
}
}
java类javax.ws.rs.ext.ParamConverterProvider的实例源码
MinijaxProviders.java 文件源码
项目:minijax
阅读 28
收藏 0
点赞 0
评论 0
AdditionalRegistrationTest.java 文件源码
项目:microprofile-rest-client
阅读 21
收藏 0
点赞 0
评论 0
@Test
public void shouldRegisterAMultiTypedProviderInstanceWithPriorities() {
MultiTypedProvider provider = new MultiTypedProvider();
Map<Class<?>, Integer> priorities = new HashMap<>();
priorities.put(ClientRequestFilter.class, 500);
priorities.put(ClientResponseFilter.class, 501);
priorities.put(MessageBodyReader.class, 502);
priorities.put(MessageBodyWriter.class, 503);
priorities.put(ReaderInterceptor.class, 504);
priorities.put(WriterInterceptor.class, 505);
priorities.put(ResponseExceptionMapper.class, 506);
priorities.put(ParamConverterProvider.class, 507);
RestClientBuilder builder = RestClientBuilder.newBuilder().register(provider, priorities);
Configuration configuration = builder.getConfiguration();
assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered");
assertTrue(configuration.isRegistered(provider), MultiTypedProvider.class + " should be registered");
Map<Class<?>, Integer> contracts = configuration.getContracts(MultiTypedProvider.class);
assertEquals(contracts.size(), priorities.size(),
"There should be "+priorities.size()+" provider types registered");
for(Map.Entry<Class<?>, Integer> priority : priorities.entrySet()) {
Integer contractPriority = contracts.get(priority.getKey());
assertEquals(contractPriority, priority.getValue(), "The priority for "+priority.getKey()+" should be "+priority.getValue());
}
}
AdditionalRegistrationTest.java 文件源码
项目:microprofile-rest-client
阅读 25
收藏 0
点赞 0
评论 0
@Test
public void shouldRegisterAMultiTypedProviderClassWithPriorities() {
Map<Class<?>, Integer> priorities = new HashMap<>();
priorities.put(ClientRequestFilter.class, 500);
priorities.put(ClientResponseFilter.class, 501);
priorities.put(MessageBodyReader.class, 502);
priorities.put(MessageBodyWriter.class, 503);
priorities.put(ReaderInterceptor.class, 504);
priorities.put(WriterInterceptor.class, 505);
priorities.put(ResponseExceptionMapper.class, 506);
priorities.put(ParamConverterProvider.class, 507);
RestClientBuilder builder = RestClientBuilder.newBuilder().register(MultiTypedProvider.class, priorities);
Configuration configuration = builder.getConfiguration();
assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered");
Map<Class<?>, Integer> contracts = configuration.getContracts(MultiTypedProvider.class);
assertEquals(contracts.size(), priorities.size(),
"There should be "+priorities.size()+" provider types registered");
for(Map.Entry<Class<?>, Integer> priority : priorities.entrySet()) {
Integer contractPriority = contracts.get(priority.getKey());
assertEquals(contractPriority, priority.getValue(), "The priority for "+priority.getKey()+" should be "+priority.getValue());
}
}
RsAddonFeature.java 文件源码
项目:ameba
阅读 22
收藏 0
点赞 0
评论 0
@Override
protected void configure() {
bind(OptionsMethodProcessor.DefaultOptionsResponseGenerator.class)
.to(OptionsResponseGenerator.class)
.in(Singleton.class);
bind(OptionsMethodProcessor.class)
.to(ModelProcessor.class)
.in(Singleton.class);
bind(ParamConverters.TypeFromStringEnum.class)
.to(ParamConverterProvider.class)
.in(Singleton.class).ranked(10);
bind(ParamConverters.DateProvider.class)
.to(ParamConverterProvider.class)
.in(Singleton.class).ranked(10);
bind(ParamConverters.BooleanProvider.class)
.to(ParamConverterProvider.class)
.in(Singleton.class).ranked(10);
}
MinijaxProviders.java 文件源码
项目:minijax
阅读 31
收藏 0
点赞 0
评论 0
public <T> ParamConverter<T> getParamConverter(final Class<T> rawType, final Type genericType, final Annotation[] annotations) {
for (final ParamConverterProvider provider : paramConverterProviders) {
final ParamConverter<T> converter = provider.getConverter(rawType, genericType, annotations);
if (converter != null) {
return converter;
}
}
return null;
}
AdditionalRegistrationTest.java 文件源码
项目:microprofile-rest-client
阅读 24
收藏 0
点赞 0
评论 0
@Test
public void shouldRegisterAMultiTypedProviderInstance() {
MultiTypedProvider provider = new MultiTypedProvider();
Class[] providerTypes = {ClientRequestFilter.class, ClientResponseFilter.class,
MessageBodyReader.class, MessageBodyWriter.class, ReaderInterceptor.class, WriterInterceptor.class,
ResponseExceptionMapper.class, ParamConverterProvider.class};
RestClientBuilder builder = RestClientBuilder.newBuilder().register(provider, providerTypes);
Configuration configuration = builder.getConfiguration();
assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered");
assertTrue(configuration.isRegistered(provider), MultiTypedProvider.class + " should be registered");
assertEquals(configuration.getContracts(MultiTypedProvider.class).size(), providerTypes.length,
"There should be "+providerTypes.length+" provider types registered");
}
AdditionalRegistrationTest.java 文件源码
项目:microprofile-rest-client
阅读 25
收藏 0
点赞 0
评论 0
@Test
public void shouldRegisterAMultiTypedProviderClass() {
Class[] providerTypes = {ClientRequestFilter.class, ClientResponseFilter.class,
MessageBodyReader.class, MessageBodyWriter.class, ReaderInterceptor.class, WriterInterceptor.class,
ResponseExceptionMapper.class, ParamConverterProvider.class};
RestClientBuilder builder = RestClientBuilder.newBuilder().register(MultiTypedProvider.class, providerTypes);
Configuration configuration = builder.getConfiguration();
assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered");
assertEquals(configuration.getContracts(MultiTypedProvider.class).size(), providerTypes.length,
"There should be "+providerTypes.length+" provider types registered");
}
RESTService.java 文件源码
项目:tomee
阅读 26
收藏 0
点赞 0
评论 0
private static <T> boolean isProvider(final Class<T> clazz) {
return MessageBodyReader.class.isAssignableFrom(clazz) ||
MessageBodyWriter.class.isAssignableFrom(clazz) ||
ParamConverter.class.isAssignableFrom(clazz) ||
ContainerRequestFilter.class.isAssignableFrom(clazz) ||
ContainerResponseFilter.class.isAssignableFrom(clazz) ||
ReaderInterceptor.class.isAssignableFrom(clazz) ||
WriterInterceptor.class.isAssignableFrom(clazz) ||
ParamConverterProvider.class.isAssignableFrom(clazz) ||
ContextResolver.class.isAssignableFrom(clazz) ||
new MetaAnnotatedClass<>(clazz).isAnnotationPresent(Provider.class);
}
OptionParamBinder.java 文件源码
项目:dropwizard-vavr
阅读 22
收藏 0
点赞 0
评论 0
@Override
protected void configure() {
// Param converter providers
bind(OptionParamConverterProvider.class).to(ParamConverterProvider.class).in(Singleton.class);
}
LazyParamBinder.java 文件源码
项目:dropwizard-vavr
阅读 24
收藏 0
点赞 0
评论 0
@Override
protected void configure() {
// Param converter providers
bind(LazyParamConverterProvider.class).to(ParamConverterProvider.class).in(Singleton.class);
}
MinijaxProviders.java 文件源码
项目:minijax
阅读 25
收藏 0
点赞 0
评论 0
private static List<ParamConverterProvider> getDefaultParamConverterProviders() {
return Collections.singletonList(new UuidParamConverterProvider());
}
SisuResteasyProviderFactory.java 文件源码
项目:nexus-public
阅读 19
收藏 0
点赞 0
评论 0
/**
* Unregisters a @Provider type from this factory.
*/
public void removeRegistrations(final Class<?> type) {
checkNotNull(type);
log.debug("Removing registrations for: {}", type.getName());
classContracts.remove(type);
removeInstancesOf(type, providerInstances);
providerClasses.remove(type);
if (ExceptionMapper.class.isAssignableFrom(type)) {
removeInstancesOf(type, exceptionMappers.values());
}
else if (MessageBodyReader.class.isAssignableFrom(type)) {
clearInstancesOf(type, clientMessageBodyReaders, DUMMY_READER);
clearInstancesOf(type, serverMessageBodyReaders, DUMMY_READER);
}
else if (MessageBodyWriter.class.isAssignableFrom(type)) {
clearInstancesOf(type, clientMessageBodyWriters, DUMMY_WRITER);
clearInstancesOf(type, serverMessageBodyWriters, DUMMY_WRITER);
}
else if (ContextResolver.class.isAssignableFrom(type)) {
Type[] args = Types.getActualTypeArgumentsOfAnInterface(type, ContextResolver.class);
contextResolvers.remove(Types.getRawType(args[0]));
}
else if (Feature.class.isAssignableFrom(type)) {
removeInstancesOf(type, featureInstances);
removeInstancesOf(type, enabledFeatures);
featureClasses.remove(type);
}
else if (DynamicFeature.class.isAssignableFrom(type)) {
removeInstancesOf(type, clientDynamicFeatures);
removeInstancesOf(type, serverDynamicFeatures);
}
else if (ParamConverterProvider.class.isAssignableFrom(type)) {
removeInstancesOf(type, paramConverterProviders);
}
else if (StringConverter.class.isAssignableFrom(type)) {
removeInstancesOf(type, stringConverters.values());
}
else if (StringParameterUnmarshaller.class.isAssignableFrom(type)) {
stringParameterUnmarshallers.values().remove(type);
}
else {
log.warn("Unable to remove registrations for: {}", type.getName());
}
}
OptionalParamBinder.java 文件源码
项目:dropwizard-java8
阅读 23
收藏 0
点赞 0
评论 0
@Override
protected void configure() {
// Param converter providers
bind(OptionalParamConverterProvider.class).to(ParamConverterProvider.class).in(Singleton.class);
}