Search in sources :

Example 1 with Provider

use of javax.inject.Provider in project jersey by jersey.

the class JaxbStringReaderProviderTest method stringReaderDoesNotReadExternalDtds.

@Test
public void stringReaderDoesNotReadExternalDtds() {
    Provider<SAXParserFactory> saxParserFactoryProvider = new Provider<SAXParserFactory>() {

        final SaxParserFactoryInjectionProvider spf = new SaxParserFactoryInjectionProvider(new CommonConfig(RuntimeType.SERVER, ComponentBag.INCLUDE_ALL));

        @Override
        public SAXParserFactory get() {
            return spf.get();
        }
    };
    JaxbStringReaderProvider.RootElementProvider provider = new JaxbStringReaderProvider.RootElementProvider(saxParserFactoryProvider, new Providers() {

        @Override
        public <T> MessageBodyReader<T> getMessageBodyReader(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
            return null;
        }

        @Override
        public <T> MessageBodyWriter<T> getMessageBodyWriter(Class<T> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
            return null;
        }

        @Override
        public <T extends Throwable> ExceptionMapper<T> getExceptionMapper(Class<T> type) {
            return null;
        }

        @Override
        public <T> ContextResolver<T> getContextResolver(Class<T> contextType, MediaType mediaType) {
            return null;
        }
    });
    String content = "<!DOCTYPE x SYSTEM 'file:///no-such-file'> <rootObject/>";
    provider.getConverter(RootObject.class, null, null).fromString(content);
}
Also used : CommonConfig(org.glassfish.jersey.model.internal.CommonConfig) Providers(javax.ws.rs.ext.Providers) Annotation(java.lang.annotation.Annotation) Provider(javax.inject.Provider) MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) RuntimeType(javax.ws.rs.RuntimeType) MediaType(javax.ws.rs.core.MediaType) Type(java.lang.reflect.Type) ExceptionMapper(javax.ws.rs.ext.ExceptionMapper) MediaType(javax.ws.rs.core.MediaType) ContextResolver(javax.ws.rs.ext.ContextResolver) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) SAXParserFactory(javax.xml.parsers.SAXParserFactory) Test(org.junit.Test)

Example 2 with Provider

use of javax.inject.Provider in project jersey by jersey.

the class ParameterInjectionBinder method configure.

