Java Code Examples for javax.enterprise.inject.Produces

The following are top voted examples for showing how to use javax.enterprise.inject.Produces. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: atbash-octopus   File: ProducerBean.java   View source code 7 votes vote down vote up
@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;
}
 
Example 2
Project: Biliomi   File: VersionInfoProducer.java   View source code 6 votes vote down vote up
@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;
}
 
Example 3
Project: javaee8-jaxrs-sample   File: PasswordEncoderProducer.java   View source code 6 votes vote down vote up
@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;
}
 
Example 4
Project: Biliomi   File: UserSettingsProducer.java   View source code 6 votes vote down vote up
@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;
}
 
Example 5
Project: wildfly-microprofile-config   File: ConfigProducer.java   View source code 6 votes vote down vote up
@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));
}
 
Example 6
Project: Mastering-Java-EE-Development-with-WildFly   File: BankFactory.java   View source code 5 votes vote down vote up
@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();
}
 
Example 7
Project: Mastering-Java-EE-Development-with-WildFly   File: BookService.java   View source code 5 votes vote down vote up
@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);
}
 
Example 8
Project: Mastering-Java-EE-Development-with-WildFly   File: PublishService.java   View source code 5 votes vote down vote up
@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);
}
 
Example 9
Project: willdfly-swarm-hello-world   File: LiquibaseProducer.java   View source code 5 votes vote down vote up
@Produces
@LiquibaseType
public CDILiquibaseConfig createConfig() {
    final CDILiquibaseConfig config = new CDILiquibaseConfig();
    config.setChangeLog("liquibase/db.changelog.xml");
    return config;
}
 
Example 10
Project: java-cdi   File: SpanContextProducer.java   View source code 5 votes vote down vote up
@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;
}
 
Example 11
Project: java-cdi   File: SpanContextProducer.java   View source code 5 votes vote down vote up
@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();
}
 
Example 12
Project: java-cdi   File: SpanContextProducer.java   View source code 5 votes vote down vote up
@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;
}
 
Example 13
Project: Hi-Framework   File: MVCReqHandler.java   View source code 5 votes vote down vote up
@Produces
public HTMLizer getHTMLizer(){

    HTMLizer htmLizer = HTMLizer.getInstance();
    htmLizer.setGsonBuilder(appContext.getGsonBuilder());
    return htmLizer;

}
 
Example 14
Project: atbash-octopus   File: ProducerBean.java   View source code 5 votes vote down vote up
@Produces
@Named("loggedInUser")
public String produceUser() {
    Object principal = SecurityUtils.getSubject().getPrincipal();
    if (principal != null) {
        return principal.toString();
    } else {
        return null;
    }
}
 
Example 15
Project: java-ml-projects   File: Producers.java   View source code 5 votes vote down vote up
@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());
}
 
Example 16
Project: java-ml-projects   File: Producers.java   View source code 5 votes vote down vote up
@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;
}
 
Example 17
Project: lra-service   File: BeanConfiguration.java   View source code 5 votes vote down vote up
@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();

}
 
