use of jakarta.ws.rs.ConstrainedTo in project resteasy by resteasy.
the class ServerHelper method processProviderInstanceContracts.
protected void processProviderInstanceContracts(Object provider, Map<Class<?>, Integer> contracts, Integer priorityOverride, boolean builtIn, Map<Class<?>, Integer> newContracts) {
ConstrainedTo constrainedTo = (ConstrainedTo) provider.getClass().getAnnotation(ConstrainedTo.class);
if (constrainedTo != null && constrainedTo.value() != RuntimeType.SERVER)
return;
super.processProviderInstanceContracts(provider, contracts, priorityOverride, builtIn, newContracts);
if (Utils.isA(provider, ContainerRequestFilter.class, contracts)) {
int priority = Utils.getPriority(priorityOverride, contracts, ContainerRequestFilter.class, provider.getClass());
JaxrsInterceptorRegistry<ContainerRequestFilter> registry = getRequestFiltersForWrite();
registry.registerSingleton((ContainerRequestFilter) provider, priority);
attachedRequestFilters = false;
requestFilters = registry;
newContracts.put(ContainerRequestFilter.class, priority);
}
if (Utils.isA(provider, ContainerResponseFilter.class, contracts)) {
int priority = Utils.getPriority(priorityOverride, contracts, ContainerResponseFilter.class, provider.getClass());
JaxrsInterceptorRegistry<ContainerResponseFilter> registry = getResponseFiltersForWrite();
registry.registerSingleton((ContainerResponseFilter) provider, priority);
attachedResponseFilters = false;
responseFilters = registry;
newContracts.put(ContainerResponseFilter.class, priority);
}
if (Utils.isA(provider, AsyncResponseProvider.class, contracts)) {
try {
addAsyncResponseProvider((AsyncResponseProvider) provider, provider.getClass());
int priority = Utils.getPriority(priorityOverride, contracts, AsyncResponseProvider.class, provider.getClass());
newContracts.put(AsyncResponseProvider.class, priority);
} catch (Exception e) {
throw new RuntimeException(Messages.MESSAGES.unableToInstantiateAsyncResponseProvider(), e);
}
}
if (Utils.isA(provider, AsyncStreamProvider.class, contracts)) {
try {
addAsyncStreamProvider((AsyncStreamProvider) provider, provider.getClass());
int priority = Utils.getPriority(priorityOverride, contracts, AsyncStreamProvider.class, provider.getClass());
newContracts.put(AsyncStreamProvider.class, priority);
} catch (Exception e) {
throw new RuntimeException(Messages.MESSAGES.unableToInstantiateAsyncStreamProvider(), e);
}
}
if (Utils.isA(provider, ExceptionMapper.class, contracts)) {
try {
addExceptionMapper((ExceptionMapper) provider, provider.getClass(), builtIn);
int priority = Utils.getPriority(priorityOverride, contracts, ExceptionMapper.class, provider.getClass());
newContracts.put(ExceptionMapper.class, priority);
} catch (Exception e) {
throw new RuntimeException(Messages.MESSAGES.unableToInstantiateExceptionMapper(), e);
}
}
}
use of jakarta.ws.rs.ConstrainedTo in project resteasy by resteasy.
the class ClientHelper method processProviderInstanceContracts.
protected void processProviderInstanceContracts(Object provider, Map<Class<?>, Integer> contracts, Integer priorityOverride, boolean builtIn, Map<Class<?>, Integer> newContracts) {
ConstrainedTo constrainedTo = (ConstrainedTo) provider.getClass().getAnnotation(ConstrainedTo.class);
if (constrainedTo != null && constrainedTo.value() != RuntimeType.CLIENT)
return;
super.processProviderInstanceContracts(provider, contracts, priorityOverride, builtIn, newContracts);
if (Utils.isA(provider, ClientRequestFilter.class, contracts)) {
int priority = Utils.getPriority(priorityOverride, contracts, ClientRequestFilter.class, provider.getClass());
JaxrsInterceptorRegistry<ClientRequestFilter> registry = getRequestFiltersForWrite();
Utils.injectProperties(rpf, provider);
registry.registerSingleton((ClientRequestFilter) provider, priority);
attachedRequestFilters = false;
requestFilters = registry;
newContracts.put(ClientRequestFilter.class, priority);
}
if (Utils.isA(provider, ClientResponseFilter.class, contracts)) {
int priority = Utils.getPriority(priorityOverride, contracts, ClientResponseFilter.class, provider.getClass());
JaxrsInterceptorRegistry<ClientResponseFilter> registry = getResponseFiltersForWrite();
Utils.injectProperties(rpf, provider);
registry.registerSingleton((ClientResponseFilter) provider, priority);
attachedResponseFilters = false;
responseFilters = registry;
newContracts.put(ClientResponseFilter.class, priority);
}
if (Utils.isA(provider, AsyncClientResponseProvider.class, contracts)) {
try {
addAsyncClientResponseProvider((AsyncClientResponseProvider) provider, provider.getClass());
int priority = Utils.getPriority(priorityOverride, contracts, AsyncClientResponseProvider.class, provider.getClass());
newContracts.put(AsyncClientResponseProvider.class, priority);
} catch (Exception e) {
throw new RuntimeException(Messages.MESSAGES.unableToInstantiateAsyncClientResponseProvider(), e);
}
}
}
use of jakarta.ws.rs.ConstrainedTo in project resteasy by resteasy.
the class ClientHelper method processProviderContracts.
protected void processProviderContracts(Class provider, Integer priorityOverride, boolean isBuiltin, Map<Class<?>, Integer> contracts, Map<Class<?>, Integer> newContracts) {
ConstrainedTo constrainedTo = (ConstrainedTo) provider.getAnnotation(ConstrainedTo.class);
if (constrainedTo != null && constrainedTo.value() != RuntimeType.CLIENT)
return;
super.processProviderContracts(provider, priorityOverride, isBuiltin, contracts, newContracts);
if (Utils.isA(provider, ClientRequestFilter.class, contracts)) {
int priority = Utils.getPriority(priorityOverride, contracts, ClientRequestFilter.class, provider);
Utils.injectProperties(rpf, provider);
addClientRequestFilter(provider, priority);
newContracts.put(ClientRequestFilter.class, priority);
}
if (Utils.isA(provider, ClientResponseFilter.class, contracts)) {
int priority = Utils.getPriority(priorityOverride, contracts, ClientResponseFilter.class, provider);
Utils.injectProperties(rpf, provider);
addClientResponseFilter(provider, priority);
newContracts.put(ClientResponseFilter.class, priority);
}
if (Utils.isA(provider, AsyncClientResponseProvider.class, contracts)) {
try {
addAsyncClientResponseProvider(provider);
newContracts.put(AsyncClientResponseProvider.class, Utils.getPriority(priorityOverride, contracts, AsyncClientResponseProvider.class, provider));
} catch (Exception e) {
throw new RuntimeException(Messages.MESSAGES.unableToInstantiateAsyncClientResponseProvider(), e);
}
}
if (Utils.isA(provider, RxInvokerProvider.class, contracts)) {
int priority = Utils.getPriority(priorityOverride, contracts, RxInvokerProvider.class, provider);
newContracts.put(RxInvokerProvider.class, priority);
addReactiveClass(provider);
}
}
use of jakarta.ws.rs.ConstrainedTo in project resteasy by resteasy.
the class ResteasyProviderFactoryImpl method processProviderContracts.
private void processProviderContracts(Class provider, Integer priorityOverride, boolean isBuiltin, Map<Class<?>, Integer> contracts, Map<Class<?>, Integer> newContracts) {
clientHelper.processProviderContracts(provider, priorityOverride, isBuiltin, contracts, newContracts);
serverHelper.processProviderContracts(provider, priorityOverride, isBuiltin, contracts, newContracts);
if (Utils.isA(provider, ParamConverterProvider.class, contracts)) {
int priority = Utils.getPriority(priorityOverride, contracts, ParamConverterProvider.class, provider);
addParameterConverterProvider(provider, isBuiltin, priority);
newContracts.put(ParamConverterProvider.class, priority);
}
if (Utils.isA(provider, ContextResolver.class, contracts)) {
try {
int priority = Utils.getPriority(priorityOverride, contracts, ContextResolver.class, provider);
addContextResolver(provider, isBuiltin, priority);
newContracts.put(ContextResolver.class, priority);
} catch (Exception e) {
throw new RuntimeException(Messages.MESSAGES.unableToInstantiateContextResolver(), e);
}
}
if (Utils.isA(provider, ContextInjector.class, contracts)) {
try {
addContextInjector(provider);
int priority = Utils.getPriority(priorityOverride, contracts, ContextInjector.class, provider);
newContracts.put(ContextInjector.class, priority);
} catch (Exception e) {
throw new RuntimeException(Messages.MESSAGES.unableToInstantiateContextInjector(), e);
}
}
if (Utils.isA(provider, StringParameterUnmarshaller.class, contracts)) {
addStringParameterUnmarshaller(provider);
int priority = Utils.getPriority(priorityOverride, contracts, StringParameterUnmarshaller.class, provider);
newContracts.put(StringParameterUnmarshaller.class, priority);
}
if (Utils.isA(provider, InjectorFactory.class, contracts)) {
try {
addInjectorFactory(provider);
newContracts.put(InjectorFactory.class, 0);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
if (Utils.isA(provider, Feature.class, contracts)) {
ConstrainedTo constrainedTo = (ConstrainedTo) provider.getAnnotation(ConstrainedTo.class);
int priority = Utils.getPriority(priorityOverride, contracts, Feature.class, provider);
if (constrainedTo == null || constrainedTo.value() == getRuntimeType()) {
addFeature(provider);
}
newContracts.put(Feature.class, priority);
}
if (Utils.isA(provider, ResourceClassProcessor.class, contracts)) {
int priority = Utils.getPriority(priorityOverride, contracts, ResourceClassProcessor.class, provider);
addResourceClassProcessor(provider, priority);
newContracts.put(ResourceClassProcessor.class, priority);
}
if (Utils.isA(provider, HeaderDelegate.class, contracts)) {
addHeaderDelegate(provider);
}
if (Utils.isA(provider, ThreadContext.class, contracts)) {
ResteasyContext.computeIfAbsent(ThreadContexts.class, ThreadContexts::new).add(createProviderInstance((Class<? extends ThreadContext>) provider));
}
}
use of jakarta.ws.rs.ConstrainedTo in project resteasy by resteasy.
the class ResteasyProviderFactoryImpl method processProviderInstanceContracts.
private void processProviderInstanceContracts(Object provider, Map<Class<?>, Integer> contracts, Integer priorityOverride, boolean builtIn, Map<Class<?>, Integer> newContracts) {
clientHelper.processProviderInstanceContracts(provider, contracts, priorityOverride, builtIn, newContracts);
serverHelper.processProviderInstanceContracts(provider, contracts, priorityOverride, builtIn, newContracts);
if (Utils.isA(provider, ParamConverterProvider.class, contracts)) {
injectProperties(provider);
int priority = Utils.getPriority(priorityOverride, contracts, ParamConverterProvider.class, provider.getClass());
copyParamConvertsIfNeeded();
sortedParamConverterProviders.add(new ExtSortedKey<>(null, (ParamConverterProvider) provider, provider.getClass(), priority, builtIn));
newContracts.put(ParamConverterProvider.class, priority);
}
if (Utils.isA(provider, ContextResolver.class, contracts)) {
try {
int priority = Utils.getPriority(priorityOverride, contracts, ContextResolver.class, provider.getClass());
addContextResolver((ContextResolver) provider, priority, provider.getClass(), false);
newContracts.put(ContextResolver.class, priority);
} catch (Exception e) {
throw new RuntimeException(Messages.MESSAGES.unableToInstantiateContextResolver(), e);
}
}
if (Utils.isA(provider, ContextInjector.class, contracts)) {
try {
addContextInjector((ContextInjector) provider, provider.getClass());
int priority = Utils.getPriority(priorityOverride, contracts, ContextInjector.class, provider.getClass());
newContracts.put(ContextInjector.class, priority);
} catch (Exception e) {
throw new RuntimeException(Messages.MESSAGES.unableToInstantiateContextInjector(), e);
}
}
if (Utils.isA(provider, InjectorFactory.class, contracts)) {
this.injectorFactory = (InjectorFactory) provider;
newContracts.put(InjectorFactory.class, 0);
}
if (Utils.isA(provider, Feature.class, contracts)) {
Feature feature = (Feature) provider;
Utils.injectProperties(this, provider.getClass(), provider);
ConstrainedTo constrainedTo = (ConstrainedTo) provider.getClass().getAnnotation(ConstrainedTo.class);
if (constrainedTo == null || constrainedTo.value() == getRuntimeType()) {
if (feature.configure(new FeatureContextDelegate(this))) {
enabledFeatures.add(feature);
}
}
int priority = Utils.getPriority(priorityOverride, contracts, Feature.class, provider.getClass());
newContracts.put(Feature.class, priority);
}
if (Utils.isA(provider, ResourceClassProcessor.class, contracts)) {
int priority = Utils.getPriority(priorityOverride, contracts, ResourceClassProcessor.class, provider.getClass());
addResourceClassProcessor((ResourceClassProcessor) provider, priority);
newContracts.put(ResourceClassProcessor.class, priority);
}
if (Utils.isA(provider, HeaderDelegate.class, contracts)) {
Type[] headerTypes = Types.getActualTypeArgumentsOfAnInterface(provider.getClass(), HeaderDelegate.class);
if (headerTypes.length == 0) {
LogMessages.LOGGER.cannotRegisterheaderDelegate(provider.getClass());
} else {
Class<?> headerClass = Types.getRawType(headerTypes[0]);
addHeaderDelegate(headerClass, (HeaderDelegate) provider);
}
}
if (Utils.isA(provider, ThreadContext.class, contracts)) {
ResteasyContext.computeIfAbsent(ThreadContexts.class, ThreadContexts::new).add((ThreadContext<?>) provider);
}
}
Aggregations