@Override
public void configure() {
    // Param converter providers
    // TODO: Replace by non-di version
    bind(new ParamConverters.AggregatedProvider()).to(ParamConverterProvider.class);
    Provider<ContainerRequest> requestProvider = Injections.getProvider(injectionManager, ContainerRequest.class);
    Provider<AsyncContext> asyncContextProvider = Injections.getProvider(injectionManager, AsyncContext.class);
    Function<Class<? extends Configuration>, Configuration> clientConfigProvider = clientConfigClass -> Injections.getOrCreate(injectionManager, clientConfigClass);
    // Param Converters must be initialized Lazy and created at the time of the call on extractor
    LazyValue<ParamConverterFactory> lazyParamConverterFactory = Values.lazy((Value<ParamConverterFactory>) () -> new ParamConverterFactory(Providers.getProviders(injectionManager, ParamConverterProvider.class), Providers.getCustomProviders(injectionManager, ParamConverterProvider.class)));
    LazyValue<Configuration> lazyConfiguration = Values.lazy((Value<Configuration>) () -> injectionManager.getInstance(Configuration.class));
    MultivaluedParameterExtractorFactory paramExtractor = new MultivaluedParameterExtractorFactory(lazyParamConverterFactory);
    bind(paramExtractor).to(MultivaluedParameterExtractorProvider.class);
    // Parameter injection value providers
    AsyncResponseValueSupplierProvider asyncSupplier = new AsyncResponseValueSupplierProvider(asyncContextProvider);
    bindValueSupplier(asyncSupplier);
    CookieParamValueSupplierProvider cookieSupplier = new CookieParamValueSupplierProvider(paramExtractor, requestProvider);
    bindValueSupplier(cookieSupplier);
    EntityParamValueSupplierProvider entitySupplier = new EntityParamValueSupplierProvider(paramExtractor, requestProvider);
    bindValueSupplier(entitySupplier);
    FormParamValueSupplierProvider formSupplier = new FormParamValueSupplierProvider(paramExtractor, requestProvider);
    bindValueSupplier(formSupplier);
    HeaderParamValueSupplierProvider headerSupplier = new HeaderParamValueSupplierProvider(paramExtractor, requestProvider);
    bindValueSupplier(headerSupplier);
    MatrixParamValueSupplierProvider matrixSupplier = new MatrixParamValueSupplierProvider(paramExtractor, requestProvider);
    bindValueSupplier(matrixSupplier);
    PathParamValueSupplierProvider pathSupplier = new PathParamValueSupplierProvider(paramExtractor, requestProvider);
    bindValueSupplier(pathSupplier);
    QueryParamValueSupplierProvider querySupplier = new QueryParamValueSupplierProvider(paramExtractor, requestProvider);
    bindValueSupplier(querySupplier);
    WebTargetValueSupplierProvider webTargetSupplier = new WebTargetValueSupplierProvider(requestProvider, lazyConfiguration, clientConfigProvider);
    bindValueSupplier(webTargetSupplier);
    BeanParamValueSupplierProvider beanSupplier = new BeanParamValueSupplierProvider(paramExtractor, requestProvider, injectionManager);
    bindValueSupplier(beanSupplier);
    // Register InjectionResolvers with param providers
    // TODO: RENAME INJECTION RESOLVER
    bind(new ParamInjectionResolver<>(cookieSupplier, CookieParam.class));
    bind(new ParamInjectionResolver<>(formSupplier, FormParam.class));
    bind(new ParamInjectionResolver<>(headerSupplier, HeaderParam.class));
    bind(new ParamInjectionResolver<>(matrixSupplier, MatrixParam.class));
    bind(new ParamInjectionResolver<>(querySupplier, QueryParam.class));
    bind(new ParamInjectionResolver<>(pathSupplier, PathParam.class));
    bind(new ParamInjectionResolver<>(asyncSupplier, Suspended.class));
    bind(new ParamInjectionResolver<>(webTargetSupplier, Uri.class));
    bind(new ParamInjectionResolver<>(beanSupplier, BeanParam.class));
    // Delegated value supplier for Context InjectionResolver which is implemented directly in DI provider
    ContextInjectionResolver contextInjectionResolver = injectionManager.getInstance(ContextInjectionResolver.class);
    bind(new DelegatedInjectionValueSupplierProvider(contextInjectionResolver, injectionManager::createForeignDescriptor)).to(ValueSupplierProvider.class);
}
Also used : FormParam(javax.ws.rs.FormParam) ContextInjectionResolver(org.glassfish.jersey.internal.inject.ContextInjectionResolver) PathParam(javax.ws.rs.PathParam) Provider(javax.inject.Provider) Configuration(javax.ws.rs.core.Configuration) AsyncContext(org.glassfish.jersey.server.internal.process.AsyncContext) AbstractBinder(org.glassfish.jersey.internal.inject.AbstractBinder) Providers(org.glassfish.jersey.internal.inject.Providers) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) Function(java.util.function.Function) Suspended(javax.ws.rs.container.Suspended) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Uri(org.glassfish.jersey.server.Uri) BeanParam(javax.ws.rs.BeanParam) QueryParam(javax.ws.rs.QueryParam) Value(org.glassfish.jersey.internal.util.collection.Value) MatrixParam(javax.ws.rs.MatrixParam) LazyValue(org.glassfish.jersey.internal.util.collection.LazyValue) ValueSupplierProvider(org.glassfish.jersey.server.spi.internal.ValueSupplierProvider) HeaderParam(javax.ws.rs.HeaderParam) ParamConverterProvider(javax.ws.rs.ext.ParamConverterProvider) CookieParam(javax.ws.rs.CookieParam) Injections(org.glassfish.jersey.internal.inject.Injections) Values(org.glassfish.jersey.internal.util.collection.Values) HeaderParam(javax.ws.rs.HeaderParam) MatrixParam(javax.ws.rs.MatrixParam) Configuration(javax.ws.rs.core.Configuration) AsyncContext(org.glassfish.jersey.server.internal.process.AsyncContext) Uri(org.glassfish.jersey.server.Uri) ParamConverterProvider(javax.ws.rs.ext.ParamConverterProvider) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) PathParam(javax.ws.rs.PathParam) Suspended(javax.ws.rs.container.Suspended) ContextInjectionResolver(org.glassfish.jersey.internal.inject.ContextInjectionResolver) BeanParam(javax.ws.rs.BeanParam) CookieParam(javax.ws.rs.CookieParam) QueryParam(javax.ws.rs.QueryParam) FormParam(javax.ws.rs.FormParam)

Example 3 with Provider

use of javax.inject.Provider in project OpenAM by OpenRock.

the class TokenGenerationServiceHttpRouteProvider method get.