Example 18
Project: poi   File: ConfiguratorProducer.java   View source code 5 votes vote down vote up
/**
 * 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);
}
 
Example 19
Project: xsharing-services-router   File: TargetProducer.java   View source code 5 votes vote down vote up
@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);
}
 
Example 20
Project: scalable-coffee-shop   File: KafkaConfigurator.java   View source code 5 votes vote down vote up
@Produces
@RequestScoped
public Properties exposeKafkaProperties() throws IOException {
    final Properties properties = new Properties();
    properties.putAll(kafkaProperties);
    return properties;
}
 
Example 21
Project: scalable-coffee-shop   File: KafkaConfigurator.java   View source code 5 votes vote down vote up
@Produces
@RequestScoped
public Properties exposeKafkaProperties() throws IOException {
    final Properties properties = new Properties();
    properties.putAll(kafkaProperties);
    return properties;
}
 
Example 22
Project: scalable-coffee-shop   File: KafkaConfigurator.java   View source code 5 votes vote down vote up
@Produces
@RequestScoped
public Properties exposeKafkaProperties() throws IOException {
    final Properties properties = new Properties();
    properties.putAll(kafkaProperties);
    return properties;
}
 
Example 23
Project: crnk-framework   File: MetaModuleProducer.java   View source code 5 votes vote down vote up
@Produces
@ApplicationScoped
public MetaModule createMetaModule() {
	MetaModuleConfig metaConfig = new MetaModuleConfig();
	metaConfig.addMetaProvider(new ResourceMetaProvider());
	MetaModule metaModule = MetaModule.createServerModule(metaConfig);
	return metaModule;
}
 
Example 24
Project: crnk-framework   File: MetaModuleProducer.java   View source code 5 votes vote down vote up
@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;
}
 
Example 25
Project: testee.fi-examples   File: WebDriverProducer.java   View source code 5 votes vote down vote up
@Produces
public WebDriver webDriver() {
    synchronized (WebDriverProducer.class) {
        if (webDriver == null) {
            webDriver = getWebDriverFactory().create();
            getRuntime().addShutdownHook(new Thread(webDriver::close));
        }
        return webDriver;
    }
}
 
Example 26
Project: redis-cdi-example   File: JedisProducer.java   View source code 5 votes vote down vote up
@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;
}
 
Example 27
Project: redis-cdi-example   File: PooledJedisProducer.java   View source code 5 votes vote down vote up
@RequestScoped
@Produces
@FromJedisPool
public Jedis get() {
    Jedis jedis = pool.getResource();
    System.out.println("Got resource from Jedis pool");
    return jedis;
}
 
Example 28
Project: apm-client   File: HelloServiceConfiguration.java   View source code 5 votes vote down vote up
/**
 * Get the configuration.
 * @return The configuration
 */
@Produces
static TraceConfiguration getDefault() {
  return new TraceConfiguration(
    "greetings-server",
    "http://localhost:8126",
    TimeUnit.MINUTES.toMillis(1));
}
 
Example 29
Project: apm-client   File: TraceConfigurationFactory.java   View source code 5 votes vote down vote up
/**
 * Get the configuration.
 * @return The configuration
 */
@Produces
static TraceConfiguration getDefault() {
  return new TraceConfiguration(
    "greetings-client",
    "http://localhost:8126",
    TimeUnit.MINUTES.toMillis(1));
}
 
Example 30
Project: apm-client   File: TraceConfigurationFactory.java   View source code 5 votes vote down vote up
/**
 * Get the configuration.
 * @return The configuration
 */
@Produces
static TraceConfiguration getDefault() {
  return new TraceConfiguration(
    "greetings-client",
    "http://localhost:8126",
    TimeUnit.MINUTES.toMillis(1));
}
 
Example 31
Project: microprofile-metrics   File: MetricProducerMethodBean.java   View source code 5 votes vote down vote up
@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();
        }
    };

}
 
Example 32
Project: Biliomi   File: LoggerProducer.java   View source code 5 votes vote down vote up
@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);
}
 
Example 33
Project: payara-micro-docker-starter-kit   File: ConfigProducer.java   View source code 5 votes vote down vote up
@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);
}
 
Example 34
Project: Pedidex   File: Resources.java   View source code 5 votes vote down vote up
@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);
}
 
Example 35
Project: Java-9-Programming-Blueprints   File: Producers.java   View source code 5 votes vote down vote up
@Produces
private MongoDatabase getDatabase() {
    if (database == null) {
        database = getMongoClient().getDatabase("monumentum");
    }
    
    return database;
}
 
Example 36
Project: Architecting-Modern-Java-EE-Applications   File: ConfigurationExposer.java   View source code 5 votes vote down vote up
@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;
}
 
Example 37
Project: Architecting-Modern-Java-EE-Applications   File: GreetingStrategySelector.java   View source code 5 votes vote down vote up
@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");
}
 
Example 38
Project: Architecting-Modern-Java-EE-Applications   File: ConfigurationExposer.java   View source code 5 votes vote down vote up
@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;
}
 
Example 39
Project: javaee8-jsf-sample   File: Resources.java   View source code 4 votes vote down vote up
@Produces
public Logger getLogger(InjectionPoint p) {
    return Logger.getLogger(p.getMember().getDeclaringClass().getName());
}
 
Example 40
Project: launcher-backend   File: BoosterCatalogFactory.java   View source code 4 votes vote down vote up
@Produces
@Singleton
public BoosterCatalog getDefaultCatalog() {
    return defaultBoosterCatalog;
}