use of javax.ws.rs.RuntimeType in project jersey by jersey.
the class MultiPartFeature method configure.
@Override
public boolean configure(final FeatureContext context) {
final RuntimeType runtime = context.getConfiguration().getRuntimeType();
if (RuntimeType.SERVER.equals(runtime)) {
context.register(FormDataParamInjectionFeature.class);
context.register(MultiPartReaderServerSide.class);
} else {
context.register(MultiPartReaderClientSide.class);
}
context.register(MultiPartWriter.class);
return true;
}
use of javax.ws.rs.RuntimeType in project jersey by jersey.
the class ProviderBinder method bindProviders.
/**
* Bind all providers contained in {@code p roviderBag} (classes and instances) using injection manager. Configuration is
* also committed.
*
* @param componentBag bag of provider classes and instances.
* @param constrainedTo current runtime (client or server).
* @param registeredClasses classes which are manually registered by the user (not found by the classpath scanning).
* @param injectionManager injection manager the binder will use to bind the providers into.
*/
public static void bindProviders(ComponentBag componentBag, RuntimeType constrainedTo, Set<Class<?>> registeredClasses, InjectionManager injectionManager) {
Predicate<ContractProvider> filter = ComponentBag.EXCLUDE_EMPTY.and(ComponentBag.excludeMetaProviders(injectionManager));
/*
* Check the {@code component} whether it is correctly configured for client or server {@link RuntimeType runtime}.
*/
Predicate<Class<?>> correctlyConfigured = componentClass -> Providers.checkProviderRuntime(componentClass, componentBag.getModel(componentClass), constrainedTo, registeredClasses == null || !registeredClasses.contains(componentClass), false);
/*
* These binder will be register to Bean Manager at the and of method because of a bulk registration to avoid register
* each binder alone.
*/
Collection<Binder> binderToRegister = new ArrayList<>();
// Bind provider classes except for pure meta-providers and providers with empty contract models (e.g. resources)
Set<Class<?>> classes = new LinkedHashSet<>(componentBag.getClasses(filter));
if (constrainedTo != null) {
classes = classes.stream().filter(correctlyConfigured).collect(Collectors.toSet());
}
for (final Class<?> providerClass : classes) {
final ContractProvider model = componentBag.getModel(providerClass);
binderToRegister.addAll(createProviderBinders(providerClass, model));
}
// Bind pure provider instances except for pure meta-providers and providers with empty contract models (e.g. resources)
Set<Object> instances = componentBag.getInstances(filter);
if (constrainedTo != null) {
instances = instances.stream().filter(component -> correctlyConfigured.test(component.getClass())).collect(Collectors.toSet());
}
for (final Object provider : instances) {
final ContractProvider model = componentBag.getModel(provider.getClass());
binderToRegister.addAll(createProviderBinders(provider, model));
}
injectionManager.register(CompositeBinder.wrap(binderToRegister));
}
use of javax.ws.rs.RuntimeType in project jersey by jersey.
the class CommittingOutputStreamTest method testPropertiesWithMessageContextVeryBigBuffer.
@Test
public void testPropertiesWithMessageContextVeryBigBuffer() throws IOException {
final int size = 200000;
Map<String, Object> properties = new HashMap<>();
properties.put(CommonProperties.OUTBOUND_CONTENT_LENGTH_BUFFER, size);
final RuntimeType runtime = RuntimeType.CLIENT;
checkBufferSize(size, properties, runtime);
}
use of javax.ws.rs.RuntimeType in project jersey by jersey.
the class CommittingOutputStreamTest method testPropertiesWithMessageContextDefaultNoProps.
@Test
public void testPropertiesWithMessageContextDefaultNoProps() throws IOException {
Map<String, Object> properties = new HashMap<>();
final RuntimeType runtime = RuntimeType.CLIENT;
checkBufferSize(CommittingOutputStream.DEFAULT_BUFFER_SIZE, properties, runtime);
}
use of javax.ws.rs.RuntimeType in project jersey by jersey.
the class ApplicationHandler method bindProvidersAndResources.
private void bindProvidersAndResources(final Iterable<ComponentProvider> componentProviders, final ComponentBag componentBag, final Collection<Class<?>> resourceClasses, final Collection<Object> resourceInstances) {
JerseyResourceContext resourceContext = injectionManager.getInstance(JerseyResourceContext.class);
Set<Class<?>> registeredClasses = runtimeConfig.getRegisteredClasses();
/*
* Check the {@code component} whether it is correctly configured for client or server {@link RuntimeType runtime}.
*/
java.util.function.Predicate<Class<?>> correctlyConfigured = componentClass -> Providers.checkProviderRuntime(componentClass, componentBag.getModel(componentClass), RuntimeType.SERVER, !registeredClasses.contains(componentClass), resourceClasses.contains(componentClass));
/*
* Check the {@code resource class} whether it is correctly configured for client or server {@link RuntimeType runtime}.
*/
BiPredicate<Class<?>, ContractProvider> correctlyConfiguredResource = (resourceClass, model) -> Providers.checkProviderRuntime(resourceClass, model, RuntimeType.SERVER, !registeredClasses.contains(resourceClass), true);
Set<Class<?>> componentClassses = componentBag.getClasses(ComponentBag.excludeMetaProviders(injectionManager)).stream().filter(correctlyConfigured).collect(Collectors.toSet());
// Merge programmatic resource classes with component classes.
Set<Class<?>> classes = Collections.newSetFromMap(new IdentityHashMap<>());
classes.addAll(componentClassses);
classes.addAll(resourceClasses);
// Bind classes.
for (final Class<?> componentClass : classes) {
ContractProvider model = componentBag.getModel(componentClass);
if (bindWithComponentProvider(componentClass, model, componentProviders)) {
continue;
}
if (resourceClasses.contains(componentClass)) {
if (!Resource.isAcceptable(componentClass)) {
LOGGER.warning(LocalizationMessages.NON_INSTANTIABLE_COMPONENT(componentClass));
continue;
}
if (model != null && !correctlyConfiguredResource.test(componentClass, model)) {
model = null;
}
resourceContext.unsafeBindResource(componentClass, model, injectionManager);
} else {
ProviderBinder.bindProvider(componentClass, model, injectionManager);
}
}
// Merge programmatic resource instances with other component instances.
Set<Object> instances = componentBag.getInstances(ComponentBag.excludeMetaProviders(injectionManager)).stream().filter(instance -> correctlyConfigured.test(instance.getClass())).collect(Collectors.toSet());
instances.addAll(resourceInstances);
// Bind instances.
for (Object component : instances) {
ContractProvider model = componentBag.getModel(component.getClass());
if (resourceInstances.contains(component)) {
if (model != null && !correctlyConfiguredResource.test(component.getClass(), model)) {
model = null;
}
resourceContext.unsafeBindResource(component, model, injectionManager);
} else {
ProviderBinder.bindProvider(component, model, injectionManager);
}
}
}
Aggregations