Java Code Examples for org.jboss.resteasy.spi.ResteasyProviderFactory#registerProviderInstance()

The following examples show how to use org.jboss.resteasy.spi.ResteasyProviderFactory#registerProviderInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SofaResteasyClientBuilder.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
/**
 * 注册jaxrs Provider
 *
 * @return SofaResteasyClientBuilder
 */
public SofaResteasyClientBuilder registerProvider() {
    ResteasyProviderFactory providerFactory = getProviderFactory();
    // 注册内置
    Set<Class> internalProviderClasses = JAXRSProviderManager.getInternalProviderClasses();
    if (CommonUtils.isNotEmpty(internalProviderClasses)) {
        for (Class providerClass : internalProviderClasses) {
            providerFactory.register(providerClass);
        }
    }
    // 注册自定义
    Set<Object> customProviderInstances = JAXRSProviderManager.getCustomProviderInstances();
    if (CommonUtils.isNotEmpty(customProviderInstances)) {
        for (Object provider : customProviderInstances) {
            PropertyInjector propertyInjector = providerFactory.getInjectorFactory()
                .createPropertyInjector(
                    JAXRSProviderManager.getTargetClass(provider), providerFactory);
            propertyInjector.inject(provider);
            providerFactory.registerProviderInstance(provider);
        }
    }

    return this;
}
 
Example 2
Source File: GuiceRsApplicationServlet.java    From digdag with Apache License 2.0 6 votes vote down vote up
@Override
public void init(ServletConfig servletConfig)
        throws ServletException
{
    super.init(servletConfig);
    Registry registry = servletContainerDispatcher.getDispatcher().getRegistry();
    ResteasyProviderFactory providerFactory = servletContainerDispatcher.getDispatcher().getProviderFactory();

    // add injected providers
    for (Key<Object> key : providers) {
        providerFactory.registerProviderInstance(injector.getInstance(key));
    }

    // add injected resources
    for (Map.Entry<Key<Object>, Class<?>> pair : resources.entrySet()) {
        GuiceRsResourceFactory resourceFactory = new GuiceRsResourceFactory(injector.getProvider(pair.getKey()), pair.getValue());
        registry.addResourceFactory(resourceFactory);
    }
}
 
Example 3
Source File: NexusITSupport.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * The jax-rs clients require ObjectMapper customizations to work with ComponentXO.
 */
private Customizer getObjectMapperCustomizer(final TestSuiteObjectMapperResolver testSuiteObjectMapperResolver) {
  return builder -> {
    ResteasyProviderFactory providerFactory = new LocalResteasyProviderFactory(
        ResteasyProviderFactory.newInstance());
    providerFactory.registerProviderInstance(testSuiteObjectMapperResolver, null, 1000, false);

    ResteasyClientBuilder resteasyClientBuilder = (ResteasyClientBuilder) builder;
    resteasyClientBuilder.providerFactory(providerFactory);
    RegisterBuiltin.register(providerFactory);
  };
}
 
Example 4
Source File: NexusITSupport.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * The jax-rs clients require ObjectMapper customizations to work with ComponentXO.
 */
private Customizer getObjectMapperCustomizer(final TestSuiteObjectMapperResolver testSuiteObjectMapperResolver) {
  return builder -> {
    ResteasyProviderFactory providerFactory = new LocalResteasyProviderFactory(
        ResteasyProviderFactory.newInstance());
    providerFactory.registerProviderInstance(testSuiteObjectMapperResolver, null, 1000, false);

    ResteasyClientBuilder resteasyClientBuilder = (ResteasyClientBuilder) builder;
    resteasyClientBuilder.providerFactory(providerFactory);
    RegisterBuiltin.register(providerFactory);
  };
}