Search in sources :

Example 1 with ParamConverterProvider

use of jakarta.ws.rs.ext.ParamConverterProvider in project resteasy by resteasy.

the class ResteasyProviderFactoryImpl method addParameterConverterProvider.

public void addParameterConverterProvider(Class provider, boolean isBuiltin, int priority) {
    ParamConverterProvider paramConverterProvider = (ParamConverterProvider) injectedInstance(provider);
    injectProperties(provider);
    copyParamConvertsIfNeeded();
    sortedParamConverterProviders.add(new ExtSortedKey<>(null, paramConverterProvider, provider, priority, isBuiltin));
}
Also used : ParamConverterProvider(jakarta.ws.rs.ext.ParamConverterProvider)

Example 2 with ParamConverterProvider

use of jakarta.ws.rs.ext.ParamConverterProvider in project quarkus by quarkusio.

the class QuarkusRestClientBuilder method register.

@Override
public RestClientBuilder register(Object o, int i) {
    if (o instanceof ResponseExceptionMapper) {
        // local
        ResponseExceptionMapper mapper = (ResponseExceptionMapper) o;
        HashMap<Class<?>, Integer> contracts = new HashMap<>();
        contracts.put(ResponseExceptionMapper.class, i);
        registerLocalProviderInstance(mapper, contracts);
        // delegate
        builderDelegate.register(mapper, i);
    } else if (o instanceof ParamConverterProvider) {
        // local
        ParamConverterProvider converter = (ParamConverterProvider) o;
        HashMap<Class<?>, Integer> contracts = new HashMap<>();
        contracts.put(ParamConverterProvider.class, i);
        registerLocalProviderInstance(converter, contracts);
        // delegate
        builderDelegate.register(converter, i);
    } else if (o instanceof AsyncInvocationInterceptorFactory) {
        invocationInterceptorFactories.add((AsyncInvocationInterceptorFactory) o);
    } else {
        builderDelegate.register(o, i);
    }
    return this;
}
Also used : HashMap(java.util.HashMap) ResponseExceptionMapper(org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper) DefaultResponseExceptionMapper(org.jboss.resteasy.microprofile.client.DefaultResponseExceptionMapper) ParamConverterProvider(jakarta.ws.rs.ext.ParamConverterProvider) AsyncInvocationInterceptorFactory(org.eclipse.microprofile.rest.client.ext.AsyncInvocationInterceptorFactory)

Example 3 with ParamConverterProvider

use of jakarta.ws.rs.ext.ParamConverterProvider in project quarkus by quarkusio.

the class QuarkusRestClientBuilder method register.

@Override
public RestClientBuilder register(Object o) {
    if (o instanceof ResponseExceptionMapper) {
        ResponseExceptionMapper mapper = (ResponseExceptionMapper) o;
        register(mapper, mapper.getPriority());
    } else if (o instanceof ParamConverterProvider) {
        register(o, Priorities.USER);
    } else if (o instanceof AsyncInvocationInterceptorFactory) {
        invocationInterceptorFactories.add((AsyncInvocationInterceptorFactory) o);
    } else {
        builderDelegate.register(o);
    }
    return this;
}
Also used : ResponseExceptionMapper(org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper) DefaultResponseExceptionMapper(org.jboss.resteasy.microprofile.client.DefaultResponseExceptionMapper) ParamConverterProvider(jakarta.ws.rs.ext.ParamConverterProvider) AsyncInvocationInterceptorFactory(org.eclipse.microprofile.rest.client.ext.AsyncInvocationInterceptorFactory)

Example 4 with ParamConverterProvider

use of jakarta.ws.rs.ext.ParamConverterProvider in project resteasy by resteasy.

the class PriorityEqualityTest method testParamConverterProvidersObjects.

/**
 * @tpTestDetails ResteasyProviderFactory should store multiple ParamConvertProviders
 *                with the same @Priority.
 * @tpSince RESTEasy 4.0.0
 */
@Test
public void testParamConverterProvidersObjects() throws Exception {
    ResteasyProviderFactory factory = ResteasyProviderFactory.newInstance();
    RegisterBuiltin.register(factory);
    ResteasyProviderFactory.setInstance(factory);
    ParamConverterProvider p1 = new ParamConverterProvider1();
    ParamConverterProvider p2 = new ParamConverterProvider2();
    factory.registerProviderInstance(p1);
    factory.registerProviderInstance(p2);
    Assert.assertTrue(factory.getProviderInstances().contains(p1));
    Assert.assertTrue(factory.getProviderInstances().contains(p2));
    ResteasyProviderFactory.clearInstanceIfEqual(factory);
}
Also used : ParamConverterProvider(jakarta.ws.rs.ext.ParamConverterProvider) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) Test(org.junit.Test)

Example 5 with ParamConverterProvider

use of jakarta.ws.rs.ext.ParamConverterProvider 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);
    }
}
Also used : ConstrainedTo(jakarta.ws.rs.ConstrainedTo) MediaType(jakarta.ws.rs.core.MediaType) ParameterizedType(java.lang.reflect.ParameterizedType) RuntimeType(jakarta.ws.rs.RuntimeType) Type(java.lang.reflect.Type) FeatureContextDelegate(org.jboss.resteasy.util.FeatureContextDelegate) ParamConverterProvider(jakarta.ws.rs.ext.ParamConverterProvider) Feature(jakarta.ws.rs.core.Feature) DynamicFeature(jakarta.ws.rs.container.DynamicFeature) ThreadContexts(org.jboss.resteasy.spi.concurrent.ThreadContexts)

Aggregations

ParamConverterProvider (jakarta.ws.rs.ext.ParamConverterProvider)6 Prioritized (io.helidon.common.Prioritized)1 ServerThreadPoolSupplier (io.helidon.common.configurable.ServerThreadPoolSupplier)1 Http (io.helidon.common.http.Http)1 Config (io.helidon.config.Config)1 BuildTimeStart (io.helidon.microprofile.cdi.BuildTimeStart)1 RuntimeStart (io.helidon.microprofile.cdi.RuntimeStart)1 KeyPerformanceIndicatorSupport (io.helidon.webserver.KeyPerformanceIndicatorSupport)1 Routing (io.helidon.webserver.Routing)1 Service (io.helidon.webserver.Service)1 WebServer (io.helidon.webserver.WebServer)1 JerseySupport (io.helidon.webserver.jersey.JerseySupport)1 StaticContentSupport (io.helidon.webserver.staticcontent.StaticContentSupport)1 Priority (jakarta.annotation.Priority)1 ApplicationScoped (jakarta.enterprise.context.ApplicationScoped)1 BeforeDestroyed (jakarta.enterprise.context.BeforeDestroyed)1 Initialized (jakarta.enterprise.context.Initialized)1 CreationalContext (jakarta.enterprise.context.spi.CreationalContext)1 Observes (jakarta.enterprise.event.Observes)1 Bean (jakarta.enterprise.inject.spi.Bean)1