Optional Injection-less client side for SE (#5232)
Signed-off-by: jansupol <jan.supol@oracle.com>
diff --git a/core-client/src/main/java/org/glassfish/jersey/client/ChunkedInputReader.java b/core-client/src/main/java/org/glassfish/jersey/client/ChunkedInputReader.java
index f480447..e0179ba 100644
--- a/core-client/src/main/java/org/glassfish/jersey/client/ChunkedInputReader.java
+++ b/core-client/src/main/java/org/glassfish/jersey/client/ChunkedInputReader.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -43,10 +43,15 @@
@ConstrainedTo(RuntimeType.CLIENT)
class ChunkedInputReader implements MessageBodyReader<ChunkedInput> {
+ private final Provider<MessageBodyWorkers> messageBodyWorkers;
+ private final Provider<PropertiesDelegate> propertiesDelegateProvider;
+
@Inject
- private Provider<MessageBodyWorkers> messageBodyWorkers;
- @Inject
- private Provider<PropertiesDelegate> propertiesDelegateProvider;
+ public ChunkedInputReader(Provider<MessageBodyWorkers> messageBodyWorkers,
+ Provider<PropertiesDelegate> propertiesDelegateProvider) {
+ this.messageBodyWorkers = messageBodyWorkers;
+ this.propertiesDelegateProvider = propertiesDelegateProvider;
+ }
@Override
public boolean isReadable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
diff --git a/core-client/src/main/java/org/glassfish/jersey/client/ClientConfig.java b/core-client/src/main/java/org/glassfish/jersey/client/ClientConfig.java
index 89e87f1..d5983c8 100644
--- a/core-client/src/main/java/org/glassfish/jersey/client/ClientConfig.java
+++ b/core-client/src/main/java/org/glassfish/jersey/client/ClientConfig.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2021 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018 Payara Foundation and/or its affiliates.
*
* This program and the accompanying materials are made available under the
@@ -35,6 +35,7 @@
import org.glassfish.jersey.CommonProperties;
import org.glassfish.jersey.ExtendedConfig;
import org.glassfish.jersey.client.internal.LocalizationMessages;
+import org.glassfish.jersey.client.innate.inject.NonInjectionManager;
import org.glassfish.jersey.client.internal.inject.ParameterUpdaterConfigurator;
import org.glassfish.jersey.client.spi.Connector;
import org.glassfish.jersey.client.spi.ConnectorProvider;
@@ -410,7 +411,7 @@
final State runtimeCfgState = this.copy();
runtimeCfgState.markAsShared();
- InjectionManager injectionManager = Injections.createInjectionManager();
+ final InjectionManager injectionManager = findInjectionManager();
injectionManager.register(new ClientBinder(runtimeCfgState.getProperties()));
final ClientBootstrapBag bootstrapBag = new ClientBootstrapBag();
@@ -471,6 +472,14 @@
return crt;
}
+ private final InjectionManager findInjectionManager() {
+ try {
+ return Injections.createInjectionManager(RuntimeType.CLIENT);
+ } catch (IllegalStateException ise) {
+ return new NonInjectionManager(true);
+ }
+ }
+
@Override
public boolean equals(final Object o) {
if (this == o) {
diff --git a/core-client/src/main/java/org/glassfish/jersey/client/filter/EncodingFilter.java b/core-client/src/main/java/org/glassfish/jersey/client/filter/EncodingFilter.java
index bd15ec4..cdd21d8 100644
--- a/core-client/src/main/java/org/glassfish/jersey/client/filter/EncodingFilter.java
+++ b/core-client/src/main/java/org/glassfish/jersey/client/filter/EncodingFilter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -49,10 +49,15 @@
* @author Martin Matula
*/
public final class EncodingFilter implements ClientRequestFilter {
- @Inject
- private InjectionManager injectionManager;
+
+ private final InjectionManager injectionManager;
private volatile List<Object> supportedEncodings = null;
+ @Inject
+ public EncodingFilter(InjectionManager injectionManager) {
+ this.injectionManager = injectionManager;
+ }
+
@Override
public void filter(ClientRequestContext request) throws IOException {
if (getSupportedEncodings().isEmpty()) {
diff --git a/core-client/src/main/java/org/glassfish/jersey/client/innate/inject/NonInjectionManager.java b/core-client/src/main/java/org/glassfish/jersey/client/innate/inject/NonInjectionManager.java
new file mode 100644
index 0000000..74ccd8c
--- /dev/null
+++ b/core-client/src/main/java/org/glassfish/jersey/client/innate/inject/NonInjectionManager.java
@@ -0,0 +1,1029 @@
+/*
+ * Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.client.innate.inject;
+
+import org.glassfish.jersey.client.internal.LocalizationMessages;
+import org.glassfish.jersey.internal.inject.Binder;
+import org.glassfish.jersey.internal.inject.Binding;
+import org.glassfish.jersey.internal.inject.ClassBinding;
+import org.glassfish.jersey.internal.inject.DisposableSupplier;
+import org.glassfish.jersey.internal.inject.ForeignDescriptor;
+import org.glassfish.jersey.internal.inject.InjectionManager;
+import org.glassfish.jersey.internal.inject.InstanceBinding;
+import org.glassfish.jersey.internal.inject.PerThread;
+import org.glassfish.jersey.internal.inject.ServiceHolder;
+import org.glassfish.jersey.internal.inject.ServiceHolderImpl;
+import org.glassfish.jersey.internal.inject.SupplierClassBinding;
+import org.glassfish.jersey.internal.inject.SupplierInstanceBinding;
+import org.glassfish.jersey.internal.util.collection.LazyValue;
+import org.glassfish.jersey.internal.util.collection.Value;
+import org.glassfish.jersey.internal.util.collection.Values;
+import org.glassfish.jersey.process.internal.RequestScope;
+import org.glassfish.jersey.process.internal.RequestScoped;
+
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.inject.Inject;
+import javax.inject.Provider;
+import javax.inject.Singleton;
+import javax.ws.rs.ConstrainedTo;
+import javax.ws.rs.RuntimeType;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Executable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Proxy;
+import java.lang.reflect.Type;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.function.Supplier;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.stream.Collectors;
+
+@ConstrainedTo(RuntimeType.CLIENT)
+public final class NonInjectionManager implements InjectionManager {
+ private static final Logger logger = Logger.getLogger(NonInjectionManager.class.getName());
+
+ private final MultivaluedMap<Class<?>, InstanceBinding<?>> instanceBindings = new MultivaluedHashMap<>();
+ private final MultivaluedMap<Class<?>, ClassBinding<?>> contractBindings = new MultivaluedHashMap<>();
+ private final MultivaluedMap<Class<?>, SupplierInstanceBinding<?>> supplierInstanceBindings = new MultivaluedHashMap<>();
+ private final MultivaluedMap<Class<?>, SupplierClassBinding<?>> supplierClassBindings = new MultivaluedHashMap<>();
+ private final MultivaluedMap<Type, InstanceBinding<?>> instanceTypeBindings = new MultivaluedHashMap<>();
+ private final MultivaluedMap<Type, ClassBinding<?>> contractTypeBindings = new MultivaluedHashMap<>();
+ private final MultivaluedMap<Type, SupplierInstanceBinding<?>> supplierTypeInstanceBindings = new MultivaluedHashMap<>();
+ private final MultivaluedMap<Type, SupplierClassBinding<?>> supplierTypeClassBindings = new MultivaluedHashMap<>();
+
+ private final MultivaluedMap<DisposableSupplier, Object> disposableSupplierObjects = new MultivaluedHashMap<>();
+
+ private final Instances instances = new Instances();
+ private final Types types = new Types();
+
+ private volatile boolean isRequestScope = false;
+ private volatile boolean shutdown = false;
+
+ /**
+ * A class that holds singleton instances and thread-scope instances. Provides thread safe access to singletons
+ * and thread-scope instances. The instances are created for Type (ParametrizedType) and for a Class.
+ * @param <TYPE> the type for which the instance is created, either Class, or ParametrizedType (for instance
+ * Provider<SomeClass>).
+ */
+ private class TypedInstances<TYPE> {
+ private final MultivaluedMap<TYPE, InstanceContext<?>> singletonInstances = new MultivaluedHashMap<>();
+ private final ThreadLocal<MultivaluedMap<TYPE, InstanceContext<?>>> threadInstances = new ThreadLocal<>();
+ private final List<Object> threadPredestroyables = Collections.synchronizedList(new LinkedList<>());
+
+ private <T> List<InstanceContext<?>> _getSingletons(TYPE clazz) {
+ List<InstanceContext<?>> si;
+ synchronized (singletonInstances) {
+ si = singletonInstances.get(clazz);
+ }
+ return si;
+ }
+
+ @SuppressWarnings("unchecked")
+ <T> T _addSingleton(TYPE clazz, T instance, Binding<?, ?> binding, Annotation[] qualifiers) {
+ synchronized (singletonInstances) {
+ // check existing singleton with a qualifier already created by another thread io a meantime
+ List<InstanceContext<?>> values = singletonInstances.get(clazz);
+ if (values != null) {
+ List<InstanceContext<?>> qualified
+ = values.stream()
+ .filter(ctx -> ctx.hasQualifiers(qualifiers))
+ .collect(Collectors.toList());
+ if (!qualified.isEmpty()) {
+ return (T) qualified.get(0).instance;
+ }
+ }
+ singletonInstances.add(clazz, new InstanceContext<>(instance, binding, qualifiers));
+ threadPredestroyables.add(instance);
+ return instance;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ <T> T addSingleton(TYPE clazz, T t, Binding<?, ?> binding, Annotation[] instanceQualifiers) {
+ T t2 = _addSingleton(clazz, t, binding, instanceQualifiers);
+ if (t2 == t) {
+ for (Type contract : binding.getContracts()) {
+ if (!clazz.equals(contract) && isClass(contract)) {
+ _addSingleton((TYPE) contract, t, binding, instanceQualifiers);
+ }
+ }
+ }
+ return t2;
+ }
+
+ private List<InstanceContext<?>> _getThreadInstances(TYPE clazz) {
+ MultivaluedMap<TYPE, InstanceContext<?>> ti = threadInstances.get();
+ List<InstanceContext<?>> list = ti == null ? null : new LinkedList<>();
+ if (ti != null) {
+ return ti.get(clazz);
+ }
+ return list;
+ }
+
+ private <T> void _addThreadInstance(TYPE clazz, T instance, Binding<T, ?> binding, Annotation[] qualifiers) {
+ MultivaluedMap<TYPE, InstanceContext<?>> map = threadInstances.get();
+ if (map == null) {
+ map = new MultivaluedHashMap<>();
+ threadInstances.set(map);
+ }
+ map.add(clazz, new InstanceContext<>(instance, binding, qualifiers));
+ threadPredestroyables.add(instance);
+ }
+
+ <T> void addThreadInstance(TYPE clazz, T t, Binding<T, ?> binding, Annotation[] instanceQualifiers) {
+ _addThreadInstance(clazz, t, binding, instanceQualifiers);
+ for (Type contract : binding.getContracts()) {
+ if (!clazz.equals(contract) && isClass(contract)) {
+ _addThreadInstance((TYPE) contract, t, binding, instanceQualifiers);
+ }
+ }
+ }
+
+ private <T> List<T> getInstances(TYPE clazz, Annotation[] annotations) {
+ List<InstanceContext<?>> i = _getContexts(clazz);
+ return InstanceContext.toInstances(i, annotations);
+ }
+
+ <T> List<InstanceContext<?>> getContexts(TYPE clazz, Annotation[] annotations) {
+ List<InstanceContext<?>> i = _getContexts(clazz);
+ return InstanceContext.filterInstances(i, annotations);
+ }
+
+ private <T> List<InstanceContext<?>> _getContexts(TYPE clazz) {
+ List<InstanceContext<?>> si = _getSingletons(clazz);
+ List<InstanceContext<?>> ti = _getThreadInstances(clazz);
+ if (si == null && ti != null) {
+ si = ti;
+ } else if (ti != null) {
+ si.addAll(ti);
+ }
+ return si;
+ }
+
+ <T> T getInstance(TYPE clazz, Annotation[] annotations) {
+ List<T> i = getInstances(clazz, annotations);
+ if (i != null) {
+ checkUnique(i);
+ return i.get(0);
+ }
+ return null;
+ }
+
+ void dispose() {
+ singletonInstances.forEach((clazz, instances) -> instances.forEach(instance -> preDestroy(instance.getInstance())));
+ threadPredestroyables.forEach(NonInjectionManager.this::preDestroy);
+ }
+ }
+
+ private class Instances extends TypedInstances<Class<?>> {
+ }
+
+ private class Types extends TypedInstances<Type> {
+ }
+
+ public NonInjectionManager() {
+ }
+
+ public NonInjectionManager(boolean warning) {
+ if (warning) {
+ logger.warning(LocalizationMessages.NONINJECT_FALLBACK());
+ } else {
+ logger.log(Level.FINER, LocalizationMessages.NONINJECT_FALLBACK());
+ }
+ }
+
+ @Override
+ public void completeRegistration() {
+ instances._addSingleton(InjectionManager.class, this, new InjectionManagerBinding(), null);
+ }
+
+ @Override
+ public void shutdown() {
+ shutdown = true;
+
+ disposableSupplierObjects.forEach((supplier, objects) -> objects.forEach(supplier::dispose));
+ disposableSupplierObjects.clear();
+
+ instances.dispose();
+ types.dispose();
+ }
+
+ @Override
+ public boolean isShutdown() {
+ return shutdown;
+ }
+
+ private void checkShutdown() {
+ if (shutdown) {
+ throw new IllegalStateException(LocalizationMessages.NONINJECT_SHUTDOWN());
+ }
+ }
+
+ @Override
+ public void register(Binding binding) {
+ checkShutdown();
+ if (InstanceBinding.class.isInstance(binding)) {
+ InstanceBinding instanceBinding = (InstanceBinding) binding;
+ Class<?> mainType = binding.getImplementationType();
+ if (!instanceBindings.containsKey(mainType)) { // the class could be registered twice, for reader & for writer
+ instanceBindings.add(mainType, (InstanceBinding) binding);
+ }
+ for (Type type : (Iterable<Type>) instanceBinding.getContracts()) {
+ if (isClass(type)) {
+ if (!mainType.equals(type)) {
+ instanceBindings.add((Class<?>) type, instanceBinding);
+ }
+ } else {
+ instanceTypeBindings.add(type, instanceBinding);
+ }
+ }
+ } else if (ClassBinding.class.isInstance(binding)) {
+ ClassBinding<?> contractBinding = (ClassBinding<?>) binding;
+ Class<?> mainType = binding.getImplementationType();
+ if (!contractBindings.containsKey(mainType)) { // the class could be registered twice, for reader & for writer
+ contractBindings.add(mainType, contractBinding);
+ }
+ for (Type type : contractBinding.getContracts()) {
+ if (isClass(type)) {
+ if (!mainType.equals(type)) {
+ contractBindings.add((Class<?>) type, contractBinding);
+ }
+ } else {
+ contractTypeBindings.add(type, contractBinding);
+ }
+ }
+ } else if (SupplierInstanceBinding.class.isInstance(binding)) {
+ SupplierInstanceBinding<?> supplierBinding = (SupplierInstanceBinding<?>) binding;
+ for (Type type : supplierBinding.getContracts()) {
+ if (isClass(type)) {
+ supplierInstanceBindings.add((Class<?>) type, supplierBinding);
+ } else {
+ supplierTypeInstanceBindings.add(type, supplierBinding);
+ }
+ }
+ } else if (SupplierClassBinding.class.isInstance(binding)) {
+ SupplierClassBinding<?> supplierBinding = (SupplierClassBinding<?>) binding;
+ for (Type type : supplierBinding.getContracts()) {
+ if (isClass(type)) {
+ supplierClassBindings.add((Class<?>) type, supplierBinding);
+ } else {
+ supplierTypeClassBindings.add(type, supplierBinding);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void register(Iterable<Binding> descriptors) {
+ checkShutdown();
+ for (Binding binding : descriptors) {
+ register(binding);
+ }
+ }
+
+ @Override
+ public void register(Binder binder) {
+ checkShutdown();
+ binder.getBindings().stream().iterator().forEachRemaining(this::register);
+ }
+
+ @Override
+ public void register(Object provider) throws IllegalArgumentException {
+ throw new UnsupportedOperationException("Register " + provider);
+ }
+
+ @Override
+ public boolean isRegistrable(Class<?> clazz) {
+ return false; // for external creators
+ }
+
+ @Override
+ public <T> List<ServiceHolder<T>> getAllServiceHolders(Class<T> contractOrImpl, Annotation... qualifiers) {
+ checkShutdown();
+
+ ClassBindings<T> classBindings = classBindings(contractOrImpl, qualifiers);
+ return classBindings.getAllServiceHolders(qualifiers);
+ }
+
+ @Override
+ public <T> T getInstance(Class<T> contractOrImpl, Annotation... qualifiers) {
+ checkShutdown();
+
+ ClassBindings<T> classBindings = classBindings(contractOrImpl, qualifiers);
+ classBindings.matchQualifiers(qualifiers);
+ return classBindings.getInstance();
+ }
+
+ @Override
+ public <T> T getInstance(Class<T> contractOrImpl, String classAnalyzer) {
+ throw new UnsupportedOperationException("getInstance(Class, String)");
+ }
+
+ @Override
+ public <T> T getInstance(Class<T> contractOrImpl) {
+ checkShutdown();
+
+ T instance = instances.getInstance(contractOrImpl, null);
+ if (instance != null) {
+ return instance;
+ }
+ return create(contractOrImpl);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <T> T getInstance(Type contractOrImpl) {
+ checkShutdown();
+
+ if (ParameterizedType.class.isInstance(contractOrImpl)) {
+ T instance = types.getInstance(contractOrImpl, null);
+ if (instance != null) {
+ return instance;
+ }
+
+ TypeBindings<T> typeBindings = typeBindings(contractOrImpl);
+ return typeBindings.getInstance();
+ } else if (isClass(contractOrImpl)) {
+ return getInstance((Class<? extends T>) contractOrImpl);
+ }
+ throw new IllegalStateException(LocalizationMessages.NONINJECT_UNSATISFIED(contractOrImpl));
+ }
+
+ private static boolean isClass(Type type) {
+ return Class.class.isAssignableFrom(type.getClass());
+ }
+
+ @Override
+ public Object getInstance(ForeignDescriptor foreignDescriptor) {
+ throw new UnsupportedOperationException("getInstance(ForeignDescriptor foreignDescriptor) ");
+ }
+
+ @Override
+ public ForeignDescriptor createForeignDescriptor(Binding binding) {
+ throw new UnsupportedOperationException("createForeignDescriptor(Binding binding) ");
+ }
+
+ @Override
+ public <T> List<T> getAllInstances(Type contractOrImpl) {
+ checkShutdown();
+
+ if (!isClass(contractOrImpl)) {
+ TypeBindings<T> typeBindings = typeBindings(contractOrImpl);
+ return typeBindings.allInstances();
+ }
+
+ @SuppressWarnings("unchecked")
+ ClassBindings<T> classBindings = classBindings((Class<T>) contractOrImpl);
+ return classBindings.allInstances();
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T> T create(Class<T> createMe) {
+ checkShutdown();
+
+ if (InjectionManager.class.equals(createMe)) {
+ return (T) this;
+ }
+ if (RequestScope.class.equals(createMe)) {
+ if (!isRequestScope) {
+ isRequestScope = true;
+ return (T) new NonInjectionRequestScope();
+ } else {
+ throw new IllegalStateException(LocalizationMessages.NONINJECT_REQUESTSCOPE_CREATED());
+ }
+ }
+
+ ClassBindings<T> classBindings = classBindings(createMe);
+ return classBindings.create();
+ }
+
+ private <T> T justCreate(Class<T> createMe) {
+ T result = null;
+ try {
+ Constructor<T> mostArgConstructor = findConstructor(createMe);
+ if (mostArgConstructor != null) {
+ int argCount = mostArgConstructor.getParameterCount();
+ if (argCount == 0) {
+ ensureAccessible(mostArgConstructor);
+ result = mostArgConstructor.newInstance();
+ } else if (argCount > 0) {
+ Object[] args = getArguments(mostArgConstructor, argCount);
+ if (args != null) {
+ ensureAccessible(mostArgConstructor);
+ result = mostArgConstructor.newInstance(args);
+ }
+ }
+ }
+ if (result == null) {
+ throw new IllegalStateException(LocalizationMessages.NONINJECT_NO_CONSTRUCTOR(createMe.getName()));
+ }
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+
+ inject(result);
+ return result;
+ }
+
+ private static <T> Constructor<T> findConstructor(Class<T> forClass) {
+ Constructor<T>[] constructors = (Constructor<T>[]) forClass.getDeclaredConstructors();
+ Constructor<T> mostArgConstructor = null;
+ int argCount = -1;
+ for (Constructor<T> constructor : constructors) {
+ if (constructor.isAnnotationPresent(Inject.class) || constructor.getParameterCount() == 0) {
+ if (constructor.getParameterCount() > argCount) {
+ mostArgConstructor = constructor;
+ argCount = constructor.getParameterCount();
+ }
+ }
+ }
+ return mostArgConstructor;
+ }
+
+ private Object[] getArguments(Executable executable, int argCount) {
+ if (executable == null) {
+ return null;
+ }
+ Object[] args = new Object[argCount];
+ for (int i = 0; i != argCount; i++) {
+ Type type = executable.getAnnotatedParameterTypes()[i].getType();
+ args[i] = isClass(type) ? getInstance((Class<?>) type) : getInstance(type);
+ }
+ return args;
+ }
+
+ private static void ensureAccessible(Executable executable) {
+ try {
+ if (!executable.isAccessible()) {
+ executable.setAccessible(true);
+ }
+ } catch (Exception e) {
+ // consume. It will fail later with invoking the executable
+ }
+ }
+
+ private void checkUnique(List<?> list) {
+ if (list.size() != 1) {
+ throw new IllegalStateException(LocalizationMessages.NONINJECT_AMBIGUOUS_SERVICES(list.get(0)));
+ }
+ }
+
+ @Override
+ public <T> T createAndInitialize(Class<T> createMe) {
+ return justCreate(createMe);
+ }
+
+ @Override
+ public void inject(Object injectMe) {
+ Method postConstruct = getAnnotatedMethod(injectMe, PostConstruct.class);
+ if (postConstruct != null) {
+ ensureAccessible(postConstruct);
+ try {
+ postConstruct.invoke(injectMe);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+
+ @Override
+ public void inject(Object injectMe, String classAnalyzer) {
+ throw new UnsupportedOperationException("inject(Object injectMe, String classAnalyzer)");
+ }
+
+ @Override
+ public void preDestroy(Object preDestroyMe) {
+ Method preDestroy = getAnnotatedMethod(preDestroyMe, PreDestroy.class);
+ if (preDestroy != null) {
+ ensureAccessible(preDestroy);
+ try {
+ preDestroy.invoke(preDestroyMe);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+
+ private static Method getAnnotatedMethod(Object object, Class<? extends Annotation> annotation) {
+ Class<?> clazz = object.getClass();
+ for (Method method : clazz.getMethods()) {
+ if (method.isAnnotationPresent(annotation)
+ && /* do not invoke interceptors */ method.getParameterCount() == 0) {
+ return method;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Some {@link Binding} requires the proxy to be created rather than just the instance,
+ * for instance a proxy of an instance supplied by a supplier that is not known at a time of the proxy creation.
+ * @param createProxy the nullable {@link Binding#isProxiable()} information
+ * @param iface the type of which the proxy is created
+ * @param supplier the reference to the supplier
+ * @param <T> the type the supplier should supply
+ * @return The proxy for the instance supplied by a supplier or the instance if not required to be proxied.
+ */
+ @SuppressWarnings("unchecked")
+ private <T> T createSupplierProxyIfNeeded(Boolean createProxy, Class<T> iface, Supplier<T> supplier) {
+ if (createProxy != null && createProxy && iface.isInterface()) {
+ T proxy = (T) Proxy.newProxyInstance(iface.getClassLoader(), new Class[]{iface}, new InvocationHandler() {
+ final SingleRegisterSupplier<T> singleSupplierRegister = new SingleRegisterSupplier<>(supplier);
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ T t = singleSupplierRegister.get();
+ Object ret = method.invoke(t, args);
+ return ret;
+ }
+ });
+ return proxy;
+ } else {
+ return registerDisposableSupplierAndGet(supplier);
+ }
+ }
+
+ /**
+ * A holder class making sure the Supplier (especially the {@link DisposableSupplier}) supplying the instance
+ * supplies (and is registered for being disposed at the end of the lifecycle) only once.
+ * @param <T>
+ */
+ private class SingleRegisterSupplier<T> {
+ private final LazyValue<T> once;
+
+ private SingleRegisterSupplier(Supplier<T> supplier) {
+ once = Values.lazy((Value<T>) () -> registerDisposableSupplierAndGet(supplier));
+ }
+
+ T get() {
+ return once.get();
+ }
+ }
+
+ private <T> T registerDisposableSupplierAndGet(Supplier<T> supplier) {
+ T instance = supplier.get();
+ if (DisposableSupplier.class.isInstance(supplier)) {
+ disposableSupplierObjects.add((DisposableSupplier<T>) supplier, instance);
+ }
+ return instance;
+ }
+
+ /**
+ * Create {@link ClassBindings} instance containing bindings and instances for the given Type.
+ * @param clazz the given class.
+ * @param instancesQualifiers The qualifiers the expected instances of the given class should have.
+ * @param <T> Expected return class type.
+ * @return the {@link ClassBindings}.
+ */
+ @SuppressWarnings("unchecked")
+ private <T> ClassBindings<T> classBindings(Class<T> clazz, Annotation... instancesQualifiers) {
+ ClassBindings<T> classBindings = new ClassBindings<>(clazz, instancesQualifiers);
+ List<InstanceBinding<?>> ib = instanceBindings.get(clazz);
+ if (ib != null) {
+ ib.forEach(binding -> classBindings.instanceBindings.add((InstanceBinding<T>) binding));
+ }
+ List<SupplierInstanceBinding<?>> sib = supplierInstanceBindings.get(clazz);
+ if (sib != null) {
+ sib.forEach(binding -> classBindings.supplierInstanceBindings.add((SupplierInstanceBinding<T>) binding));
+ }
+ List<ClassBinding<?>> cb = contractBindings.get(clazz);
+ if (cb != null) {
+ cb.forEach(binding -> classBindings.classBindings.add((ClassBinding<T>) binding));
+ }
+ List<SupplierClassBinding<?>> scb = supplierClassBindings.get(clazz);
+ if (scb != null) {
+ scb.forEach(binding -> classBindings.supplierClassBindings.add((SupplierClassBinding<T>) binding));
+ }
+ return classBindings;
+ }
+
+ /**
+ * Create {@link TypeBindings} instance containing bindings and instances for the given Type.
+ * @param type the given type.
+ * @param <T> Expected return type.
+ * @return the {@link TypeBindings}.
+ */
+ @SuppressWarnings("unchecked")
+ private <T> TypeBindings<T> typeBindings(Type type) {
+ TypeBindings<T> typeBindings = new TypeBindings<>(type);
+ List<InstanceBinding<?>> ib = instanceTypeBindings.get(type);
+ if (ib != null) {
+ ib.forEach(binding -> typeBindings.instanceBindings.add((InstanceBinding<T>) binding));
+ }
+ List<SupplierInstanceBinding<?>> sib = supplierTypeInstanceBindings.get(type);
+ if (sib != null) {
+ sib.forEach(binding -> typeBindings.supplierInstanceBindings.add((SupplierInstanceBinding<T>) binding));
+ }
+ List<ClassBinding<?>> cb = contractTypeBindings.get(type);
+ if (cb != null) {
+ cb.forEach(binding -> typeBindings.classBindings.add((ClassBinding<T>) binding));
+ }
+ List<SupplierClassBinding<?>> scb = supplierTypeClassBindings.get(type);
+ if (scb != null) {
+ scb.forEach(binding -> typeBindings.supplierClassBindings.add((SupplierClassBinding<T>) binding));
+ }
+ return typeBindings;
+ }
+
+ /**
+ * <p>
+ * A class that contains relevant bindings for a given TYPE, filtered from all registered bindings.
+ * The TYPE is either Type (ParametrizedType) or Class.
+ * </p>
+ * <p>
+ * The class also filters any bindings for which the singleton or thread-scoped instance already is created.
+ * The class either provides the existing instance, or all instances of the TYPE, or {@link ServiceHolder}s.
+ * </p>
+ * @param <X> The expected return type for the TYPE.
+ * @param <TYPE> The Type for which a {@link Binding} has been created.
+ */
+ private abstract class XBindings<X, TYPE> {
+
+ protected final List<InstanceBinding<X>> instanceBindings = new LinkedList<>();
+ protected final List<SupplierInstanceBinding<X>> supplierInstanceBindings = new LinkedList<>();
+ protected final List<ClassBinding<X>> classBindings = new LinkedList<>();
+ protected final List<SupplierClassBinding<X>> supplierClassBindings = new LinkedList<>();
+
+ protected final TYPE type;
+ protected final Annotation[] instancesQualifiers;
+ protected final TypedInstances<TYPE> instances;
+
+ protected XBindings(TYPE type, Annotation[] instancesQualifiers, TypedInstances<TYPE> instances) {
+ this.type = type;
+ this.instancesQualifiers = instancesQualifiers;
+ this.instances = instances;
+ }
+
+ int size() {
+ return instanceBindings.size()
+ + supplierInstanceBindings.size()
+ + classBindings.size()
+ + supplierClassBindings.size();
+ }
+
+ private void _checkUnique() {
+ if (size() > 1) {
+ throw new IllegalStateException(LocalizationMessages.NONINJECT_AMBIGUOUS_SERVICES(type));
+ }
+ }
+
+ void filterBinding(Binding binding) {
+ if (InstanceBinding.class.isInstance(binding)) {
+ instanceBindings.remove(binding);
+ } else if (ClassBinding.class.isInstance(binding)) {
+ classBindings.remove(binding);
+ } else if (SupplierInstanceBinding.class.isInstance(binding)) {
+ supplierInstanceBindings.remove(binding);
+ } else if (SupplierClassBinding.class.isInstance(binding)) {
+ supplierClassBindings.remove(binding);
+ }
+ }
+
+ /**
+ * Match the binging qualifiers
+ * @param bindingQualifiers the qualifiers registered with the bindings
+ */
+ void matchQualifiers(Annotation... bindingQualifiers) {
+ if (bindingQualifiers != null) {
+ _filterRequested(instanceBindings, bindingQualifiers);
+ _filterRequested(classBindings, bindingQualifiers);
+ _filterRequested(supplierInstanceBindings, bindingQualifiers);
+ _filterRequested(supplierClassBindings, bindingQualifiers);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private void _filterRequested(List<? extends Binding<?, ?>> bindingList, Annotation... requestedQualifiers) {
+ for (Iterator<? extends Binding> bindingIterator = bindingList.iterator(); bindingIterator.hasNext();) {
+ Binding<X, ?> binding = bindingIterator.next();
+ classLoop:
+ for (Annotation requestedQualifier : requestedQualifiers) {
+ for (Annotation bindingQualifier : binding.getQualifiers()) {
+ if (requestedQualifier.annotationType().isInstance(bindingQualifier)) {
+ continue classLoop;
+ }
+ }
+ bindingIterator.remove();
+ }
+ }
+ }
+
+ protected boolean _isPerThread(Class<? extends Annotation> scope) {
+ return RequestScoped.class.equals(scope) || PerThread.class.equals(scope);
+ }
+
+ private X _getInstance(InstanceBinding<X> instanceBinding) {
+ return instanceBinding.getService();
+ }
+
+ private X _create(SupplierInstanceBinding<X> binding) {
+ Supplier<X> supplier = binding.getSupplier();
+ X t = registerDisposableSupplierAndGet(supplier);
+ if (Singleton.class.equals(binding.getScope())) {
+ _addInstance(t, binding);
+ } else if (_isPerThread(binding.getScope())) {
+ _addThreadInstance(t, binding);
+ }
+ return t;
+ }
+
+ X create() {
+ _checkUnique();
+ if (!instanceBindings.isEmpty()) {
+ return _getInstance(instanceBindings.get(0));
+ } else if (!supplierInstanceBindings.isEmpty()) {
+ return _create(supplierInstanceBindings.get(0));
+ } else if (!classBindings.isEmpty()) {
+ return _createAndStore(classBindings.get(0));
+ } else if (!supplierClassBindings.isEmpty()) {
+ return _create(supplierClassBindings.get(0));
+ }
+
+ throw new IllegalStateException(LocalizationMessages.NONINJECT_NO_BINDING(type));
+ }
+
+ protected X getInstance() {
+ X instance = instances.getInstance(type, instancesQualifiers);
+ if (instance != null) {
+ return instance;
+ }
+ return create();
+ }
+
+ List<X> allInstances() {
+ List<X> list = new LinkedList<>();
+ List<InstanceContext<?>> instanceContextList;
+
+ instanceContextList = instances.getContexts(type, instancesQualifiers);
+ if (instanceContextList != null) {
+ instanceContextList.forEach(instanceContext -> filterBinding(instanceContext.getBinding()));
+ instanceContextList.forEach(instanceContext -> list.add((X) instanceContext.getInstance()));
+ }
+
+ list.addAll(instanceBindings.stream()
+ .map(this::_getInstance)
+ .collect(Collectors.toList()));
+
+ list.addAll(classBindings.stream()
+ .map(this::_createAndStore)
+ .collect(Collectors.toList()));
+
+ list.addAll(supplierInstanceBindings.stream()
+ .map(this::_create)
+ .collect(Collectors.toList()));
+
+ list.addAll(supplierClassBindings.stream()
+ .map(this::_create)
+ .collect(Collectors.toList()));
+
+ return list;
+ }
+
+ protected abstract X _create(SupplierClassBinding<X> binding);
+
+ protected abstract X _createAndStore(ClassBinding<X> binding);
+
+ protected <T> T _addInstance(TYPE type, T instance, Binding<?, ?> binding) {
+ return instances.addSingleton(type, instance, binding, instancesQualifiers);
+ }
+
+ protected void _addThreadInstance(TYPE type, Object instance, Binding binding) {
+ instances.addThreadInstance(type, instance, binding, instancesQualifiers);
+ }
+
+ protected <T> T _addInstance(T instance, Binding<?, ?> binding) {
+ return instances.addSingleton(type, instance, binding, instancesQualifiers);
+ }
+
+ protected void _addThreadInstance(Object instance, Binding binding) {
+ instances.addThreadInstance(type, instance, binding, instancesQualifiers);
+ }
+ }
+
+
+ private class ClassBindings<T> extends XBindings<T, Class<?>> {
+ private ClassBindings(Class<T> clazz, Annotation[] instancesQualifiers) {
+ super(clazz, instancesQualifiers, NonInjectionManager.this.instances);
+ }
+
+ @SuppressWarnings("unchecked")
+ List<ServiceHolder<T>> getAllServiceHolders(Annotation... qualifiers) {
+ matchQualifiers(qualifiers);
+
+ List<ServiceHolder<T>> holders = new LinkedList<>();
+ List<InstanceContext<?>> instanceContextList;
+
+ instanceContextList = instances.getContexts(type, qualifiers);
+
+ if (instanceContextList != null) {
+ instanceContextList.forEach(instanceContext -> filterBinding(instanceContext.getBinding()));
+ instanceContextList.forEach(instanceContext -> holders.add(new ServiceHolderImpl<T>(
+ (T) instanceContext.getInstance(),
+ (Class<T>) instanceContext.getInstance().getClass(),
+ instanceContext.getBinding().getContracts(),
+ instanceContext.getBinding().getRank() == null ? 0 : instanceContext.getBinding().getRank())
+ ));
+ }
+
+ List<ServiceHolder<T>> instanceBindingHolders = instanceBindings.stream()
+ .map(this::_serviceHolder)
+ .collect(Collectors.toList());
+ holders.addAll(instanceBindingHolders);
+
+ List<ServiceHolder<T>> classBindingHolders = classBindings.stream()
+ .filter(binding -> NonInjectionManager.this.findConstructor(binding.getService()) != null)
+ .map(this::_serviceHolder)
+ .collect(Collectors.toList());
+ holders.addAll(classBindingHolders);
+
+ return holders;
+ }
+
+ private <T> ServiceHolderImpl<T> _serviceHolder(InstanceBinding<T> binding) {
+ return new ServiceHolderImpl<T>(
+ binding.getService(),
+ binding.getImplementationType(),
+ binding.getContracts(),
+ binding.getRank() == null ? 0 : binding.getRank());
+ }
+
+ private <T> ServiceHolderImpl<T> _serviceHolder(ClassBinding<T> binding) {
+ return new ServiceHolderImpl<T>(
+ NonInjectionManager.this.create(binding.getService()),
+ binding.getImplementationType(),
+ binding.getContracts(),
+ binding.getRank() == null ? 0 : binding.getRank());
+ }
+
+ protected T _create(SupplierClassBinding<T> binding) {
+ Supplier<T> supplier = instances.getInstance(binding.getSupplierClass(), null);
+ if (supplier == null) {
+ supplier = justCreate(binding.getSupplierClass());
+ if (Singleton.class.equals(binding.getSupplierScope())) {
+ supplier = instances.addSingleton(binding.getSupplierClass(), supplier, binding, null);
+ } else if (_isPerThread(binding.getSupplierScope())) {
+ instances.addThreadInstance(binding.getSupplierClass(), supplier, binding, null);
+ }
+ }
+
+ T t = createSupplierProxyIfNeeded(binding.isProxiable(), (Class<T>) type, supplier);
+ if (Singleton.class.equals(binding.getScope())) {
+ t = _addInstance(type, t, binding);
+ } else if (_isPerThread(binding.getScope())) {
+ _addThreadInstance(type, t, binding);
+ }
+ return t;
+ }
+
+ protected T _createAndStore(ClassBinding<T> binding) {
+ T result = justCreate(binding.getService());
+ result = _addInstance(binding.getService(), result, binding);
+ return result;
+ }
+ }
+
+ private class TypeBindings<T> extends XBindings<T, Type> {
+ private TypeBindings(Type type) {
+ super(type, null, types);
+ }
+
+ protected T _create(SupplierClassBinding<T> binding) {
+ Supplier<T> supplier = justCreate(binding.getSupplierClass());
+
+ T t = registerDisposableSupplierAndGet(supplier);
+ if (Singleton.class.equals(binding.getScope())) {
+ t = _addInstance(type, t, binding);
+ } else if (_isPerThread(binding.getScope())) {
+ _addThreadInstance(type, t, binding);
+ }
+ return t;
+ }
+
+ @Override
+ protected T _createAndStore(ClassBinding<T> binding) {
+ T result = justCreate(binding.getService());
+ result = _addInstance(type, result, binding);
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ T create() {
+ if (ParameterizedType.class.isInstance(type)) {
+ ParameterizedType pt = (ParameterizedType) type;
+ if (Provider.class.equals(pt.getRawType())) {
+ return (T) new Provider<Object>() {
+ final SingleRegisterSupplier<Object> supplier = new SingleRegisterSupplier<>(new Supplier<Object>() {
+ @Override
+ public Object get() {
+ Type actualTypeArgument = pt.getActualTypeArguments()[0];
+ if (isClass(actualTypeArgument)) {
+ return NonInjectionManager.this.getInstance((Class<? extends T>) actualTypeArgument);
+ } else {
+ return NonInjectionManager.this.getInstance(actualTypeArgument);
+ }
+ }
+ });
+
+ @Override
+ public Object get() {
+ return supplier.get(); //Not disposable
+ }
+ };
+ }
+ }
+ return super.create();
+ }
+ }
+
+ /**
+ * A triplet of created instance, the registered {@link Binding} that prescribed the creation of the instance
+ * and {@link Annotation qualifiers} the instance was created with.
+ * @param <T> type of the instance.
+ * @see NonInjectionManager#getInstance(Class, Annotation[])
+ */
+ private static class InstanceContext<T> {
+ private final T instance;
+ private final Binding<?, ?> binding;
+ private final Annotation[] createdWithQualifiers;
+
+ private InstanceContext(T instance, Binding<?, ?> binding, Annotation[] qualifiers) {
+ this.instance = instance;
+ this.binding = binding;
+ this.createdWithQualifiers = qualifiers;
+ }
+
+ public Binding<?, ?> getBinding() {
+ return binding;
+ }
+
+ public T getInstance() {
+ return instance;
+ }
+
+ @SuppressWarnings("unchecked")
+ static <T> List<T> toInstances(List<InstanceContext<?>> instances, Annotation[] qualifiers) {
+ return instances != null
+ ? instances.stream()
+ .filter(instance -> instance.hasQualifiers(qualifiers))
+ .map(pair -> (T) pair.getInstance())
+ .collect(Collectors.toList())
+ : null;
+ }
+
+ private static List<InstanceContext<?>> filterInstances(List<InstanceContext<?>> instances, Annotation... qualifiers) {
+ return instances != null
+ ? instances.stream()
+ .filter(instance -> instance.hasQualifiers(qualifiers))
+ .collect(Collectors.toList())
+ : null;
+ }
+
+ private boolean hasQualifiers(Annotation[] requested) {
+ if (requested != null) {
+ classLoop:
+ for (Annotation req : requested) {
+ if (createdWithQualifiers != null) {
+ for (Annotation cur : createdWithQualifiers) {
+ if (cur.annotationType().isInstance(req)) {
+ continue classLoop;
+ }
+ }
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ }
+
+ /**
+ * Singleton Binding this {@link NonInjectionManager} was supposed to be created based upon.
+ */
+ private static final class InjectionManagerBinding extends Binding<InjectionManager, Binding<?, ?>> {
+ }
+
+}
diff --git a/core-client/src/main/java/org/glassfish/jersey/client/innate/inject/NonInjectionRequestScope.java b/core-client/src/main/java/org/glassfish/jersey/client/innate/inject/NonInjectionRequestScope.java
new file mode 100644
index 0000000..258780d
--- /dev/null
+++ b/core-client/src/main/java/org/glassfish/jersey/client/innate/inject/NonInjectionRequestScope.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.client.innate.inject;
+
+import org.glassfish.jersey.internal.util.ExtendedLogger;
+import org.glassfish.jersey.internal.util.LazyUid;
+import org.glassfish.jersey.process.internal.RequestScope;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class NonInjectionRequestScope extends RequestScope {
+ @Override
+ public org.glassfish.jersey.process.internal.RequestContext createContext() {
+ return new Instance();
+ }
+
+ /**
+ * Implementation of the request scope instance.
+ */
+ public static final class Instance implements org.glassfish.jersey.process.internal.RequestContext {
+
+ private static final ExtendedLogger logger = new ExtendedLogger(Logger.getLogger(Instance.class.getName()), Level.FINEST);
+
+ /*
+ * Scope instance UUID.
+ *
+ * For performance reasons, it's only generated if toString() method is invoked,
+ * e.g. as part of some low-level logging.
+ */
+ private final LazyUid id = new LazyUid();
+
+ /**
+ * Holds the number of snapshots of this scope.
+ */
+ private final AtomicInteger referenceCounter;
+
+ private Instance() {
+ this.referenceCounter = new AtomicInteger(1);
+ }
+
+ /**
+ * Get a "new" reference of the scope instance. This will increase
+ * the internal reference counter which prevents the scope instance
+ * to be destroyed until a {@link #release()} method is explicitly
+ * called (once per each {@code getReference()} method call).
+ *
+ * @return referenced scope instance.
+ */
+ @Override
+ public NonInjectionRequestScope.Instance getReference() {
+ // TODO: replace counter with a phantom reference + reference queue-based solution
+ referenceCounter.incrementAndGet();
+ return this;
+ }
+
+
+ /**
+ * Release a single reference to the current request scope instance.
+ * <p>
+ * Once all instance references are released, the instance will be recycled.
+ */
+ @Override
+ public void release() {
+ referenceCounter.decrementAndGet();
+ }
+
+ @Override
+ public String toString() {
+ return "Instance{"
+ + "id=" + id
+ + ", referenceCounter=" + referenceCounter
+ + '}';
+ }
+ }
+}
diff --git a/core-client/src/main/resources/org/glassfish/jersey/client/internal/localization.properties b/core-client/src/main/resources/org/glassfish/jersey/client/internal/localization.properties
index e66ceab..ee80184 100644
--- a/core-client/src/main/resources/org/glassfish/jersey/client/internal/localization.properties
+++ b/core-client/src/main/resources/org/glassfish/jersey/client/internal/localization.properties
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License v. 2.0, which is available at
@@ -48,7 +48,14 @@
Using default cached thread pool.
negative.chunk.size=Negative chunked HTTP transfer coding chunk size value specified in the client configuration property: [{0}] \
Reverting to programmatically set default: [{1}]
-negative.input.parameter="Input parameter {0} must not be negative."
+negative.input.parameter="Input parameter {0} must not be negative1."
+noninject.ambiguous.services=Ambiguous providing services ${0}.
+noninject.fallback=Falling back to injection-less client.
+noninject.no.constructor=No applicable constructor for ${0} found.
+noninject.no.binding=No binding found for ${0}.
+noninject.requestscope.created=RequestScope already created.
+noninject.shutdown=InjectionManager is already shutdown.
+noninject.unsatisfied=Unsatisfied dependency for ${0}.
null.connector.provider=ConnectorProvider must not be set to null.
null.executor.service=ExecutorService must not be set to null.
null.input.parameter=Input method parameter {0} must not be null.
diff --git a/core-client/src/test/java/org/glassfish/jersey/client/ClientConfigTest.java b/core-client/src/test/java/org/glassfish/jersey/client/ClientConfigTest.java
index eff6b19..9dc98e5 100644
--- a/core-client/src/test/java/org/glassfish/jersey/client/ClientConfigTest.java
+++ b/core-client/src/test/java/org/glassfish/jersey/client/ClientConfigTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -112,7 +112,7 @@
}
@Provider
- public class MyProvider implements ContextResolver<String> {
+ public static class MyProvider implements ContextResolver<String> {
@Override
public String getContext(final Class<?> type) {
diff --git a/core-client/src/test/java/org/glassfish/jersey/client/JerseyClientTest.java b/core-client/src/test/java/org/glassfish/jersey/client/JerseyClientTest.java
index 41d9efb..fbee0e5 100644
--- a/core-client/src/test/java/org/glassfish/jersey/client/JerseyClientTest.java
+++ b/core-client/src/test/java/org/glassfish/jersey/client/JerseyClientTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -272,8 +272,12 @@
}
public static class CustomProvider implements ClientRequestFilter {
+ private final CustomContract customContract;
+
@Inject
- private CustomContract customContract;
+ CustomProvider(CustomContract customContract) {
+ this.customContract = customContract;
+ }
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
diff --git a/core-client/src/test/java/org/glassfish/jersey/client/JerseyCompletionStageRxInvokerTest.java b/core-client/src/test/java/org/glassfish/jersey/client/JerseyCompletionStageRxInvokerTest.java
index 53c9c28..0b1818d 100644
--- a/core-client/src/test/java/org/glassfish/jersey/client/JerseyCompletionStageRxInvokerTest.java
+++ b/core-client/src/test/java/org/glassfish/jersey/client/JerseyCompletionStageRxInvokerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -34,7 +34,6 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
@@ -71,7 +70,6 @@
}
@Test
- @Disabled("TODO JAX-RS 2.1")
public void testNewClientExecutor() throws Exception {
testClient(ClientBuilder.newBuilder()
.executorService(executor)
diff --git a/core-client/src/test/java/org/glassfish/jersey/client/spi/PreInvocationInterceptorTest.java b/core-client/src/test/java/org/glassfish/jersey/client/spi/PreInvocationInterceptorTest.java
index a438a58..d121b44 100644
--- a/core-client/src/test/java/org/glassfish/jersey/client/spi/PreInvocationInterceptorTest.java
+++ b/core-client/src/test/java/org/glassfish/jersey/client/spi/PreInvocationInterceptorTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -22,13 +22,13 @@
import org.junit.jupiter.api.Test;
import javax.annotation.Priority;
+import javax.inject.Inject;
import javax.ws.rs.ProcessingException;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.core.Configuration;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
@@ -263,8 +263,12 @@
}
private static class InjectedPreInvocationInterceptor implements PreInvocationInterceptor {
- @Context
- Configuration configuration;
+ private final Configuration configuration;
+
+ @Inject
+ public InjectedPreInvocationInterceptor(Configuration configuration) {
+ this.configuration = configuration;
+ }
@Override
public void beforeRequest(ClientRequestContext requestContext) {
diff --git a/core-common/src/main/java/org/glassfish/jersey/internal/JaxrsProviders.java b/core-common/src/main/java/org/glassfish/jersey/internal/JaxrsProviders.java
index 81364a1..d88730f 100644
--- a/core-common/src/main/java/org/glassfish/jersey/internal/JaxrsProviders.java
+++ b/core-common/src/main/java/org/glassfish/jersey/internal/JaxrsProviders.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -62,12 +62,18 @@
}
}
+ private final Provider<MessageBodyWorkers> workers;
+ private final Provider<ContextResolvers> resolvers;
+ private final Provider<ExceptionMappers> mappers;
+
@Inject
- private Provider<MessageBodyWorkers> workers;
- @Inject
- private Provider<ContextResolvers> resolvers;
- @Inject
- private Provider<ExceptionMappers> mappers;
+ public JaxrsProviders(Provider<MessageBodyWorkers> workers,
+ Provider<ContextResolvers> resolvers,
+ Provider<ExceptionMappers> mappers) {
+ this.workers = workers;
+ this.resolvers = resolvers;
+ this.mappers = mappers;
+ }
@Override
public <T> MessageBodyReader<T> getMessageBodyReader(Class<T> type,
diff --git a/core-common/src/main/java/org/glassfish/jersey/internal/inject/Injections.java b/core-common/src/main/java/org/glassfish/jersey/internal/inject/Injections.java
index d2ff00d..f944637 100644
--- a/core-common/src/main/java/org/glassfish/jersey/internal/inject/Injections.java
+++ b/core-common/src/main/java/org/glassfish/jersey/internal/inject/Injections.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -20,6 +20,8 @@
import java.util.List;
import java.util.Optional;
+import javax.ws.rs.ConstrainedTo;
+import javax.ws.rs.RuntimeType;
import javax.ws.rs.WebApplicationException;
import org.glassfish.jersey.internal.LocalizationMessages;
@@ -36,22 +38,32 @@
public class Injections {
/**
- * Creates a {@link InjectionManager} without parent and initial binder.
+ * Creates an {@link InjectionManager} without parent and initial binder.
*
- * @return a injection manager with all the bindings.
+ * @return an injection manager with all the bindings.
*/
public static InjectionManager createInjectionManager() {
- return lookupInjectionManagerFactory().create();
+ return lookupInjectionManagerFactory(RuntimeType.SERVER).create();
+ }
+
+ /**
+ * Creates an {@link InjectionManager} without parent and initial binder.
+ * @param type {@link RuntimeType} the {@link InjectionManagerFactory} must be {@link ConstrainedTo} if annotated.
+ *
+ * @return an injection manager with all the bindings.
+ */
+ public static InjectionManager createInjectionManager(RuntimeType type) {
+ return lookupInjectionManagerFactory(type).create();
}
/**
* Creates a {@link InjectionManager} with initial binder that is immediately registered.
*
* @param binder custom the {@link Binder binder}.
- * @return a injection manager with all the bindings.
+ * @return an injection manager with all the bindings.
*/
public static InjectionManager createInjectionManager(Binder binder) {
- InjectionManagerFactory injectionManagerFactory = lookupInjectionManagerFactory();
+ InjectionManagerFactory injectionManagerFactory = lookupInjectionManagerFactory(RuntimeType.SERVER);
InjectionManager injectionManager = injectionManagerFactory.create();
injectionManager.register(binder);
return injectionManager;
@@ -66,11 +78,11 @@
* @return an injection manager with all the bindings.
*/
public static InjectionManager createInjectionManager(Object parent) {
- return lookupInjectionManagerFactory().create(parent);
+ return lookupInjectionManagerFactory(RuntimeType.SERVER).create(parent);
}
- private static InjectionManagerFactory lookupInjectionManagerFactory() {
- return lookupService(InjectionManagerFactory.class)
+ private static InjectionManagerFactory lookupInjectionManagerFactory(RuntimeType type) {
+ return lookupService(InjectionManagerFactory.class, type)
.orElseThrow(() -> new IllegalStateException(LocalizationMessages.INJECTION_MANAGER_FACTORY_NOT_FOUND()));
}
@@ -80,12 +92,17 @@
*
* @param clazz type of service to look for.
* @param <T> type of service to look for.
+ * @param type {@link RuntimeType} the {@link InjectionManagerFactory} must be {@link ConstrainedTo} if annotated.
* @return instance of service with highest priority or {@code null} if service of given type cannot be found.
* @see javax.annotation.Priority
*/
- private static <T> Optional<T> lookupService(final Class<T> clazz) {
+ private static <T> Optional<T> lookupService(final Class<T> clazz, RuntimeType type) {
List<RankedProvider<T>> providers = new LinkedList<>();
for (T provider : ServiceFinder.find(clazz)) {
+ ConstrainedTo constrain = provider.getClass().getAnnotation(ConstrainedTo.class);
+ if (constrain != null && type != constrain.value()) {
+ continue;
+ }
providers.add(new RankedProvider<>(provider));
}
providers.sort(new RankedComparator<>(RankedComparator.Order.DESCENDING));
diff --git a/core-common/src/main/java/org/glassfish/jersey/message/internal/SourceProvider.java b/core-common/src/main/java/org/glassfish/jersey/message/internal/SourceProvider.java
index acd27d8..f140dfc 100644
--- a/core-common/src/main/java/org/glassfish/jersey/message/internal/SourceProvider.java
+++ b/core-common/src/main/java/org/glassfish/jersey/message/internal/SourceProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -22,11 +22,11 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import javax.inject.Inject;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.Consumes;
import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyReader;
@@ -95,7 +95,8 @@
private final Provider<SAXParserFactory> spf;
- public SaxSourceReader(@Context Provider<SAXParserFactory> spf) {
+ @Inject
+ public SaxSourceReader(Provider<SAXParserFactory> spf) {
this.spf = spf;
}
@@ -135,7 +136,8 @@
private final Provider<DocumentBuilderFactory> dbf;
- public DomSourceReader(@Context Provider<DocumentBuilderFactory> dbf) {
+ @Inject
+ public DomSourceReader(Provider<DocumentBuilderFactory> dbf) {
this.dbf = dbf;
}
@@ -176,8 +178,9 @@
private final Provider<SAXParserFactory> saxParserFactory;
private final Provider<TransformerFactory> transformerFactory;
- public SourceWriter(@Context Provider<SAXParserFactory> spf,
- @Context Provider<TransformerFactory> tf) {
+ @Inject
+ public SourceWriter(Provider<SAXParserFactory> spf,
+ Provider<TransformerFactory> tf) {
this.saxParserFactory = spf;
this.transformerFactory = tf;
}
diff --git a/ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/EntityInspectorImpl.java b/ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/EntityInspectorImpl.java
index 0e353f4..d5f4d71 100644
--- a/ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/EntityInspectorImpl.java
+++ b/ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/EntityInspectorImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -51,9 +51,7 @@
@Singleton
final class EntityInspectorImpl implements EntityInspector {
private final List<EntityProcessor> entityProcessors;
-
- @Inject
- private EntityGraphProvider graphProvider;
+ private final EntityGraphProvider graphProvider;
/**
* Constructor expecting {@link InjectionManager} to be injected.
@@ -61,10 +59,11 @@
* @param injectionManager injection manager to be injected.
*/
@Inject
- public EntityInspectorImpl(final InjectionManager injectionManager) {
+ public EntityInspectorImpl(final InjectionManager injectionManager, EntityGraphProvider graphProvider) {
Spliterator<EntityProcessor> entities =
Providers.getAllProviders(injectionManager, EntityProcessor.class, new RankedComparator<>()).spliterator();
this.entityProcessors = StreamSupport.stream(entities, false).collect(Collectors.toList());
+ this.graphProvider = graphProvider;
}
@Override
diff --git a/ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/ObjectGraphProvider.java b/ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/ObjectGraphProvider.java
index 5f911e3..6c8e85f 100644
--- a/ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/ObjectGraphProvider.java
+++ b/ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/ObjectGraphProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -17,7 +17,12 @@
package org.glassfish.jersey.message.filtering;
import org.glassfish.jersey.message.filtering.spi.AbstractObjectProvider;
+import org.glassfish.jersey.message.filtering.spi.EntityGraphProvider;
+import org.glassfish.jersey.message.filtering.spi.EntityInspector;
import org.glassfish.jersey.message.filtering.spi.ObjectGraph;
+import org.glassfish.jersey.message.filtering.spi.ScopeProvider;
+
+import javax.inject.Inject;
/**
* {@link org.glassfish.jersey.message.filtering.spi.ObjectProvider Object provider} and
@@ -28,6 +33,13 @@
*/
final class ObjectGraphProvider extends AbstractObjectProvider<ObjectGraph> {
+ @Inject
+ public ObjectGraphProvider(ScopeProvider scopeProvider,
+ EntityInspector entityInspector,
+ EntityGraphProvider graphProvider) {
+ super(scopeProvider, entityInspector, graphProvider);
+ }
+
@Override
public ObjectGraph transform(final ObjectGraph graph) {
return graph;
diff --git a/ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/spi/AbstractObjectProvider.java b/ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/spi/AbstractObjectProvider.java
index 94118cd..4793f21 100644
--- a/ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/spi/AbstractObjectProvider.java
+++ b/ext/entity-filtering/src/main/java/org/glassfish/jersey/message/filtering/spi/AbstractObjectProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -46,15 +46,18 @@
private final Cache<EntityContext, T> filteringObjects = CacheBuilder.newBuilder().maximumSize(PROVIDER_CACHE_SIZE).build();
- @Inject
private ScopeProvider scopeProvider;
-
- @Inject
private EntityInspector entityInspector;
-
- @Inject
private EntityGraphProvider graphProvider;
+ public AbstractObjectProvider(ScopeProvider scopeProvider,
+ EntityInspector entityInspector,
+ EntityGraphProvider graphProvider) {
+ this.scopeProvider = scopeProvider;
+ this.entityInspector = entityInspector;
+ this.graphProvider = graphProvider;
+ }
+
@Override
public final T getFilteringObject(final Type genericType, final boolean forWriter, final Annotation... annotations) {
return getFilteringObject(FilteringHelper.getEntityClass(genericType), forWriter, annotations);
diff --git a/ext/metainf-services/src/test/java/org/glassfish/jersey/message/MetaInfServicesTest.java b/ext/metainf-services/src/test/java/org/glassfish/jersey/message/MetaInfServicesTest.java
index f1ad7da..cb0c845 100644
--- a/ext/metainf-services/src/test/java/org/glassfish/jersey/message/MetaInfServicesTest.java
+++ b/ext/metainf-services/src/test/java/org/glassfish/jersey/message/MetaInfServicesTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -22,13 +22,13 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import javax.inject.Inject;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Configuration;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
@@ -72,7 +72,10 @@
public static class MessageProvider implements MessageBodyReader<MetaInf>, MessageBodyWriter<MetaInf> {
- @Context
+ @Inject
+ MessageProvider(Configuration configuration) {
+ this.config = configuration;
+ }
private Configuration config;
@Override
diff --git a/incubator/cdi-inject-weld/src/test/java/org/glassfish/jersey/inject/weld/internal/injector/JerseyProxyResolverTest.java b/incubator/cdi-inject-weld/src/test/java/org/glassfish/jersey/inject/weld/internal/injector/JerseyProxyResolverTest.java
index 521b805..486aad0 100644
--- a/incubator/cdi-inject-weld/src/test/java/org/glassfish/jersey/inject/weld/internal/injector/JerseyProxyResolverTest.java
+++ b/incubator/cdi-inject-weld/src/test/java/org/glassfish/jersey/inject/weld/internal/injector/JerseyProxyResolverTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -96,7 +96,7 @@
@Test
public void testProxyCreated() {
- MyInjectionResolver injectionResolver = new MyInjectionResolver(new JaxrsProviders());
+ MyInjectionResolver injectionResolver = new MyInjectionResolver(new JaxrsProviders(null, null, null));
InjecteeImpl injectee = new InjecteeImpl();
injectee.setRequiredType(Providers.class);
injectee.setParent(FIELDS[0]);
@@ -108,7 +108,7 @@
@Test
public void testProxyCached() {
- MyInjectionResolver injectionResolver = new MyInjectionResolver(new JaxrsProviders());
+ MyInjectionResolver injectionResolver = new MyInjectionResolver(new JaxrsProviders(null, null, null));
InjecteeImpl injectee1 = new InjecteeImpl();
injectee1.setRequiredType(Providers.class);
injectee1.setParent(FIELDS[0]);
@@ -125,7 +125,7 @@
@Test
public void testProxyCacheNotMismatched() {
- MyInjectionResolver injectionResolver1 = new MyInjectionResolver(new JaxrsProviders());
+ MyInjectionResolver injectionResolver1 = new MyInjectionResolver(new JaxrsProviders(null, null, null));
InjecteeImpl injectee1 = new InjecteeImpl();
injectee1.setRequiredType(Providers.class);
injectee1.setParent(FIELDS[0]);
diff --git a/incubator/injectless-client/pom.xml b/incubator/injectless-client/pom.xml
new file mode 100644
index 0000000..91b14fd
--- /dev/null
+++ b/incubator/injectless-client/pom.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
+
+ This program and the accompanying materials are made available under the
+ terms of the Eclipse Public License v. 2.0, which is available at
+ http://www.eclipse.org/legal/epl-2.0.
+
+ This Source Code may also be made available under the following Secondary
+ Licenses when the conditions for such availability set forth in the
+ Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ version 2 with the GNU Classpath Exception, which is available at
+ https://www.gnu.org/software/classpath/license.html.
+
+ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.glassfish.jersey.incubator</groupId>
+ <artifactId>project</artifactId>
+ <version>2.39-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>jersey-injectless-client</artifactId>
+ <packaging>jar</packaging>
+ <name>jersey-inject-injectless-client</name>
+
+ <description>Client side support of no injection mechanism</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-client</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <inherited>true</inherited>
+ <extensions>true</extensions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/incubator/injectless-client/src/main/java/org/glassfish/jersey/inject/injectless/NonInjectionManagerFactory.java b/incubator/injectless-client/src/main/java/org/glassfish/jersey/inject/injectless/NonInjectionManagerFactory.java
new file mode 100644
index 0000000..43b17aa
--- /dev/null
+++ b/incubator/injectless-client/src/main/java/org/glassfish/jersey/inject/injectless/NonInjectionManagerFactory.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+package org.glassfish.jersey.inject.injectless;
+
+import org.glassfish.jersey.client.innate.inject.NonInjectionManager;
+import org.glassfish.jersey.internal.inject.InjectionManager;
+import org.glassfish.jersey.internal.inject.InjectionManagerFactory;
+
+import javax.annotation.Priority;
+import javax.inject.Inject;
+import javax.ws.rs.ConstrainedTo;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.RuntimeType;
+
+/**
+ * <p>
+ * This {@link InjectionManagerFactory} implementation provides a special {@link InjectionManager}. The highest priority
+ * of this injection manager is not to require any DI container. It is designed for pure REST client performing a request
+ * without a further requirements for performing injections in the customer client classes, such a filter or a provider.
+ * It means the customer classes do not have any injection points defined by {@link Inject} or {@link Context}.
+ * </p>
+ * <p>
+ * Using this injection manager does not prevent using any Jersey modules (such as Jersey-Media-Jackson module) from working
+ * with the client.
+ * </p>
+ */
+@Priority(15)
+@ConstrainedTo(RuntimeType.CLIENT)
+public class NonInjectionManagerFactory implements InjectionManagerFactory {
+ @Override
+ public InjectionManager create(Object parent) {
+ return new NonInjectionManager(false);
+ }
+}
diff --git a/incubator/injectless-client/src/main/resources/META-INF/services/org.glassfish.jersey.internal.inject.InjectionManagerFactory b/incubator/injectless-client/src/main/resources/META-INF/services/org.glassfish.jersey.internal.inject.InjectionManagerFactory
new file mode 100644
index 0000000..8473fa4
--- /dev/null
+++ b/incubator/injectless-client/src/main/resources/META-INF/services/org.glassfish.jersey.internal.inject.InjectionManagerFactory
@@ -0,0 +1 @@
+org.glassfish.jersey.inject.injectless.NonInjectionManagerFactory
\ No newline at end of file
diff --git a/incubator/kryo/src/main/java/org/glassfish/jersey/kryo/internal/KryoMessageBodyProvider.java b/incubator/kryo/src/main/java/org/glassfish/jersey/kryo/internal/KryoMessageBodyProvider.java
index 096c0a8..35c695a 100644
--- a/incubator/kryo/src/main/java/org/glassfish/jersey/kryo/internal/KryoMessageBodyProvider.java
+++ b/incubator/kryo/src/main/java/org/glassfish/jersey/kryo/internal/KryoMessageBodyProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -23,11 +23,10 @@
import java.lang.reflect.Type;
import java.util.Optional;
+import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Configuration;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.ContextResolver;
@@ -55,7 +54,8 @@
private final ContextResolver<Kryo> contextResolver;
private final Optional<KryoPool> kryoPool;
- public KryoMessageBodyProvider(@Context Providers providers) {
+ @Inject
+ public KryoMessageBodyProvider(Providers providers) {
final MediaType mediaType = new MediaType("application", "x-kryo");
contextResolver = providers.getContextResolver(Kryo.class, mediaType);
kryoPool = getKryoPool();
diff --git a/incubator/pom.xml b/incubator/pom.xml
index 3718fc2..bd095bf 100644
--- a/incubator/pom.xml
+++ b/incubator/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2011, 2022 Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2011, 2023 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
@@ -40,6 +40,7 @@
<module>declarative-linking</module>
<module>gae-integration</module>
<module>html-json</module>
+ <module>injectless-client</module>
<module>kryo</module>
<module>open-tracing</module>
</modules>
diff --git a/inject/cdi2-se/src/test/java/org/glassfish/jersey/inject/cdi/se/injector/JerseyProxyResolverTest.java b/inject/cdi2-se/src/test/java/org/glassfish/jersey/inject/cdi/se/injector/JerseyProxyResolverTest.java
index 5f071b1..b0de0e6 100644
--- a/inject/cdi2-se/src/test/java/org/glassfish/jersey/inject/cdi/se/injector/JerseyProxyResolverTest.java
+++ b/inject/cdi2-se/src/test/java/org/glassfish/jersey/inject/cdi/se/injector/JerseyProxyResolverTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -97,7 +97,7 @@
@Test
public void testProxyCreated() {
- MyInjectionResolver injectionResolver = new MyInjectionResolver(new JaxrsProviders());
+ MyInjectionResolver injectionResolver = new MyInjectionResolver(new JaxrsProviders(null, null, null));
InjecteeImpl injectee = new InjecteeImpl();
injectee.setRequiredType(Providers.class);
injectee.setParent(FIELDS[0]);
@@ -109,7 +109,7 @@
@Test
public void testProxyCached() {
- MyInjectionResolver injectionResolver = new MyInjectionResolver(new JaxrsProviders());
+ MyInjectionResolver injectionResolver = new MyInjectionResolver(new JaxrsProviders(null, null, null));
InjecteeImpl injectee1 = new InjecteeImpl();
injectee1.setRequiredType(Providers.class);
injectee1.setParent(FIELDS[0]);
@@ -126,7 +126,7 @@
@Test
public void testProxyCacheNotMismatched() {
- MyInjectionResolver injectionResolver1 = new MyInjectionResolver(new JaxrsProviders());
+ MyInjectionResolver injectionResolver1 = new MyInjectionResolver(new JaxrsProviders(null, null, null));
InjecteeImpl injectee1 = new InjecteeImpl();
injectee1.setRequiredType(Providers.class);
injectee1.setParent(FIELDS[0]);
diff --git a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractCollectionJaxbProvider.java b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractCollectionJaxbProvider.java
index 075e866..ec70496 100644
--- a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractCollectionJaxbProvider.java
+++ b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractCollectionJaxbProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -39,6 +39,7 @@
import javax.ws.rs.BadRequestException;
import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.NoContentException;
@@ -120,12 +121,12 @@
}
};
- public AbstractCollectionJaxbProvider(Providers ps) {
- super(ps);
+ public AbstractCollectionJaxbProvider(Providers ps, Configuration config) {
+ super(ps, config);
}
- public AbstractCollectionJaxbProvider(Providers ps, MediaType mt) {
- super(ps, mt);
+ public AbstractCollectionJaxbProvider(Providers ps, MediaType mt, Configuration config) {
+ super(ps, mt, config);
}
@Override
diff --git a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractJaxbElementProvider.java b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractJaxbElementProvider.java
index 78cc2fd..9481a8c 100644
--- a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractJaxbElementProvider.java
+++ b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractJaxbElementProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -27,6 +27,7 @@
import javax.ws.rs.BadRequestException;
import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.NoContentException;
@@ -67,8 +68,8 @@
*
* @param providers JAX-RS providers.
*/
- public AbstractJaxbElementProvider(Providers providers) {
- super(providers);
+ public AbstractJaxbElementProvider(Providers providers, Configuration config) {
+ super(providers, config);
}
/**
@@ -77,8 +78,8 @@
* @param providers JAX-RS providers.
* @param resolverMediaType JAXB component context resolver media type to be used.
*/
- public AbstractJaxbElementProvider(Providers providers, MediaType resolverMediaType) {
- super(providers, resolverMediaType);
+ public AbstractJaxbElementProvider(Providers providers, MediaType resolverMediaType, Configuration config) {
+ super(providers, resolverMediaType, config);
}
@Override
diff --git a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractJaxbProvider.java b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractJaxbProvider.java
index f512398..04342c4 100644
--- a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractJaxbProvider.java
+++ b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractJaxbProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -25,7 +25,6 @@
import java.util.logging.Logger;
import javax.ws.rs.core.Configuration;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.Providers;
@@ -71,8 +70,8 @@
*
* @param providers JAX-RS providers.
*/
- public AbstractJaxbProvider(final Providers providers) {
- this(providers, null);
+ public AbstractJaxbProvider(final Providers providers, final Configuration config) {
+ this(providers, null, config);
}
/**
@@ -81,7 +80,7 @@
* @param providers JAX-RS providers.
* @param resolverMediaType JAXB component context resolver media type to be used.
*/
- public AbstractJaxbProvider(final Providers providers, final MediaType resolverMediaType) {
+ public AbstractJaxbProvider(final Providers providers, final MediaType resolverMediaType, final Configuration config) {
this.jaxrsProviders = providers;
fixedResolverMediaType = resolverMediaType != null;
@@ -112,10 +111,10 @@
this.mtUnmarshaller = null;
this.mtMarshaller = null;
}
+ setConfiguration(config);
}
// TODO This provider should be registered and configured via a feature.
- @Context
public void setConfiguration(final Configuration config) {
formattedOutput = Values.lazy(new Value<Boolean>() {
diff --git a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractRootElementJaxbProvider.java b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractRootElementJaxbProvider.java
index 9d686e7..261e982 100644
--- a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractRootElementJaxbProvider.java
+++ b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/AbstractRootElementJaxbProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -26,6 +26,7 @@
import javax.ws.rs.BadRequestException;
import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.NoContentException;
@@ -69,8 +70,8 @@
*
* @param providers JAX-RS providers.
*/
- public AbstractRootElementJaxbProvider(Providers providers) {
- super(providers);
+ public AbstractRootElementJaxbProvider(Providers providers, Configuration config) {
+ super(providers, config);
}
/**
@@ -79,8 +80,8 @@
* @param providers JAX-RS providers.
* @param resolverMediaType JAXB component context resolver media type to be used.
*/
- public AbstractRootElementJaxbProvider(Providers providers, MediaType resolverMediaType) {
- super(providers, resolverMediaType);
+ public AbstractRootElementJaxbProvider(Providers providers, MediaType resolverMediaType, Configuration config) {
+ super(providers, resolverMediaType, config);
}
@Override
diff --git a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/DocumentBuilderFactoryInjectionProvider.java b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/DocumentBuilderFactoryInjectionProvider.java
index b5b3ec8..064482b 100644
--- a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/DocumentBuilderFactoryInjectionProvider.java
+++ b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/DocumentBuilderFactoryInjectionProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -39,11 +39,11 @@
*/
// TODO This provider should be registered and configured via a feature.
@Inject
- public DocumentBuilderFactoryInjectionProvider(final Configuration config) {
+ public DocumentBuilderFactoryInjectionProvider(final InjectionManager injectionManager, final Configuration config) {
super(config);
+ this.injectionManager = injectionManager;
}
- @Inject
private InjectionManager injectionManager;
@Override
diff --git a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/DocumentProvider.java b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/DocumentProvider.java
index b175bc9..6dccd66 100644
--- a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/DocumentProvider.java
+++ b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/DocumentProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -55,10 +55,14 @@
@Singleton
public final class DocumentProvider extends AbstractMessageReaderWriterProvider<Document> {
+ private final Provider<DocumentBuilderFactory> dbf;
+ private final Provider<TransformerFactory> tf;
+
@Inject
- private Provider<DocumentBuilderFactory> dbf;
- @Inject
- private Provider<TransformerFactory> tf;
+ public DocumentProvider(Provider<DocumentBuilderFactory> dbf, Provider<TransformerFactory> tf) {
+ this.dbf = dbf;
+ this.tf = tf;
+ }
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
diff --git a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/SaxParserFactoryInjectionProvider.java b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/SaxParserFactoryInjectionProvider.java
index 4b1bbb3..6103bce 100644
--- a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/SaxParserFactoryInjectionProvider.java
+++ b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/SaxParserFactoryInjectionProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -49,11 +49,11 @@
*/
// TODO This provider should be registered and configured via a feature.
@Inject
- public SaxParserFactoryInjectionProvider(final Configuration config) {
+ public SaxParserFactoryInjectionProvider(final InjectionManager injectionManager, final Configuration config) {
super(config);
+ this.injectionManager = injectionManager;
}
- @Inject
private InjectionManager injectionManager;
@Override
diff --git a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/TransformerFactoryInjectionProvider.java b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/TransformerFactoryInjectionProvider.java
index fb13b3f..364e9b6 100644
--- a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/TransformerFactoryInjectionProvider.java
+++ b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/TransformerFactoryInjectionProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -45,11 +45,11 @@
*/
// TODO This provider should be registered and configured via a feature.
@Inject
- public TransformerFactoryInjectionProvider(final Configuration config) {
+ public TransformerFactoryInjectionProvider(final InjectionManager injectionManager, final Configuration config) {
super(config);
+ this.injectionManager = injectionManager;
}
- @Inject
private InjectionManager injectionManager;
@Override
diff --git a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlCollectionJaxbProvider.java b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlCollectionJaxbProvider.java
index f5e8e1b..b9e4191 100644
--- a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlCollectionJaxbProvider.java
+++ b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlCollectionJaxbProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -24,9 +24,10 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Providers;
@@ -50,14 +51,14 @@
private final Provider<XMLInputFactory> xif;
- XmlCollectionJaxbProvider(Provider<XMLInputFactory> xif, Providers ps) {
- super(ps);
+ XmlCollectionJaxbProvider(Provider<XMLInputFactory> xif, Providers ps, Configuration config) {
+ super(ps, config);
this.xif = xif;
}
- XmlCollectionJaxbProvider(Provider<XMLInputFactory> xif, Providers ps, MediaType mt) {
- super(ps, mt);
+ XmlCollectionJaxbProvider(Provider<XMLInputFactory> xif, Providers ps, MediaType mt, Configuration config) {
+ super(ps, mt, config);
this.xif = xif;
}
@@ -71,8 +72,9 @@
@Singleton
public static final class App extends XmlCollectionJaxbProvider {
- public App(@Context Provider<XMLInputFactory> xif, @Context Providers ps) {
- super(xif, ps, MediaType.APPLICATION_XML_TYPE);
+ @Inject
+ public App(Provider<XMLInputFactory> xif, Providers ps, Configuration config) {
+ super(xif, ps, MediaType.APPLICATION_XML_TYPE, config);
}
}
@@ -85,8 +87,9 @@
@Singleton
public static final class Text extends XmlCollectionJaxbProvider {
- public Text(@Context Provider<XMLInputFactory> xif, @Context Providers ps) {
- super(xif, ps, MediaType.TEXT_XML_TYPE);
+ @Inject
+ public Text(Provider<XMLInputFactory> xif, Providers ps, Configuration config) {
+ super(xif, ps, MediaType.TEXT_XML_TYPE, config);
}
}
@@ -99,8 +102,9 @@
@Singleton
public static final class General extends XmlCollectionJaxbProvider {
- public General(@Context Provider<XMLInputFactory> xif, @Context Providers ps) {
- super(xif, ps);
+ @Inject
+ public General(Provider<XMLInputFactory> xif, Providers ps, Configuration config) {
+ super(xif, ps, config);
}
@Override
diff --git a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlInputFactoryInjectionProvider.java b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlInputFactoryInjectionProvider.java
index 64b48c1..0c5a936 100644
--- a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlInputFactoryInjectionProvider.java
+++ b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlInputFactoryInjectionProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2021 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -38,11 +38,11 @@
*/
// TODO This provider should be registered and configured via a feature.
@Inject
- public XmlInputFactoryInjectionProvider(final Configuration config) {
+ public XmlInputFactoryInjectionProvider(final InjectionManager injectionManager, final Configuration config) {
super(config);
+ this.injectionManager = injectionManager;
}
- @Inject
private InjectionManager injectionManager;
@Override
diff --git a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlJaxbElementProvider.java b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlJaxbElementProvider.java
index 69e9d46..bd5ee4d 100644
--- a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlJaxbElementProvider.java
+++ b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlJaxbElementProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -20,9 +20,10 @@
import java.io.OutputStream;
import java.nio.charset.Charset;
+import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Providers;
@@ -44,14 +45,14 @@
private final Provider<SAXParserFactory> spf;
- public XmlJaxbElementProvider(Provider<SAXParserFactory> spf, Providers ps) {
- super(ps);
+ public XmlJaxbElementProvider(Provider<SAXParserFactory> spf, Providers ps, Configuration config) {
+ super(ps, config);
this.spf = spf;
}
- public XmlJaxbElementProvider(Provider<SAXParserFactory> spf, Providers ps, MediaType mt) {
- super(ps, mt);
+ public XmlJaxbElementProvider(Provider<SAXParserFactory> spf, Providers ps, MediaType mt, Configuration config) {
+ super(ps, mt, config);
this.spf = spf;
}
@@ -65,8 +66,9 @@
@Singleton
public static final class App extends XmlJaxbElementProvider {
- public App(@Context Provider<SAXParserFactory> spf, @Context Providers ps) {
- super(spf, ps, MediaType.APPLICATION_XML_TYPE);
+ @Inject
+ public App(Provider<SAXParserFactory> spf, Providers ps, Configuration config) {
+ super(spf, ps, MediaType.APPLICATION_XML_TYPE, config);
}
}
@@ -79,8 +81,9 @@
@Singleton
public static final class Text extends XmlJaxbElementProvider {
- public Text(@Context Provider<SAXParserFactory> spf, @Context Providers ps) {
- super(spf, ps, MediaType.TEXT_XML_TYPE);
+ @Inject
+ public Text(Provider<SAXParserFactory> spf, Providers ps, Configuration config) {
+ super(spf, ps, MediaType.TEXT_XML_TYPE, config);
}
}
@@ -93,8 +96,9 @@
@Singleton
public static final class General extends XmlJaxbElementProvider {
- public General(@Context Provider<SAXParserFactory> spf, @Context Providers ps) {
- super(spf, ps);
+ @Inject
+ public General(Provider<SAXParserFactory> spf, Providers ps, Configuration config) {
+ super(spf, ps, config);
}
@Override
diff --git a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlRootElementJaxbProvider.java b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlRootElementJaxbProvider.java
index 6a3f8e3..1418c24 100644
--- a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlRootElementJaxbProvider.java
+++ b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlRootElementJaxbProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -18,9 +18,10 @@
import java.io.InputStream;
+import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Providers;
@@ -45,14 +46,14 @@
// Delay construction of factory
private final Provider<SAXParserFactory> spf;
- XmlRootElementJaxbProvider(Provider<SAXParserFactory> spf, Providers ps) {
- super(ps);
+ XmlRootElementJaxbProvider(Provider<SAXParserFactory> spf, Providers ps, Configuration config) {
+ super(ps, config);
this.spf = spf;
}
- XmlRootElementJaxbProvider(Provider<SAXParserFactory> spf, Providers ps, MediaType mt) {
- super(ps, mt);
+ XmlRootElementJaxbProvider(Provider<SAXParserFactory> spf, Providers ps, MediaType mt, Configuration config) {
+ super(ps, mt, config);
this.spf = spf;
}
@@ -67,8 +68,9 @@
@Singleton
public static final class App extends XmlRootElementJaxbProvider {
- public App(@Context Provider<SAXParserFactory> spf, @Context Providers ps) {
- super(spf, ps, MediaType.APPLICATION_XML_TYPE);
+ @Inject
+ public App(Provider<SAXParserFactory> spf, Providers ps, Configuration config) {
+ super(spf, ps, MediaType.APPLICATION_XML_TYPE, config);
}
}
@@ -82,8 +84,9 @@
@Singleton
public static final class Text extends XmlRootElementJaxbProvider {
- public Text(@Context Provider<SAXParserFactory> spf, @Context Providers ps) {
- super(spf, ps, MediaType.TEXT_XML_TYPE);
+ @Inject
+ public Text(Provider<SAXParserFactory> spf, Providers ps, Configuration config) {
+ super(spf, ps, MediaType.TEXT_XML_TYPE, config);
}
}
@@ -97,8 +100,9 @@
@Singleton
public static final class General extends XmlRootElementJaxbProvider {
- public General(@Context Provider<SAXParserFactory> spf, @Context Providers ps) {
- super(spf, ps);
+ @Inject
+ public General(Provider<SAXParserFactory> spf, Providers ps, Configuration config) {
+ super(spf, ps, config);
}
@Override
diff --git a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlRootObjectJaxbProvider.java b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlRootObjectJaxbProvider.java
index fa0e3ce..b8c2950 100644
--- a/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlRootObjectJaxbProvider.java
+++ b/media/jaxb/src/main/java/org/glassfish/jersey/jaxb/internal/XmlRootObjectJaxbProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -22,12 +22,13 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import javax.inject.Inject;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.Consumes;
import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.NoContentException;
@@ -53,14 +54,14 @@
private final Provider<SAXParserFactory> spf;
- XmlRootObjectJaxbProvider(Provider<SAXParserFactory> spf, Providers ps) {
- super(ps);
+ XmlRootObjectJaxbProvider(Provider<SAXParserFactory> spf, Providers ps, Configuration config) {
+ super(ps, config);
this.spf = spf;
}
- XmlRootObjectJaxbProvider(Provider<SAXParserFactory> spf, Providers ps, MediaType mt) {
- super(ps, mt);
+ XmlRootObjectJaxbProvider(Provider<SAXParserFactory> spf, Providers ps, MediaType mt, Configuration config) {
+ super(ps, mt, config);
this.spf = spf;
}
@@ -79,8 +80,9 @@
@Singleton
public static final class App extends XmlRootObjectJaxbProvider {
- public App(@Context Provider<SAXParserFactory> spf, @Context Providers ps) {
- super(spf, ps, MediaType.APPLICATION_XML_TYPE);
+ @Inject
+ public App(Provider<SAXParserFactory> spf, Providers ps, Configuration config) {
+ super(spf, ps, MediaType.APPLICATION_XML_TYPE, config);
}
}
@@ -93,8 +95,9 @@
@Singleton
public static final class Text extends XmlRootObjectJaxbProvider {
- public Text(@Context Provider<SAXParserFactory> spf, @Context Providers ps) {
- super(spf, ps, MediaType.TEXT_XML_TYPE);
+ @Inject
+ public Text(Provider<SAXParserFactory> spf, Providers ps, Configuration config) {
+ super(spf, ps, MediaType.TEXT_XML_TYPE, config);
}
}
@@ -107,8 +110,9 @@
@Singleton
public static final class General extends XmlRootObjectJaxbProvider {
- public General(@Context Provider<SAXParserFactory> spf, @Context Providers ps) {
- super(spf, ps);
+ @Inject
+ public General(Provider<SAXParserFactory> spf, Providers ps, Configuration config) {
+ super(spf, ps, config);
}
@Override
diff --git a/media/jaxb/src/test/java/org/glassfish/jersey/jaxb/internal/JaxbStringReaderProviderTest.java b/media/jaxb/src/test/java/org/glassfish/jersey/jaxb/internal/JaxbStringReaderProviderTest.java
index 38793d8..9e9b89a 100644
--- a/media/jaxb/src/test/java/org/glassfish/jersey/jaxb/internal/JaxbStringReaderProviderTest.java
+++ b/media/jaxb/src/test/java/org/glassfish/jersey/jaxb/internal/JaxbStringReaderProviderTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -48,7 +48,7 @@
public void stringReaderDoesNotReadExternalDtds() {
Provider<SAXParserFactory> saxParserFactoryProvider = new Provider<SAXParserFactory>() {
- final SaxParserFactoryInjectionProvider spf = new SaxParserFactoryInjectionProvider(
+ final SaxParserFactoryInjectionProvider spf = new SaxParserFactoryInjectionProvider(null,
new CommonConfig(RuntimeType.SERVER, ComponentBag.INCLUDE_ALL));
@Override
diff --git a/media/json-binding/src/main/java/org/glassfish/jersey/jsonb/internal/JsonBindingProvider.java b/media/json-binding/src/main/java/org/glassfish/jersey/jsonb/internal/JsonBindingProvider.java
index 3ac8031..f2662c0 100644
--- a/media/json-binding/src/main/java/org/glassfish/jersey/jsonb/internal/JsonBindingProvider.java
+++ b/media/json-binding/src/main/java/org/glassfish/jersey/jsonb/internal/JsonBindingProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -22,11 +22,11 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.ProcessingException;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.NoContentException;
@@ -55,9 +55,10 @@
private static final String JSON = "json";
private static final String PLUS_JSON = "+json";
- private Providers providers;
+ private final Providers providers;
- public JsonBindingProvider(@Context Providers providers) {
+ @Inject
+ public JsonBindingProvider(Providers providers) {
this.providers = providers;
}
diff --git a/media/json-gson/src/main/java/org/glassfish/jersey/gson/internal/JsonGsonProvider.java b/media/json-gson/src/main/java/org/glassfish/jersey/gson/internal/JsonGsonProvider.java
index 3799af1..7375fd3 100644
--- a/media/json-gson/src/main/java/org/glassfish/jersey/gson/internal/JsonGsonProvider.java
+++ b/media/json-gson/src/main/java/org/glassfish/jersey/gson/internal/JsonGsonProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -23,11 +23,11 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.ProcessingException;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.NoContentException;
@@ -56,7 +56,8 @@
private Providers providers;
- public JsonGsonProvider(@Context Providers providers) {
+ @Inject
+ public JsonGsonProvider(Providers providers) {
this.providers = providers;
}
diff --git a/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/DefaultJacksonJaxbJsonProvider.java b/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/DefaultJacksonJaxbJsonProvider.java
index a75544c..7a803d8 100644
--- a/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/DefaultJacksonJaxbJsonProvider.java
+++ b/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/DefaultJacksonJaxbJsonProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2020, 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2020, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -25,26 +25,27 @@
import java.util.Arrays;
import java.util.List;
import javax.annotation.PostConstruct;
+import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.core.Configuration;
-import javax.ws.rs.core.Context;
+import javax.ws.rs.ext.Providers;
/**
* Entity Data provider based on Jackson JSON provider.
*/
@Singleton
public class DefaultJacksonJaxbJsonProvider extends JacksonJaxbJsonProvider {
-
- @Context
private Configuration commonConfig;
+ @Inject
+ public DefaultJacksonJaxbJsonProvider(Providers providers, Configuration config) {
+ this.commonConfig = config;
+ _providers = providers;
+ }
+
//do not register JaxbAnnotationModule because it brakes default annotations processing
private static final String EXCLUDE_MODULE_NAME = "JaxbAnnotationModule";
- public DefaultJacksonJaxbJsonProvider() {
- super();
- }
-
public DefaultJacksonJaxbJsonProvider(final Annotations... annotationsToUse) {
super(annotationsToUse);
}
diff --git a/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/FilteringJacksonJaxbJsonProvider.java b/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/FilteringJacksonJaxbJsonProvider.java
index 328697c..641a078 100644
--- a/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/FilteringJacksonJaxbJsonProvider.java
+++ b/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/FilteringJacksonJaxbJsonProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -22,12 +22,14 @@
import java.lang.reflect.Method;
import java.lang.reflect.Type;
+import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
+import javax.ws.rs.ext.Providers;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.jackson.internal.jackson.jaxrs.cfg.EndpointConfigBase;
@@ -57,8 +59,15 @@
@Singleton
public final class FilteringJacksonJaxbJsonProvider extends DefaultJacksonJaxbJsonProvider {
+ private final Provider<ObjectProvider<FilterProvider>> provider;
+
@Inject
- private Provider<ObjectProvider<FilterProvider>> provider;
+ public FilteringJacksonJaxbJsonProvider(Provider<ObjectProvider<FilterProvider>> provider,
+ Providers providers, Configuration config) {
+ super(providers, config);
+ this.provider = provider;
+ }
+
@Override
protected JsonEndpointConfig _configForWriting(final ObjectMapper mapper, final Annotation[] annotations,
diff --git a/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/JacksonObjectProvider.java b/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/JacksonObjectProvider.java
index d341486..46f5ebb 100644
--- a/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/JacksonObjectProvider.java
+++ b/media/json-jackson/src/main/java/org/glassfish/jersey/jackson/internal/JacksonObjectProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -23,6 +23,8 @@
import java.util.Stack;
import org.glassfish.jersey.message.filtering.spi.AbstractObjectProvider;
+import org.glassfish.jersey.message.filtering.spi.EntityGraphProvider;
+import org.glassfish.jersey.message.filtering.spi.EntityInspector;
import org.glassfish.jersey.message.filtering.spi.ObjectGraph;
import com.fasterxml.jackson.core.JsonGenerator;
@@ -35,12 +37,22 @@
import com.fasterxml.jackson.databind.ser.PropertyFilter;
import com.fasterxml.jackson.databind.ser.PropertyWriter;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
+import org.glassfish.jersey.message.filtering.spi.ScopeProvider;
+
+import javax.inject.Inject;
/**
* @author Michal Gajdos
*/
final class JacksonObjectProvider extends AbstractObjectProvider<FilterProvider> {
+ @Inject
+ public JacksonObjectProvider(ScopeProvider scopeProvider,
+ EntityInspector entityInspector,
+ EntityGraphProvider graphProvider) {
+ super(scopeProvider, entityInspector, graphProvider);
+ }
+
@Override
public FilterProvider transform(final ObjectGraph graph) {
// Root entity.
diff --git a/media/json-jackson/src/test/java/org/glassfish/jersey/jackson/internal/DefaultJsonJacksonProviderForDisabledModulesTest.java b/media/json-jackson/src/test/java/org/glassfish/jersey/jackson/internal/DefaultJsonJacksonProviderForDisabledModulesTest.java
index 8d8075c..b34803e 100644
--- a/media/json-jackson/src/test/java/org/glassfish/jersey/jackson/internal/DefaultJsonJacksonProviderForDisabledModulesTest.java
+++ b/media/json-jackson/src/test/java/org/glassfish/jersey/jackson/internal/DefaultJsonJacksonProviderForDisabledModulesTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -55,6 +55,9 @@
private static class TestJacksonJaxbJsonProvider extends JacksonJaxbJsonProvider {
@Inject
+ public TestJacksonJaxbJsonProvider(Configuration configuration) {
+ this.configuration = configuration;
+ }
private Configuration configuration;
@PostConstruct
diff --git a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonJaxbElementProvider.java b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonJaxbElementProvider.java
index 15feedf..55d302f 100644
--- a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonJaxbElementProvider.java
+++ b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonJaxbElementProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -24,9 +24,10 @@
import java.lang.reflect.Type;
import java.nio.charset.Charset;
+import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Providers;
@@ -47,12 +48,12 @@
*/
public class JettisonJaxbElementProvider extends AbstractJaxbElementProvider {
- JettisonJaxbElementProvider(Providers ps) {
- super(ps);
+ JettisonJaxbElementProvider(Providers ps, Configuration config) {
+ super(ps, config);
}
- JettisonJaxbElementProvider(Providers ps, MediaType mt) {
- super(ps, mt);
+ JettisonJaxbElementProvider(Providers ps, MediaType mt, Configuration config) {
+ super(ps, mt, config);
}
@Override
@@ -69,8 +70,9 @@
@Consumes("application/json")
public static final class App extends JettisonJaxbElementProvider {
- public App(@Context Providers ps) {
- super(ps, MediaType.APPLICATION_JSON_TYPE);
+ @Inject
+ public App(Providers ps, Configuration config) {
+ super(ps, MediaType.APPLICATION_JSON_TYPE, config);
}
}
@@ -78,8 +80,9 @@
@Consumes("*/*")
public static final class General extends JettisonJaxbElementProvider {
- public General(@Context Providers ps) {
- super(ps);
+ @Inject
+ public General(Providers ps, Configuration config) {
+ super(ps, config);
}
@Override
diff --git a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonListElementProvider.java b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonListElementProvider.java
index 777c000..93338fd 100644
--- a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonListElementProvider.java
+++ b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonListElementProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -28,9 +28,10 @@
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Providers;
@@ -54,12 +55,12 @@
*/
public class JettisonListElementProvider extends AbstractCollectionJaxbProvider {
- JettisonListElementProvider(Providers ps) {
- super(ps);
+ JettisonListElementProvider(Providers ps, Configuration config) {
+ super(ps, config);
}
- JettisonListElementProvider(Providers ps, MediaType mt) {
- super(ps, mt);
+ JettisonListElementProvider(Providers ps, MediaType mt, Configuration config) {
+ super(ps, mt, config);
}
@Override
@@ -75,9 +76,9 @@
@Produces("application/json")
@Consumes("application/json")
public static final class App extends JettisonListElementProvider {
-
- public App(@Context Providers ps) {
- super(ps, MediaType.APPLICATION_JSON_TYPE);
+ @Inject
+ public App(Providers ps, Configuration config) {
+ super(ps, MediaType.APPLICATION_JSON_TYPE, config);
}
}
@@ -85,8 +86,9 @@
@Consumes("*/*")
public static final class General extends JettisonListElementProvider {
- public General(@Context Providers ps) {
- super(ps);
+ @Inject
+ public General(Providers ps, Configuration config) {
+ super(ps, config);
}
@Override
diff --git a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonRootElementProvider.java b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonRootElementProvider.java
index f8674d0..6a5d7f6 100644
--- a/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonRootElementProvider.java
+++ b/media/json-jettison/src/main/java/org/glassfish/jersey/jettison/internal/entity/JettisonRootElementProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -24,9 +24,10 @@
import java.lang.reflect.Type;
import java.nio.charset.Charset;
+import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
+import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Providers;
@@ -48,12 +49,12 @@
*/
public class JettisonRootElementProvider extends AbstractRootElementJaxbProvider {
- JettisonRootElementProvider(Providers ps) {
- super(ps);
+ JettisonRootElementProvider(Providers ps, Configuration config) {
+ super(ps, config);
}
- JettisonRootElementProvider(Providers ps, MediaType mt) {
- super(ps, mt);
+ JettisonRootElementProvider(Providers ps, MediaType mt, Configuration config) {
+ super(ps, mt, config);
}
@Override
@@ -69,18 +70,18 @@
@Produces("application/json")
@Consumes("application/json")
public static final class App extends JettisonRootElementProvider {
-
- public App(@Context Providers ps) {
- super(ps, MediaType.APPLICATION_JSON_TYPE);
+ @Inject
+ public App(Providers ps, Configuration config) {
+ super(ps, MediaType.APPLICATION_JSON_TYPE, config);
}
}
@Produces("*/*")
@Consumes("*/*")
public static final class General extends JettisonRootElementProvider {
-
- public General(@Context Providers ps) {
- super(ps);
+ @Inject
+ public General(Providers ps, Configuration config) {
+ super(ps, config);
}
@Override
diff --git a/media/moxy/src/main/java/org/glassfish/jersey/moxy/internal/MoxyObjectProvider.java b/media/moxy/src/main/java/org/glassfish/jersey/moxy/internal/MoxyObjectProvider.java
index 4fd83f3..c6d7633 100644
--- a/media/moxy/src/main/java/org/glassfish/jersey/moxy/internal/MoxyObjectProvider.java
+++ b/media/moxy/src/main/java/org/glassfish/jersey/moxy/internal/MoxyObjectProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -20,9 +20,12 @@
import java.util.Map;
import java.util.Set;
+import javax.inject.Inject;
import javax.xml.bind.JAXBException;
import org.glassfish.jersey.message.filtering.spi.AbstractObjectProvider;
+import org.glassfish.jersey.message.filtering.spi.EntityGraphProvider;
+import org.glassfish.jersey.message.filtering.spi.EntityInspector;
import org.glassfish.jersey.message.filtering.spi.ObjectGraph;
import org.eclipse.persistence.jaxb.JAXBContext;
@@ -30,6 +33,7 @@
import org.eclipse.persistence.jaxb.JAXBHelper;
import org.eclipse.persistence.jaxb.Subgraph;
import org.eclipse.persistence.jaxb.TypeMappingInfo;
+import org.glassfish.jersey.message.filtering.spi.ScopeProvider;
/**
* @author Michal Gajdos
@@ -47,6 +51,13 @@
}
}
+ @Inject
+ public MoxyObjectProvider(ScopeProvider scopeProvider,
+ EntityInspector entityInspector,
+ EntityGraphProvider graphProvider) {
+ super(scopeProvider, entityInspector, graphProvider);
+ }
+
@Override
public org.eclipse.persistence.jaxb.ObjectGraph transform(final ObjectGraph graph) {
return createObjectGraph(graph.getEntityClass(), graph);
diff --git a/media/moxy/src/main/java/org/glassfish/jersey/moxy/json/internal/ConfigurableMoxyJsonProvider.java b/media/moxy/src/main/java/org/glassfish/jersey/moxy/json/internal/ConfigurableMoxyJsonProvider.java
index fea9192..afccd4a 100644
--- a/media/moxy/src/main/java/org/glassfish/jersey/moxy/json/internal/ConfigurableMoxyJsonProvider.java
+++ b/media/moxy/src/main/java/org/glassfish/jersey/moxy/json/internal/ConfigurableMoxyJsonProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -26,9 +26,9 @@
import java.util.Map;
import java.util.Set;
+import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.core.Configuration;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.ContextResolver;
@@ -77,11 +77,13 @@
return propertyNames;
}
- @Context
- private Providers providers;
+ private final Configuration config;
- @Context
- private Configuration config;
+ @Inject
+ public ConfigurableMoxyJsonProvider(Providers providers, Configuration config) {
+ this.providers = providers;
+ this.config = config;
+ }
private MoxyJsonConfig globalConfig;
diff --git a/media/moxy/src/main/java/org/glassfish/jersey/moxy/json/internal/FilteringMoxyJsonProvider.java b/media/moxy/src/main/java/org/glassfish/jersey/moxy/json/internal/FilteringMoxyJsonProvider.java
index 16ed85b..541d6f3 100644
--- a/media/moxy/src/main/java/org/glassfish/jersey/moxy/json/internal/FilteringMoxyJsonProvider.java
+++ b/media/moxy/src/main/java/org/glassfish/jersey/moxy/json/internal/FilteringMoxyJsonProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -19,12 +19,14 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
+import javax.ws.rs.ext.Providers;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
@@ -41,9 +43,15 @@
*/
@Singleton
public class FilteringMoxyJsonProvider extends ConfigurableMoxyJsonProvider {
+ private final Provider<ObjectProvider<ObjectGraph>> provider;
@Inject
- private Provider<ObjectProvider<ObjectGraph>> provider;
+ public FilteringMoxyJsonProvider(Provider<ObjectProvider<ObjectGraph>> provider,
+ Providers providers,
+ Configuration config) {
+ super(providers, config);
+ this.provider = provider;
+ }
@Override
protected void preWriteTo(final Object object, final Class<?> type, final Type genericType, final Annotation[] annotations,
diff --git a/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartReaderClientSide.java b/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartReaderClientSide.java
index 1511108..a9fa031 100644
--- a/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartReaderClientSide.java
+++ b/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartReaderClientSide.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -32,7 +32,6 @@
import javax.ws.rs.Consumes;
import javax.ws.rs.RuntimeType;
import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
@@ -77,16 +76,15 @@
* Injectable helper to look up appropriate {@link MessageBodyReader}s
* for our body parts.
*/
- @Inject
private Provider<MessageBodyWorkers> messageBodyWorkers;
-
private final MIMEConfig mimeConfig;
/**
* Accepts constructor injection of the configuration parameters for this
* application.
*/
- public MultiPartReaderClientSide(@Context final Providers providers) {
+ @Inject
+ public MultiPartReaderClientSide(final Providers providers, Provider<MessageBodyWorkers> messageBodyWorkers) {
final ContextResolver<MultiPartProperties> contextResolver =
providers.getContextResolver(MultiPartProperties.class, MediaType.WILDCARD_TYPE);
@@ -98,6 +96,7 @@
properties = new MultiPartProperties();
}
+ this.messageBodyWorkers = messageBodyWorkers;
mimeConfig = createMimeConfig(properties);
}
diff --git a/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartReaderServerSide.java b/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartReaderServerSide.java
index a7c9623..4858b0c 100644
--- a/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartReaderServerSide.java
+++ b/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartReaderServerSide.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -23,7 +23,6 @@
import javax.ws.rs.ConstrainedTo;
import javax.ws.rs.RuntimeType;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyReader;
@@ -34,6 +33,7 @@
import javax.inject.Singleton;
import org.glassfish.jersey.media.multipart.MultiPart;
+import org.glassfish.jersey.message.MessageBodyWorkers;
import org.glassfish.jersey.server.CloseableService;
import org.jvnet.mimepull.MIMEParsingException;
@@ -52,9 +52,10 @@
private final Provider<CloseableService> closeableServiceProvider;
@Inject
- public MultiPartReaderServerSide(@Context final Providers providers,
- final Provider<CloseableService> closeableServiceProvider) {
- super(providers);
+ public MultiPartReaderServerSide(final Providers providers,
+ final Provider<CloseableService> closeableServiceProvider,
+ final Provider<MessageBodyWorkers> messageBodyWorkers) {
+ super(providers, messageBodyWorkers);
this.closeableServiceProvider = closeableServiceProvider;
}
diff --git a/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartWriter.java b/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartWriter.java
index 7eb7b2b..941fb1d 100644
--- a/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartWriter.java
+++ b/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -27,9 +27,9 @@
import java.util.List;
import java.util.Map;
+import javax.inject.Inject;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
@@ -64,7 +64,8 @@
*/
private final Providers providers;
- public MultiPartWriter(@Context final Providers providers) {
+ @Inject
+ public MultiPartWriter(final Providers providers) {
this.providers = providers;
}
diff --git a/media/sse/src/main/java/org/glassfish/jersey/media/sse/EventInputReader.java b/media/sse/src/main/java/org/glassfish/jersey/media/sse/EventInputReader.java
index 6fd71cb..f3924c7 100644
--- a/media/sse/src/main/java/org/glassfish/jersey/media/sse/EventInputReader.java
+++ b/media/sse/src/main/java/org/glassfish/jersey/media/sse/EventInputReader.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -31,7 +31,6 @@
import org.glassfish.jersey.internal.PropertiesDelegate;
import org.glassfish.jersey.message.MessageBodyWorkers;
-import org.glassfish.jersey.message.MessageUtils;
import org.glassfish.jersey.message.internal.ReaderInterceptorExecutor;
/**
@@ -41,10 +40,14 @@
*/
class EventInputReader implements MessageBodyReader<EventInput> {
+ private final Provider<MessageBodyWorkers> messageBodyWorkers;
+ private final Provider<PropertiesDelegate> propertiesDelegateProvider;
+
@Inject
- private Provider<MessageBodyWorkers> messageBodyWorkers;
- @Inject
- private Provider<PropertiesDelegate> propertiesDelegateProvider;
+ EventInputReader(Provider<MessageBodyWorkers> messageBodyWorkers, Provider<PropertiesDelegate> propertiesDelegateProvider) {
+ this.messageBodyWorkers = messageBodyWorkers;
+ this.propertiesDelegateProvider = propertiesDelegateProvider;
+ }
@Override
public boolean isReadable(Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType) {
diff --git a/media/sse/src/main/java/org/glassfish/jersey/media/sse/InboundEventReader.java b/media/sse/src/main/java/org/glassfish/jersey/media/sse/InboundEventReader.java
index 3ac2ccb..6d48a60 100644
--- a/media/sse/src/main/java/org/glassfish/jersey/media/sse/InboundEventReader.java
+++ b/media/sse/src/main/java/org/glassfish/jersey/media/sse/InboundEventReader.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -49,8 +49,12 @@
private static final Logger LOGGER = Logger.getLogger(InboundEventReader.class.getName());
private static final byte[] EOL_DATA = new byte[] {'\n'};
+ private final Provider<MessageBodyWorkers> messageBodyWorkers;
+
@Inject
- private Provider<MessageBodyWorkers> messageBodyWorkers;
+ InboundEventReader(Provider<MessageBodyWorkers> messageBodyWorkers) {
+ this.messageBodyWorkers = messageBodyWorkers;
+ }
private enum State {
SKIPPING_PREPENDED_EMPTY_EVENTS,
diff --git a/media/sse/src/main/java/org/glassfish/jersey/media/sse/OutboundEventWriter.java b/media/sse/src/main/java/org/glassfish/jersey/media/sse/OutboundEventWriter.java
index 2dd6b2e..ea2d48f 100644
--- a/media/sse/src/main/java/org/glassfish/jersey/media/sse/OutboundEventWriter.java
+++ b/media/sse/src/main/java/org/glassfish/jersey/media/sse/OutboundEventWriter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -52,8 +52,12 @@
private static final byte[] DATA_LEAD = "data: ".getBytes(UTF8);
private static final byte[] EOL = {'\n'};
+ private final Provider<MessageBodyWorkers> workersProvider;
+
@Inject
- private Provider<MessageBodyWorkers> workersProvider;
+ public OutboundEventWriter(Provider<MessageBodyWorkers> workersProvider) {
+ this.workersProvider = workersProvider;
+ }
@Override
public boolean isWriteable(final Class<?> type, final Type genericType, final Annotation[] annotations,
diff --git a/security/oauth1-client/src/main/java/org/glassfish/jersey/client/oauth1/OAuth1ClientFilter.java b/security/oauth1-client/src/main/java/org/glassfish/jersey/client/oauth1/OAuth1ClientFilter.java
index 85a9108..bd33378 100644
--- a/security/oauth1-client/src/main/java/org/glassfish/jersey/client/oauth1/OAuth1ClientFilter.java
+++ b/security/oauth1-client/src/main/java/org/glassfish/jersey/client/oauth1/OAuth1ClientFilter.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -48,11 +48,14 @@
@Priority(Priorities.AUTHENTICATION)
class OAuth1ClientFilter implements ClientRequestFilter {
- @Inject
private Provider<OAuth1Signature> oAuthSignature;
+ private Provider<MessageBodyWorkers> messageBodyWorkers;
@Inject
- private Provider<MessageBodyWorkers> messageBodyWorkers;
+ public OAuth1ClientFilter(Provider<OAuth1Signature> oAuthSignature, Provider<MessageBodyWorkers> messageBodyWorkers) {
+ this.oAuthSignature = oAuthSignature;
+ this.messageBodyWorkers = messageBodyWorkers;
+ }
@Override
public void filter(ClientRequestContext request) throws IOException {
diff --git a/security/oauth2-client/src/main/java/org/glassfish/jersey/client/oauth2/AuthCodeGrantImpl.java b/security/oauth2-client/src/main/java/org/glassfish/jersey/client/oauth2/AuthCodeGrantImpl.java
index f9979d3..9f557d1 100644
--- a/security/oauth2-client/src/main/java/org/glassfish/jersey/client/oauth2/AuthCodeGrantImpl.java
+++ b/security/oauth2-client/src/main/java/org/glassfish/jersey/client/oauth2/AuthCodeGrantImpl.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2019 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -354,11 +354,15 @@
static class DefaultTokenMessageBodyReader implements MessageBodyReader<TokenResult> {
// Provider here prevents circular dependency error from HK2 (workers inject providers and this provider inject workers)
- @Inject
- private Provider<MessageBodyWorkers> workers;
+ private final Provider<MessageBodyWorkers> workers;
+ private final Provider<PropertiesDelegate> propertiesDelegateProvider;
@Inject
- private Provider<PropertiesDelegate> propertiesDelegateProvider;
+ public DefaultTokenMessageBodyReader(Provider<MessageBodyWorkers> workers,
+ Provider<PropertiesDelegate> propertiesDelegateProvider) {
+ this.propertiesDelegateProvider = propertiesDelegateProvider;
+ this.workers = workers;
+ }
private static Iterable<ReaderInterceptor> EMPTY_INTERCEPTORS = new ArrayList<>();
diff --git a/tests/e2e-client/pom.xml b/tests/e2e-client/pom.xml
index e184c03..28243e0 100644
--- a/tests/e2e-client/pom.xml
+++ b/tests/e2e-client/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2017, 2023 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
@@ -46,6 +46,25 @@
<sun.net.http.allowRestrictedHeaders>true</sun.net.http.allowRestrictedHeaders>
</systemPropertyVariables>
</configuration>
+ <executions>
+ <execution>
+ <id>WithHK2</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <excludes>
+ <exclude>**/NonInjectionManagerTest.java</exclude>
+ </excludes>
+ <systemPropertyVariables>
+ <jersey.injectionmanager.hk2>true</jersey.injectionmanager.hk2>
+ </systemPropertyVariables>
+ <classpathDependencyExcludes>
+ <classpathDependencyExclude>org.glassfish.jersey.incubator:jersey-injectless-client</classpathDependencyExclude>
+ </classpathDependencyExcludes>
+ </configuration>
+ </execution>
+ </executions>
</plugin>
</plugins>
</build>
@@ -177,6 +196,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.incubator</groupId>
+ <artifactId>jersey-injectless-client</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework</groupId>
diff --git a/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/HttpHeadersInjectionTest.java b/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/HttpHeadersInjectionTest.java
index 65b86f0..004d4d0 100644
--- a/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/HttpHeadersInjectionTest.java
+++ b/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/HttpHeadersInjectionTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -20,6 +20,7 @@
import org.glassfish.jersey.test.JerseyTest;
import org.junit.jupiter.api.Test;
+import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@@ -43,7 +44,6 @@
import javax.ws.rs.ext.WriterInterceptor;
import javax.ws.rs.ext.WriterInterceptorContext;
import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -74,10 +74,13 @@
}
public static class HttpHeadersFilter implements ClientRequestFilter {
-
- @Context
HttpHeaders headers;
+ @Inject
+ public HttpHeadersFilter(HttpHeaders headers) {
+ this.headers = headers;
+ }
+
@Override
public void filter(ClientRequestContext requestContext) throws IOException {
requestContext.abortWith(Response.ok(headers.getHeaderString(HEADER_NAME)).build());
@@ -85,10 +88,13 @@
}
public static class HttpHeadersResponseFilter implements ClientResponseFilter {
-
- @Context
HttpHeaders headers;
+ @Inject
+ public HttpHeadersResponseFilter(HttpHeaders headers) {
+ this.headers = headers;
+ }
+
private static int headerValue = 0;
public int getHeaderValue() {
@@ -103,9 +109,13 @@
@Produces(MediaType.TEXT_PLAIN)
public static class StringWriter implements MessageBodyWriter<String> {
- @Context
HttpHeaders headers;
+ @Inject
+ public StringWriter(HttpHeaders headers) {
+ this.headers = headers;
+ }
+
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return true;
@@ -122,10 +132,13 @@
@Consumes({MediaType.TEXT_PLAIN})
public static class StringReader implements MessageBodyReader<String> {
-
- @Context
HttpHeaders headers;
+ @Inject
+ public StringReader(HttpHeaders headers) {
+ this.headers = headers;
+ }
+
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return true;
@@ -140,10 +153,13 @@
}
public static class HttpHeadersReaderInterceptor implements ReaderInterceptor {
-
- @Context
HttpHeaders headers;
+ @Inject
+ public HttpHeadersReaderInterceptor(HttpHeaders headers) {
+ this.headers = headers;
+ }
+
@Override
public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
context.getInputStream().close();
@@ -153,10 +169,13 @@
}
public static class HttpHeadersWriterInterceptor implements WriterInterceptor {
-
- @Context
HttpHeaders headers;
+ @Inject
+ public HttpHeadersWriterInterceptor(HttpHeaders headers) {
+ this.headers = headers;
+ }
+
@Override
public void aroundWriteTo(WriterInterceptorContext context) throws IOException, WebApplicationException {
OutputStreamWriter osw = new OutputStreamWriter(context.getOutputStream());
@@ -177,7 +196,7 @@
@Test
public void testHttpHeadersInjectionInResponseFilter() {
final String value = "1";
- final HttpHeadersResponseFilter filter = new HttpHeadersResponseFilter();
+ final HttpHeadersResponseFilter filter = new HttpHeadersResponseFilter(null);
final String response = target().register(HttpHeadersResponseFilter.class).request().header(HEADER_NAME, value)
.buildPost(Entity.entity(value, MediaType.TEXT_PLAIN_TYPE)).invoke(String.class);
assertThat(response, is(value));
diff --git a/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/InjectedClientBodyWorker.java b/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/InjectedClientBodyWorker.java
index 1414887..3367b1f 100644
--- a/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/InjectedClientBodyWorker.java
+++ b/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/InjectedClientBodyWorker.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -22,6 +22,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@@ -30,7 +31,6 @@
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Configuration;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.ContextResolver;
@@ -73,10 +73,13 @@
@Provider
@Produces(ProviderType)
public static class ProvidersInjectedWriter implements MessageBodyWriter<String> {
-
- @Context
Providers providers;
+ @Inject
+ public ProvidersInjectedWriter(Providers providers) {
+ this.providers = providers;
+ }
+
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return type == String.class;
@@ -105,9 +108,13 @@
@Consumes(ProviderType)
public static class ProvidersInjectedReader implements MessageBodyReader<String> {
- @Context
Providers providers;
+ @Inject
+ ProvidersInjectedReader(Providers providers) {
+ this.providers = providers;
+ }
+
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return type == String.class;
@@ -132,9 +139,13 @@
@Produces(ConfigurationTYPE)
public static class ConfigurationInjectedWriter implements MessageBodyWriter<String> {
- @Context
Configuration configuration;
+ @Inject
+ public ConfigurationInjectedWriter(Configuration configuration) {
+ this.configuration = configuration;
+ }
+
@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return type == String.class;
@@ -158,10 +169,13 @@
@Provider
@Consumes(ConfigurationTYPE)
public static class ConfigurationInjectedReader implements MessageBodyReader<String> {
-
- @Context
Configuration configuration;
+ @Inject
+ public ConfigurationInjectedReader(Configuration configuration) {
+ this.configuration = configuration;
+ }
+
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return type == String.class;
diff --git a/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/NonInjectionManagerTest.java b/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/NonInjectionManagerTest.java
new file mode 100644
index 0000000..de940b7
--- /dev/null
+++ b/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/NonInjectionManagerTest.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package org.glassfish.jersey.tests.e2e.client;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.ClientRequestFilter;
+import javax.ws.rs.core.Response;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import org.glassfish.jersey.inject.injectless.NonInjectionManagerFactory;
+
+public class NonInjectionManagerTest {
+ @Test
+ public void testNonInjectionManagerIsUsed() {
+ String value = System.getProperty("jersey.injectionmanager.hk2");
+ if ("true".equals(value)) {
+ return;
+ }
+
+ Records records = new Records();
+ Logger logger = Logger.getLogger(new NonInjectionManagerFactory().create(null).getClass().getName());
+ Level oldLevel = logger.getLevel();
+ logger.setLevel(Level.FINEST);
+ logger.addHandler(records);
+
+ ClientBuilder.newClient().register((ClientRequestFilter) requestContext -> {
+ requestContext.abortWith(Response.ok().build());
+ }).target("http://localhost:9998/nevermind").request().get();
+
+ logger.removeHandler(records);
+ logger.setLevel(oldLevel);
+
+ LogRecord warning = records.records.get(0);
+ Assertions.assertTrue(warning.getMessage().contains("injection-less"));
+ }
+
+ private static class Records extends Handler {
+ private List<LogRecord> records = new LinkedList<>();
+ @Override
+ public void publish(LogRecord record) {
+ records.add(record);
+ }
+
+ @Override
+ public void flush() {
+ }
+
+ @Override
+ public void close() throws SecurityException {
+ }
+ }
+}
diff --git a/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/RequestScopedReadEntityTest.java b/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/RequestScopedReadEntityTest.java
index f8bd405..72855f0 100644
--- a/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/RequestScopedReadEntityTest.java
+++ b/tests/e2e-client/src/test/java/org/glassfish/jersey/tests/e2e/client/RequestScopedReadEntityTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -71,9 +71,12 @@
@Produces("text/plain")
public static class ScopedMessageEntityProvider extends AbstractMessageReaderWriterProvider<Message> {
+ private final Provider<ClientRequest> clientRequestProvider;
@Inject
- private Provider<ClientRequest> clientRequestProvider;
+ public ScopedMessageEntityProvider(Provider<ClientRequest> clientRequestProvider) {
+ this.clientRequestProvider = clientRequestProvider;
+ }
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
diff --git a/tests/e2e-entity/pom.xml b/tests/e2e-entity/pom.xml
index 8800b0f..56489c2 100644
--- a/tests/e2e-entity/pom.xml
+++ b/tests/e2e-entity/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2017, 2023 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
@@ -43,6 +43,19 @@
<enableAssertions>false</enableAssertions>
<skipTests>${skip.e2e}</skipTests>
</configuration>
+ <executions>
+ <execution>
+ <id>WithHK2</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <classpathDependencyExcludes>
+ <classpathDependencyExclude>org.glassfish.jersey.incubator:jersey-injectless-client</classpathDependencyExclude>
+ </classpathDependencyExcludes>
+ </configuration>
+ </execution>
+ </executions>
</plugin>
</plugins>
</build>
@@ -181,6 +194,12 @@
<version>${junit-platform-suite.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.incubator</groupId>
+ <artifactId>jersey-injectless-client</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.hamcrest</groupId>
diff --git a/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/entity/filtering/FilteringMessageBodyProvider.java b/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/entity/filtering/FilteringMessageBodyProvider.java
index dcb6ba5..09e739b 100644
--- a/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/entity/filtering/FilteringMessageBodyProvider.java
+++ b/tests/e2e-entity/src/test/java/org/glassfish/jersey/tests/e2e/entity/filtering/FilteringMessageBodyProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -52,8 +52,12 @@
private static final Logger LOGGER = Logger.getLogger(FilteringMessageBodyProvider.class.getName());
+ private final javax.inject.Provider<ObjectProvider<ObjectGraph>> provider;
+
@Inject
- private javax.inject.Provider<ObjectProvider<ObjectGraph>> provider;
+ public FilteringMessageBodyProvider(javax.inject.Provider<ObjectProvider<ObjectGraph>> provider) {
+ this.provider = provider;
+ }
@Override
public boolean isReadable(final Class<?> type, final Type genericType, final Annotation[] annotations,
diff --git a/tests/e2e-server/pom.xml b/tests/e2e-server/pom.xml
index f753626..e17d856 100644
--- a/tests/e2e-server/pom.xml
+++ b/tests/e2e-server/pom.xml
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright (c) 2017, 2022 Oracle and/or its affiliates. All rights reserved.
+ Copyright (c) 2017, 2023 Oracle and/or its affiliates. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v. 2.0, which is available at
@@ -43,6 +43,19 @@
<enableAssertions>false</enableAssertions>
<skipTests>${skip.e2e}</skipTests>
</configuration>
+ <executions>
+ <execution>
+ <id>WithHK2</id>
+ <goals>
+ <goal>test</goal>
+ </goals>
+ <configuration>
+ <classpathDependencyExcludes>
+ <classpathDependencyExclude>org.glassfish.jersey.incubator:jersey-injectless-client</classpathDependencyExclude>
+ </classpathDependencyExcludes>
+ </configuration>
+ </execution>
+ </executions>
</plugin>
</plugins>
</build>
@@ -174,6 +187,12 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.incubator</groupId>
+ <artifactId>jersey-injectless-client</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework</groupId>
diff --git a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/ManagedClientExecutorTest.java b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/ManagedClientExecutorTest.java
index c4581ae..42bcb9b 100644
--- a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/ManagedClientExecutorTest.java
+++ b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/ManagedClientExecutorTest.java
@@ -219,11 +219,15 @@
*/
public static class SchedulerThreadNameReader implements MessageBodyReader<SchedulerThreadName> {
- @Inject
- ScheduledExecutorServiceProvider injectedProvider;
+ private final ScheduledExecutorServiceProvider injectedProvider;
+ private final ScheduledExecutorService injectedService;
@Inject
- ScheduledExecutorService injectedService;
+ public SchedulerThreadNameReader(ScheduledExecutorService injectedService,
+ ScheduledExecutorServiceProvider injectedProvider) {
+ this.injectedProvider = injectedProvider;
+ this.injectedService = injectedService;
+ }
@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
diff --git a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/validation/validateonexecution/ValidateOnExecutionOverrideTest.java b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/validation/validateonexecution/ValidateOnExecutionOverrideTest.java
index 4a50e47..c062293 100644
--- a/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/validation/validateonexecution/ValidateOnExecutionOverrideTest.java
+++ b/tests/e2e-server/src/test/java/org/glassfish/jersey/tests/e2e/server/validation/validateonexecution/ValidateOnExecutionOverrideTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -19,6 +19,7 @@
import java.util.List;
import java.util.logging.Level;
import java.util.logging.LogRecord;
+import java.util.stream.Collectors;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
@@ -101,8 +102,13 @@
private void _test(final String path) throws Exception {
assertThat(target(path).request().get().getStatus(), equalTo(500));
- final List<LogRecord> loggedRecords = getLoggedRecords();
+ final List<LogRecord> loggedRecords = getLoggedRecords()
+ .stream()
+ .filter(log -> log.getSourceClassName().equals(LOGGER_NAME)) // Skip warnings from outside of Validation
+ .collect(Collectors.toList());
assertThat(loggedRecords.size(), equalTo(1));
assertThat(loggedRecords.get(0).getThrown(), instanceOf(ValidationException.class));
}
+
+ private static final String LOGGER_NAME = "org.glassfish.jersey.server.validation.internal.ValidationExceptionMapper";
}
diff --git a/tests/e2e/src/test/java/org/glassfish/jersey/tests/api/MessageBodyWriterTest.java b/tests/e2e/src/test/java/org/glassfish/jersey/tests/api/MessageBodyWriterTest.java
index ad14824..2726ec9 100644
--- a/tests/e2e/src/test/java/org/glassfish/jersey/tests/api/MessageBodyWriterTest.java
+++ b/tests/e2e/src/test/java/org/glassfish/jersey/tests/api/MessageBodyWriterTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -21,6 +21,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
@@ -32,7 +33,6 @@
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.Configuration;
-import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
@@ -75,9 +75,13 @@
@Provider
@Produces("text/plain")
public static class OverridingStringProvider implements MessageBodyWriter<String> {
+ private final Configuration config;
- @Context
- private Configuration config;
+ @Inject
+ public OverridingStringProvider(Configuration config) {
+ this.config = config;
+ }
+
@Override
public boolean isWriteable(
@@ -120,10 +124,13 @@
@Provider
@Produces("text/html")
public static class HtmlStringProvider implements MessageBodyWriter<String> {
-
- @Context
private Configuration config;
+ @Inject
+ public HtmlStringProvider(Configuration config) {
+ this.config = config;
+ }
+
@Override
public boolean isWriteable(
final Class<?> type,
diff --git a/tests/e2e/src/test/java/org/glassfish/jersey/tests/e2e/common/LoggingFeatureTest.java b/tests/e2e/src/test/java/org/glassfish/jersey/tests/e2e/common/LoggingFeatureTest.java
index 5f2020e..8b9145c 100644
--- a/tests/e2e/src/test/java/org/glassfish/jersey/tests/e2e/common/LoggingFeatureTest.java
+++ b/tests/e2e/src/test/java/org/glassfish/jersey/tests/e2e/common/LoggingFeatureTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2022 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
@@ -707,29 +708,36 @@
// --- client request log entry
// client added header before request has sent (and logged)
- assertThat(getLoggedRecords().get(0).getMessage(),
+ Iterator<LogRecord> it = getLoggedRecords().iterator();
+ LogRecord logRecord = it.next();
+ while (logRecord.getLevel() == Level.WARNING) { // Skip any warning at the beginning
+ logRecord = it.next();
+ }
+ assertThat(logRecord.getMessage(),
containsString("1 > custom_header: client/request\n"));
// --- container request log entry
// container receives header from client request
- assertThat(getLoggedRecords().get(1).getMessage(),
+ logRecord = it.next();
+ assertThat(logRecord.getMessage(),
containsString("1 > custom_header: client/request\n"));
// container has added its own header after logging filter logged message
- assertThat(getLoggedRecords().get(1).getMessage(),
+ assertThat(logRecord.getMessage(),
not(containsString("1 > custom_header: container/request\n")));
// --- container response log entry
// container added header to the response and it was logged
- assertThat(getLoggedRecords().get(2).getMessage(),
+ assertThat(it.next().getMessage(),
containsString("1 < custom_header: container/response\n"));
// --- client response log entry
// client received header
- assertThat(getLoggedRecords().get(3).getMessage(),
+ logRecord = it.next();
+ assertThat(logRecord.getMessage(),
containsString("1 < custom_header: container/response\n"));
- assertThat(getLoggedRecords().get(3).getMessage(),
+ assertThat(logRecord.getMessage(),
not(containsString("1 < custom_header: client/response\n")));
}