Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 3rd party instantiators working with @Context only #5284

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.ws.rs.ConstrainedTo;
import javax.ws.rs.RuntimeType;
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.ext.MessageBodyReader;
Expand All @@ -47,8 +48,8 @@ class ChunkedInputReader implements MessageBodyReader<ChunkedInput> {
private final Provider<PropertiesDelegate> propertiesDelegateProvider;

@Inject
public ChunkedInputReader(Provider<MessageBodyWorkers> messageBodyWorkers,
Provider<PropertiesDelegate> propertiesDelegateProvider) {
public ChunkedInputReader(@Context Provider<MessageBodyWorkers> messageBodyWorkers,
@Context Provider<PropertiesDelegate> propertiesDelegateProvider) {
this.messageBodyWorkers = messageBodyWorkers;
this.propertiesDelegateProvider = propertiesDelegateProvider;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.HttpHeaders;

import javax.inject.Inject;
Expand Down Expand Up @@ -54,7 +55,7 @@ public final class EncodingFilter implements ClientRequestFilter {
private volatile List<Object> supportedEncodings = null;

@Inject
public EncodingFilter(InjectionManager injectionManager) {
public EncodingFilter(@Context InjectionManager injectionManager) {
this.injectionManager = injectionManager;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand Down Expand Up @@ -266,7 +267,7 @@ private static class InjectedPreInvocationInterceptor implements PreInvocationIn
private final Configuration configuration;

@Inject
public InjectedPreInvocationInterceptor(Configuration configuration) {
public InjectedPreInvocationInterceptor(@Context Configuration configuration) {
this.configuration = configuration;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.ContextResolver;
import javax.ws.rs.ext.ExceptionMapper;
Expand Down Expand Up @@ -67,9 +68,9 @@ public void init(InjectionManager injectionManager, BootstrapBag bootstrapBag) {
private final Provider<ExceptionMappers> mappers;

@Inject
public JaxrsProviders(Provider<MessageBodyWorkers> workers,
Provider<ContextResolvers> resolvers,
Provider<ExceptionMappers> mappers) {
public JaxrsProviders(@Context Provider<MessageBodyWorkers> workers,
@Context Provider<ContextResolvers> resolvers,
@Context Provider<ExceptionMappers> mappers) {
this.workers = workers;
this.resolvers = resolvers;
this.mappers = mappers;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
* Copyright (c) 2018 Payara Foundation and/or its affiliates.
*
* This program and the accompanying materials are made available under the
Expand All @@ -21,7 +21,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.security.AccessController;
import java.text.ParseException;
Expand All @@ -36,6 +35,7 @@
import javax.inject.Singleton;
import javax.ws.rs.ProcessingException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.ParamConverter;
import javax.ws.rs.ext.ParamConverterProvider;

Expand Down Expand Up @@ -409,7 +409,7 @@ public static class AggregatedProvider implements ParamConverterProvider {
* Create new aggregated {@link ParamConverterProvider param converter provider}.
*/
@Inject
public AggregatedProvider(InjectionManager manager) {
public AggregatedProvider(@Context InjectionManager manager) {
this.providers = new ParamConverterProvider[] {
// ordering is important (e.g. Date provider must be executed before String Constructor
// as Date has a deprecated String constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -96,7 +97,7 @@ public static final class SaxSourceReader implements MessageBodyReader<SAXSource
private final Provider<SAXParserFactory> spf;

@Inject
public SaxSourceReader(Provider<SAXParserFactory> spf) {
public SaxSourceReader(@Context Provider<SAXParserFactory> spf) {
this.spf = spf;
}

Expand Down Expand Up @@ -137,7 +138,7 @@ public static final class DomSourceReader implements MessageBodyReader<DOMSource
private final Provider<DocumentBuilderFactory> dbf;

@Inject
public DomSourceReader(Provider<DocumentBuilderFactory> dbf) {
public DomSourceReader(@Context Provider<DocumentBuilderFactory> dbf) {
this.dbf = dbf;
}

Expand Down Expand Up @@ -179,8 +180,8 @@ public static final class SourceWriter implements MessageBodyWriter<Source> {
private final Provider<TransformerFactory> transformerFactory;

@Inject
public SourceWriter(Provider<SAXParserFactory> spf,
Provider<TransformerFactory> tf) {
public SourceWriter(@Context Provider<SAXParserFactory> spf,
@Context Provider<TransformerFactory> tf) {
this.saxParserFactory = spf;
this.transformerFactory = tf;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.core.Context;

import org.glassfish.jersey.internal.inject.InjectionManager;
import org.glassfish.jersey.internal.inject.Providers;
Expand Down Expand Up @@ -59,7 +60,7 @@ final class EntityInspectorImpl implements EntityInspector {
* @param injectionManager injection manager to be injected.
*/
@Inject
public EntityInspectorImpl(final InjectionManager injectionManager, EntityGraphProvider graphProvider) {
public EntityInspectorImpl(@Context InjectionManager injectionManager, @Context EntityGraphProvider graphProvider) {
Spliterator<EntityProcessor> entities =
Providers.getAllProviders(injectionManager, EntityProcessor.class, new RankedComparator<>()).spliterator();
this.entityProcessors = StreamSupport.stream(entities, false).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.glassfish.jersey.message.filtering.spi.ScopeProvider;

import javax.inject.Inject;
import javax.ws.rs.core.Context;

/**
* {@link org.glassfish.jersey.message.filtering.spi.ObjectProvider Object provider} and
Expand All @@ -34,9 +35,9 @@
final class ObjectGraphProvider extends AbstractObjectProvider<ObjectGraph> {

@Inject
public ObjectGraphProvider(ScopeProvider scopeProvider,
EntityInspector entityInspector,
EntityGraphProvider graphProvider) {
public ObjectGraphProvider(@Context ScopeProvider scopeProvider,
@Context EntityInspector entityInspector,
@Context EntityGraphProvider graphProvider) {
super(scopeProvider, entityInspector, graphProvider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Set;

import javax.inject.Inject;
import javax.ws.rs.core.Context;

import org.glassfish.jersey.internal.guava.Cache;
import org.glassfish.jersey.internal.guava.CacheBuilder;
Expand All @@ -50,9 +51,9 @@ public abstract class AbstractObjectProvider<T> implements ObjectProvider<T>, Ob
private EntityInspector entityInspector;
private EntityGraphProvider graphProvider;

public AbstractObjectProvider(ScopeProvider scopeProvider,
EntityInspector entityInspector,
EntityGraphProvider graphProvider) {
public AbstractObjectProvider(@Context ScopeProvider scopeProvider,
@Context EntityInspector entityInspector,
@Context EntityGraphProvider graphProvider) {
this.scopeProvider = scopeProvider;
this.entityInspector = entityInspector;
this.graphProvider = graphProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand Down Expand Up @@ -73,7 +74,7 @@ public MetaInf post(final MetaInf entity) {
public static class MessageProvider implements MessageBodyReader<MetaInf>, MessageBodyWriter<MetaInf> {

@Inject
MessageProvider(Configuration configuration) {
MessageProvider(@Context Configuration configuration) {
this.config = configuration;
}
private Configuration config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javax.ws.rs.Consumes;
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.ext.ContextResolver;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class KryoMessageBodyProvider implements MessageBodyWriter<Object>, Messa
private final Optional<KryoPool> kryoPool;

@Inject
public KryoMessageBodyProvider(Providers providers) {
public KryoMessageBodyProvider(@Context Providers providers) {
final MediaType mediaType = new MediaType("application", "x-kryo");
contextResolver = providers.getContextResolver(Kryo.class, mediaType);
kryoPool = getKryoPool();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.ws.rs.core.Configuration;

import javax.inject.Inject;
import javax.ws.rs.core.Context;
import javax.xml.parsers.DocumentBuilderFactory;

/**
Expand All @@ -39,7 +40,8 @@ public class DocumentBuilderFactoryInjectionProvider extends AbstractXmlFactory<
*/
// TODO This provider should be registered and configured via a feature.
@Inject
public DocumentBuilderFactoryInjectionProvider(final InjectionManager injectionManager, final Configuration config) {
public DocumentBuilderFactoryInjectionProvider(@Context final InjectionManager injectionManager,
@Context final Configuration config) {
super(config);
this.injectionManager = injectionManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import javax.inject.Inject;
import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.Context;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -49,7 +50,8 @@ public class SaxParserFactoryInjectionProvider extends AbstractXmlFactory<SAXPar
*/
// TODO This provider should be registered and configured via a feature.
@Inject
public SaxParserFactoryInjectionProvider(final InjectionManager injectionManager, final Configuration config) {
public SaxParserFactoryInjectionProvider(@Context final InjectionManager injectionManager,
@Context final Configuration config) {
super(config);
this.injectionManager = injectionManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.ws.rs.core.Configuration;

import javax.inject.Inject;
import javax.ws.rs.core.Context;
import javax.xml.XMLConstants;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
Expand All @@ -45,7 +46,8 @@ public class TransformerFactoryInjectionProvider extends AbstractXmlFactory<Tran
*/
// TODO This provider should be registered and configured via a feature.
@Inject
public TransformerFactoryInjectionProvider(final InjectionManager injectionManager, final Configuration config) {
public TransformerFactoryInjectionProvider(@Context final InjectionManager injectionManager,
@Context final Configuration config) {
super(config);
this.injectionManager = injectionManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Providers;

Expand Down Expand Up @@ -73,7 +74,7 @@ public abstract class XmlCollectionJaxbProvider extends AbstractCollectionJaxbPr
public static final class App extends XmlCollectionJaxbProvider {

@Inject
public App(Provider<XMLInputFactory> xif, Providers ps, Configuration config) {
public App(@Context Provider<XMLInputFactory> xif, @Context Providers ps, @Context Configuration config) {
super(xif, ps, MediaType.APPLICATION_XML_TYPE, config);
}
}
Expand All @@ -88,7 +89,7 @@ public App(Provider<XMLInputFactory> xif, Providers ps, Configuration config) {
public static final class Text extends XmlCollectionJaxbProvider {

@Inject
public Text(Provider<XMLInputFactory> xif, Providers ps, Configuration config) {
public Text(@Context Provider<XMLInputFactory> xif, @Context Providers ps, @Context Configuration config) {
super(xif, ps, MediaType.TEXT_XML_TYPE, config);
}
}
Expand All @@ -103,7 +104,7 @@ public Text(Provider<XMLInputFactory> xif, Providers ps, Configuration config) {
public static final class General extends XmlCollectionJaxbProvider {

@Inject
public General(Provider<XMLInputFactory> xif, Providers ps, Configuration config) {
public General(@Context Provider<XMLInputFactory> xif, @Context Providers ps, @Context Configuration config) {
super(xif, ps, config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.ws.rs.core.Configuration;

import javax.inject.Inject;
import javax.ws.rs.core.Context;
import javax.xml.stream.XMLInputFactory;

/**
Expand All @@ -38,7 +39,8 @@ public class XmlInputFactoryInjectionProvider extends AbstractXmlFactory<XMLInpu
*/
// TODO This provider should be registered and configured via a feature.
@Inject
public XmlInputFactoryInjectionProvider(final InjectionManager injectionManager, final Configuration config) {
public XmlInputFactoryInjectionProvider(@Context final InjectionManager injectionManager,
@Context final Configuration config) {
super(config);
this.injectionManager = injectionManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Configuration;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Providers;

Expand Down Expand Up @@ -67,7 +68,7 @@ public XmlJaxbElementProvider(Provider<SAXParserFactory> spf, Providers ps, Medi
public static final class App extends XmlJaxbElementProvider {

@Inject
public App(Provider<SAXParserFactory> spf, Providers ps, Configuration config) {
public App(@Context Provider<SAXParserFactory> spf, @Context Providers ps, @Context Configuration config) {
super(spf, ps, MediaType.APPLICATION_XML_TYPE, config);
}
}
Expand All @@ -82,7 +83,7 @@ public App(Provider<SAXParserFactory> spf, Providers ps, Configuration config) {
public static final class Text extends XmlJaxbElementProvider {

@Inject
public Text(Provider<SAXParserFactory> spf, Providers ps, Configuration config) {
public Text(@Context Provider<SAXParserFactory> spf, @Context Providers ps, @Context Configuration config) {
super(spf, ps, MediaType.TEXT_XML_TYPE, config);
}
}
Expand All @@ -97,7 +98,7 @@ public Text(Provider<SAXParserFactory> spf, Providers ps, Configuration config)
public static final class General extends XmlJaxbElementProvider {

@Inject
public General(Provider<SAXParserFactory> spf, Providers ps, Configuration config) {
public General(@Context Provider<SAXParserFactory> spf, @Context Providers ps, @Context Configuration config) {
super(spf, ps, config);
}

Expand Down
Loading