@Produces @RequestScoped @Named("userPrincipal") public UserPrincipal producePrincipal() { Object principal = SecurityUtils.getSubject().getPrincipal(); UserPrincipal result = null; if (principal instanceof UserPrincipal) { result = (UserPrincipal) principal; } /* FIXME if (principal instanceof SystemAccountPrincipal) { SystemAccountPrincipal systemAccountPrincipal = (SystemAccountPrincipal) principal; String identifier = systemAccountPrincipal.getIdentifier(); result = new UserPrincipal(identifier); } */ if (principal == null) { result = new UserPrincipal(); } return result; }
@Produces public VersionInfo getVersionInfo() { VersionInfo versionInfo = new VersionInfo(); try { versionInfo.setVersion(appVersion); versionInfo.setUserAgent(userAgent); versionInfo.setBuildDate(new DateTime(buildTimestamp)); } catch (IllegalArgumentException e) { // In development mode no sources will be filtered yet versionInfo.setVersion("DEVELOPMENT"); versionInfo.setUserAgent("DEVELOPMENT"); versionInfo.setBuildDate(new DateTime()); } return versionInfo; }
@Produces @Crypto public PasswordEncoder passwordEncoder(InjectionPoint ip) { Crypto crypto = ip.getAnnotated().getAnnotation(Crypto.class); Crypto.Type type = crypto.value(); PasswordEncoder encoder; switch (type) { case PLAIN: encoder = new PlainPasswordEncoder(); break; case BCRYPT: encoder = new BCryptPasswordEncoder(); break; default: encoder = new PlainPasswordEncoder(); break; } return encoder; }
@Produces @CoreSetting("PRODUCER") public String getUserSetting(InjectionPoint injectionPoint) { Annotated annotated = injectionPoint.getAnnotated(); if (annotated.isAnnotationPresent(CoreSetting.class)) { String settingPath = annotated.getAnnotation(CoreSetting.class).value(); Object object = yamlCoreSettings; String[] split = settingPath.split("\\."); int c = 0; while (c < split.length) { try { object = PropertyUtils.getProperty(object, split[c]); c++; } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { LogManager.getLogger(getClass()).error("Failed retrieving setting " + settingPath, e); return null; } } return String.valueOf(object); } return null; }
@SuppressWarnings("unchecked") @Dependent @Produces @ConfigProperty <T> Optional<T> produceOptionalConfigValue(InjectionPoint injectionPoint) { Type type = injectionPoint.getAnnotated().getBaseType(); final Class<T> valueType; if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; Type[] typeArguments = parameterizedType.getActualTypeArguments(); valueType = unwrapType(typeArguments[0]); } else { valueType = (Class<T>) String.class; } return Optional.ofNullable(getValue(injectionPoint, valueType)); }
@Produces @BankProducer public Bank createBank(@Any Instance<Bank> instance, InjectionPoint injectionPoint) { Annotated annotated = injectionPoint.getAnnotated(); BankType bankTypeAnnotation = annotated.getAnnotation(BankType.class); Class<? extends Bank> bankType = bankTypeAnnotation.value().getBankType(); return instance.select(bankType).get(); }
@Draft @Produces public List<Book> getDraftBooks() { Book[] books = new Book[] { new Book("Glassfish", "Luca Stancapiano", DRAFT), new Book("Maven working", "Luca Stancapiano", DRAFT) }; return asList(books); }
@Published @Produces public List<Book> getPublishedBooks() { Book[] books = new Book[] { new Book("Mastering Java EE Development with WildFly 10", "Luca Stancapiano", PUBLISHED), new Book("Gatein Cookbook", "Luca Stancapiano", PUBLISHED) }; return asList(books); }
@Produces @LiquibaseType public CDILiquibaseConfig createConfig() { final CDILiquibaseConfig config = new CDILiquibaseConfig(); config.setChangeLog("liquibase/db.changelog.xml"); return config; }
@Produces public SpanContext produceSpanContext() { SpanContext spanContext = (SpanContext) request.getAttribute(TracingFilter.SERVER_SPAN_CONTEXT); if (null == spanContext) { log.warning("A SpanContext has been requested, but none could be found on the HTTP request's " + "attributes. Make sure the Servlet integration is on the classpath!"); } return spanContext; }
@Produces public Span produceSpan(InjectionPoint ip) { Scope scope = tracer.scopeManager().active(); if (null == scope) { String spanName = ip.getMember().getName(); return tracer.buildSpan(spanName).startActive().span(); } return scope.span(); }
@Produces public Scope produceScope(InjectionPoint ip) { Scope scope = tracer.scopeManager().active(); if (null == scope) { String spanName = ip.getMember().getName(); return tracer.buildSpan(spanName).startActive(); } return scope; }
@Produces public HTMLizer getHTMLizer(){ HTMLizer htmLizer = HTMLizer.getInstance(); htmLizer.setGsonBuilder(appContext.getGsonBuilder()); return htmLizer; }
@Produces @Named("loggedInUser") public String produceUser() { Object principal = SecurityUtils.getSubject().getPrincipal(); if (principal != null) { return principal.toString(); } else { return null; } }
@Produces @DatasetLabels public List<String> produceLabels() { String labelsProperty = System.getProperty(LABELS_PROPERTY); if (labelsProperty == null) { throw new Error("Provide comma separated values for the dataset labels using the system property " + LABELS_PROPERTY); } return Stream.of(labelsProperty.split("\\,")).collect(Collectors.toList()); }
@Produces @OutputDir public String produceOutputDir() { String outputDir = System.getProperty(OUTPUT_DIR); if (outputDir == null) { outputDir = System.getProperty("user.home"); logger.info("Using user home dir since no output dir was set: " + outputDir); } return outputDir; }
@Produces @Singleton public Tracer tracer() { String jaegerURL = System.getenv("JAEGER_SERVER_HOSTNAME"); if (jaegerURL != null) { log.info("Using Jaeger tracer"); return jaegerTracer(jaegerURL); } log.info("Using Noop tracer"); return NoopTracerFactory.create(); }
/** * Define as system property * f.e.: connectionTimeout=500 and/or readTimeout=500 */ @Produces public long expose(InjectionPoint ip) { String fieldName = ip.getMember().getName(); String configuredValue = System.getenv().getOrDefault(fieldName, "0"); return Long.parseLong(configuredValue); }
@Produces @ApplicationScoped public IVRouterService produceWebTarget() { return new ResteasyClientBuilder() .connectionPoolSize(100) .maxPooledPerRoute(20) .asyncExecutor(executor) .build() .target(CONFIG.getIvRouterBaseUrl()) .queryParam(IVRouterConfig.FORMAT, IVRouterConfig.REQUEST_FORMAT) .proxy(IVRouterService.class); }
@Produces @RequestScoped public Properties exposeKafkaProperties() throws IOException { final Properties properties = new Properties(); properties.putAll(kafkaProperties); return properties; }
@Produces @ApplicationScoped public MetaModule createMetaModule() { MetaModuleConfig metaConfig = new MetaModuleConfig(); metaConfig.addMetaProvider(new ResourceMetaProvider()); MetaModule metaModule = MetaModule.createServerModule(metaConfig); return metaModule; }
@Produces @ApplicationScoped public Module createRepositoryModule() { SimpleModule module = new SimpleModule("mock"); module.addRepository(new ScheduleRepositoryImpl()); module.addRepository(new ProjectRepository()); module.addRepository(new TaskRepository()); module.addRepository(new ProjectToTaskRepository()); module.addRepository(new ScheduleToTaskRepository()); module.addRepository(new TaskSubtypeRepository()); module.addRepository(new TaskToProjectRepository()); module.addRepository(new TaskToScheduleRepo()); return module; }
@Produces public WebDriver webDriver() { synchronized (WebDriverProducer.class) { if (webDriver == null) { webDriver = getWebDriverFactory().create(); getRuntime().addShutdownHook(new Thread(webDriver::close)); } return webDriver; } }
@Dependent @Produces public Jedis get(InjectionPoint ip) { System.out.println("injecting Jedis into " + ip.getMember().getDeclaringClass().getSimpleName()); String redisHost = System.getenv().getOrDefault("REDIS_HOST", "192.168.99.100"); String redisPort = System.getenv().getOrDefault("REDIS_PORT", "6379"); Jedis jedis = new Jedis(redisHost, Integer.valueOf(redisPort), 10000); jedis.connect(); System.out.println("Redis Connection obtained"); return jedis; }
@RequestScoped @Produces @FromJedisPool public Jedis get() { Jedis jedis = pool.getResource(); System.out.println("Got resource from Jedis pool"); return jedis; }
/** * Get the configuration. * @return The configuration */ @Produces static TraceConfiguration getDefault() { return new TraceConfiguration( "greetings-server", "http://localhost:8126", TimeUnit.MINUTES.toMillis(1)); }
/** * Get the configuration. * @return The configuration */ @Produces static TraceConfiguration getDefault() { return new TraceConfiguration( "greetings-client", "http://localhost:8126", TimeUnit.MINUTES.toMillis(1)); }
@Produces @Metric(name = "cache-hits") Gauge<Double> cacheHitRatioGauge(final @Metric(name = "hits") Meter hits, final @Metric(name = "calls") Timer calls) { return new Gauge<Double>() { @Override public Double getValue() { return (double) hits.getCount() / (double) calls.getCount(); } }; }
@Produces public Logger getLogger(InjectionPoint injectionPoint) { Class loggerClass; if (injectionPoint.getAnnotated().isAnnotationPresent(LoggerFor.class)) { loggerClass = injectionPoint.getAnnotated().getAnnotation(LoggerFor.class).value(); } else { loggerClass = injectionPoint.getBean().getBeanClass(); } return LogManager.getLogger(loggerClass); }
@Produces @IConfig public Config produce(InjectionPoint injectionPoint) throws IOException { Annotated annotated = injectionPoint.getAnnotated(); IConfig iConfig = annotated.getAnnotation(IConfig.class); String key = iConfig.value(); if (!configs.containsKey(key)) { Config config = new Config(); config.load(key); configs.put(key, config); } return configs.get(key); }
@Produces public <T extends Entidade> GenericDao<T> produceDao(InjectionPoint injectionPoint, EntityManager em) { Type[] args = ((ParameterizedType)injectionPoint.getType()).getActualTypeArguments(); if (args.length == 0) throw new IllegalArgumentException("O GenericDao precisa de um tipo"); Class<T> type = (Class<T>) args[0]; return new GenericDao(em, type); }
@Produces private MongoDatabase getDatabase() { if (database == null) { database = getMongoClient().getDatabase("monumentum"); } return database; }
@Produces @Config("") public String exposeConfig(InjectionPoint injectionPoint) { final Config config = injectionPoint.getAnnotated().getAnnotation(Config.class); if (config != null) return properties.getProperty(config.value()); return null; }
@Produces public Function<String, String> exposeStrategy() { for (GreetingStrategy strategy : strategies) { if (strategy.isAppropriate(LocalTime.now())) return strategy::greet; } throw new IllegalStateException("Couldn't find an appropriate greeting"); }
@Produces public Logger getLogger(InjectionPoint p) { return Logger.getLogger(p.getMember().getDeclaringClass().getName()); }
@Produces @Singleton public BoosterCatalog getDefaultCatalog() { return defaultBoosterCatalog; }