@Override
public Set<HttpRoute> get() {
    return Collections.singleton(HttpRoute.newHttpRoute(STARTS_WITH, "sts-tokengen", new Provider<Handler>() {

        @Override
        public Handler get() {
            CollectionResourceProvider tokenGenerationService = new TokenGenerationService(TokenGenerationServiceInjectorHolder.getInstance(Key.get(SAML2TokenGeneration.class)), TokenGenerationServiceInjectorHolder.getInstance(Key.get(OpenIdConnectTokenGeneration.class)), TokenGenerationServiceInjectorHolder.getInstance(Key.get(new TypeLiteral<STSInstanceStateProvider<RestSTSInstanceState>>() {
            })), TokenGenerationServiceInjectorHolder.getInstance(Key.get(new TypeLiteral<STSInstanceStateProvider<SoapSTSInstanceState>>() {
            })), TokenGenerationServiceInjectorHolder.getInstance(Key.get(CTSTokenPersistence.class)), TokenGenerationServiceInjectorHolder.getInstance(Key.get(Logger.class)));
            rootRouter.route("").auditAs(STS).authorizeWith(STSTokenGenerationServiceAuthzModule.class).toCollection(tokenGenerationService);
            return Handlers.chainOf(newHttpHandler(rootRouter.getRouter()), authenticationFilter);
        }
    }));
}
Also used : STSInstanceStateProvider(org.forgerock.openam.sts.tokengeneration.state.STSInstanceStateProvider) CollectionResourceProvider(org.forgerock.json.resource.CollectionResourceProvider) STSTokenGenerationServiceAuthzModule(org.forgerock.openam.rest.authz.STSTokenGenerationServiceAuthzModule) STSInstanceStateProvider(org.forgerock.openam.sts.tokengeneration.state.STSInstanceStateProvider) Provider(javax.inject.Provider) HttpRouteProvider(org.forgerock.openam.http.HttpRouteProvider) CollectionResourceProvider(org.forgerock.json.resource.CollectionResourceProvider)

Example 4 with Provider

use of javax.inject.Provider in project StreetComplete by westnordost.

the class OverpassMapDataDaoTest method testHandleOverpassQuota.

public void testHandleOverpassQuota() throws InterruptedException {
    Provider provider = mock(Provider.class);
    when(provider.get()).thenReturn(mock(OverpassMapDataParser.class));
    OverpassStatus status = new OverpassStatus();
    status.availableSlots = 0;
    status.nextAvailableSlotIn = 2;
    OsmConnection osm = mock(OsmConnection.class);
    when(osm.makeRequest(eq("status"), any(OverpassStatusParser.class))).thenReturn(status);
    when(osm.makeRequest(eq("interpreter"), eq("POST"), eq(false), any(ApiRequestWriter.class), any(OverpassStatusParser.class))).thenThrow(OsmTooManyRequestsException.class);
    final OverpassMapDataDao dao = new OverpassMapDataDao(osm, provider);
    // the dao will call get(), get an exception in return, ask its status
    // then and at least wait for the specified amount of time before calling again
    final boolean[] result = new boolean[1];
    Thread dlThread = new Thread() {

        @Override
        public void run() {
            // assert false because we interrupt the thread further down...
            result[0] = dao.getAndHandleQuota("", null);
        }
    };
    dlThread.start();
    // sleep the wait time: Downloader should not try to call
    // overpass again in this time
    Thread.sleep(status.nextAvailableSlotIn * 1000);
    verify(osm, times(1)).makeRequest(eq("interpreter"), eq("POST"), eq(false), any(ApiRequestWriter.class), any(OverpassStatusParser.class));
    verify(osm, times(1)).makeRequest(eq("status"), any(OverpassStatusParser.class));
    // now we test if dao will call overpass again after that time. It is not really
    // defined when the downloader must call overpass again, lets assume 1.5 secs here and
    // change it when it fails
    Thread.sleep(1500);
    verify(osm, times(2)).makeRequest(eq("interpreter"), eq("POST"), eq(false), any(ApiRequestWriter.class), any(OverpassStatusParser.class));
    verify(osm, times(2)).makeRequest(eq("status"), any(OverpassStatusParser.class));
    // we are done here, interrupt thread (still part of the test though...)
    dlThread.interrupt();
    dlThread.join();
    assertFalse(result[0]);
}
Also used : ApiRequestWriter(de.westnordost.osmapi.ApiRequestWriter) OsmConnection(de.westnordost.osmapi.OsmConnection) Provider(javax.inject.Provider)

Example 5 with Provider

use of javax.inject.Provider in project xwiki-platform by xwiki.

the class DefaultEntityResourceActionListerTest method configure.

@Before
public void configure() throws Exception {
    Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
    when(componentManagerProvider.get()).thenReturn(this.mocker);
}
Also used : ComponentManager(org.xwiki.component.manager.ComponentManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) Provider(javax.inject.Provider) Before(org.junit.Before)

Aggregations

Provider (javax.inject.Provider)53 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)23 Test (org.junit.Test)15 ComponentManager (org.xwiki.component.manager.ComponentManager)15 Before (org.junit.Before)11 HashMap (java.util.HashMap)9 File (java.io.File)7 FilesystemExportContext (org.xwiki.url.filesystem.FilesystemExportContext)7 ArrayList (java.util.ArrayList)6 XWikiContext (com.xpn.xwiki.XWikiContext)5 Map (java.util.Map)5 DocumentReference (org.xwiki.model.reference.DocumentReference)5 Maps (com.google.common.collect.Maps)4 Type (java.lang.reflect.Type)4 Query (org.graylog.plugins.views.search.Query)4 QueryResult (org.graylog.plugins.views.search.QueryResult)4 SearchJob (org.graylog.plugins.views.search.SearchJob)4 SearchType (org.graylog.plugins.views.search.SearchType)4 IndexLookup (org.graylog.plugins.views.search.elasticsearch.IndexLookup)4 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)4