當前位置: 首頁>>代碼示例>>Java>>正文


Java DynamicFeature類代碼示例

本文整理匯總了Java中javax.ws.rs.container.DynamicFeature的典型用法代碼示例。如果您正苦於以下問題:Java DynamicFeature類的具體用法?Java DynamicFeature怎麽用?Java DynamicFeature使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DynamicFeature類屬於javax.ws.rs.container包,在下文中一共展示了DynamicFeature類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

import javax.ws.rs.container.DynamicFeature; //導入依賴的package包/類
public void run(Configuration configuration, Environment environment) throws Exception {
  final CollectorRegistry collectorRegistry = new CollectorRegistry();
  collectorRegistry.register(new DropwizardExports(environment.metrics()));
  environment.admin()
      .addServlet("metrics", new MetricsServlet(collectorRegistry))
      .addMapping("/metrics");

  final PrometheusMetricsReporter reporter = PrometheusMetricsReporter.newMetricsReporter()
      .withCollectorRegistry(collectorRegistry)
      .withConstLabel("service", getName())
      .build();

  final Tracer tracer = getTracer();
  final Tracer metricsTracer = io.opentracing.contrib.metrics.Metrics.decorate(tracer, reporter);
  GlobalTracer.register(metricsTracer);

  final DynamicFeature tracing = new ServerTracingDynamicFeature.Builder(metricsTracer).build();
  environment.jersey().register(tracing);

  final Properties producerConfigs = new Properties();
  producerConfigs.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "tweets-kafka:9092");
  producerConfigs.put(ProducerConfig.ACKS_CONFIG, "all");
  producerConfigs.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, true);
  final KafkaProducer<Long, String> kafkaProducer =
      new KafkaProducer<>(producerConfigs, new LongSerializer(), new StringSerializer());
  final Producer<Long, String> tracingKafkaProducer =
      new TracingKafkaProducer<>(kafkaProducer, metricsTracer);
  final ObjectMapper objectMapper = environment.getObjectMapper();
  final TweetEventRepository tweetRepository = new KafkaTweetEventRepository(tracingKafkaProducer, objectMapper);
  final TweetsService tweetsService = new TweetsService(tweetRepository);
  final TweetsResource tweetsResource = new TweetsResource(tweetsService);
  environment.jersey().register(tweetsResource);
}
 
開發者ID:jeqo,項目名稱:talk-observing-distributed-systems,代碼行數:34,代碼來源:WorkerServiceApplication.java

示例2: run

import javax.ws.rs.container.DynamicFeature; //導入依賴的package包/類
public void run(Configuration configuration, Environment environment) {
  final CollectorRegistry collectorRegistry = new CollectorRegistry();
  collectorRegistry.register(new DropwizardExports(environment.metrics()));

  final PrometheusMetricsReporter reporter =
      PrometheusMetricsReporter.newMetricsReporter()
          .withCollectorRegistry(collectorRegistry)
          .withConstLabel("service", getName())
          .build();

  final Tracer tracer = getTracer();
  final Tracer metricsTracer = io.opentracing.contrib.metrics.Metrics.decorate(tracer, reporter);
  GlobalTracer.register(metricsTracer);

  final String jdbcUrl = "jdbc:tracing:postgresql://tweets-db/postgres";
  final String jdbcUsername = "postgres";
  final String jdbcPassword = "example";
  final TweetsRepository tweetsRepository = new JooqPostgresTweetsRepository(jdbcUrl, jdbcUsername, jdbcPassword);
  final TweetsService tweetsService = new TweetsService(tweetsRepository);
  final TweetsResource tweetsResource = new TweetsResource(tweetsService);

  environment.jersey().register(tweetsResource);

  final DynamicFeature tracing = new ServerTracingDynamicFeature.Builder(metricsTracer).build();
  environment.jersey().register(tracing);

  environment.admin()
      .addServlet("metrics", new MetricsServlet(collectorRegistry))
      .addMapping("/metrics");
}
 
開發者ID:jeqo,項目名稱:talk-observing-distributed-systems,代碼行數:31,代碼來源:TweetsServiceApplication.java

示例3: createResourceConfig

import javax.ws.rs.container.DynamicFeature; //導入依賴的package包/類
@Singleton
@Provides
private ResourceConfig createResourceConfig(Injector injector,
                                            Set<Feature> features,
                                            Set<DynamicFeature> dynamicFeatures,
                                            @JerseyResource Set<Object> resources, Set<Package> packages,
                                            @JerseyResource Map<String, Object> properties) {

    ResourceConfig config = new ResourceConfig();

    packages.forEach(p -> config.packages(true, p.getName()));
    resources.forEach(r -> config.register(r));

    features.forEach(f -> config.register(f));
    dynamicFeatures.forEach(df -> config.register(df));

    config.addProperties(properties);

    // TODO: make this pluggable?
    config.register(ResourceModelDebugger.class);

    // register Guice Injector as a service in Jersey HK2, and GuiceBridgeFeature as a
    GuiceBridgeFeature.register(config, injector);

    return config;
}
 
開發者ID:bootique,項目名稱:bootique-jersey,代碼行數:27,代碼來源:JerseyModule.java

示例4: Server

import javax.ws.rs.container.DynamicFeature; //導入依賴的package包/類
public Server() {
    register(FreemarkerMvcFeature.class);

    packages("ru.qatools.school.baguette.resources");

    register(new DynamicFeature() {
        @Override
        public void configure(ResourceInfo resourceInfo, FeatureContext context) {
            context.register(DatabaseProvider.class);

            if (resourceInfo.getResourceMethod().isAnnotationPresent(AuthenticationRequired.class)) {
                context.register(AuthenticationFilter.class);
            }
        }
    });
}
 
開發者ID:autoschool,項目名稱:baguette,代碼行數:17,代碼來源:Server.java

示例5: testConfiguration

import javax.ws.rs.container.DynamicFeature; //導入依賴的package包/類
@Test
public void testConfiguration() throws Exception {
	logger.info("start REST Configuration test");
	Client client = newClient();
	Configuration configuration = client.getConfiguration();
	Set<Class<?>> classes = configuration.getClasses();
	for (Class<?> clazz : classes) {
		assertTrue("verify if the class is a rest component or provider",
				MessageBodyReader.class.isAssignableFrom(clazz) || MessageBodyWriter.class.isAssignableFrom(clazz)
						|| clazz.isAnnotationPresent(Provider.class)
						|| DynamicFeature.class.isAssignableFrom(clazz));
		Map<Class<?>, Integer> contracts = configuration.getContracts(clazz);
		assertFalse("each class has different contracts", contracts.isEmpty());
		for (Class<?> contract : contracts.keySet()) {
			int value = contracts.get(contract);
			assertTrue("verify if the contract is a rest component or provider",
					value == 5000 || value == 4000 || value == 3000 || value == 0);
		}
	}
	Set<Object> instances = configuration.getInstances();
	assertTrue("by default there are not instances", instances.isEmpty());
	Map<String, Object> properties = configuration.getProperties();
	assertTrue("by default there are not properties", properties.isEmpty());
	MyComponent myComponent = new MyComponent();
	client.register(myComponent);
	instances = configuration.getInstances();
	assertFalse("Added instance", instances.isEmpty());
	for (Object instance : instances) {
		if (instance instanceof MyComponent)
			assertTrue("MyComponent is registered and active", configuration.isEnabled((Feature) instance));
	}
	assertEquals("Added property through MyComponent", 1, properties.size());
	boolean property = (Boolean) properties.get("configured_myComponent");
	assertEquals("configured_myComponent ok!", true, property);
	assertEquals("type CLIENT by default", CLIENT, configuration.getRuntimeType());
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Java-EE-Development-with-WildFly,代碼行數:37,代碼來源:ComponentTestCase.java

示例6: run

import javax.ws.rs.container.DynamicFeature; //導入依賴的package包/類
public void run(Configuration configuration, Environment environment) throws Exception {
  final CollectorRegistry collectorRegistry = new CollectorRegistry();
  collectorRegistry.register(new DropwizardExports(environment.metrics()));
  environment.admin()
      .addServlet("metrics", new MetricsServlet(collectorRegistry))
      .addMapping("/metrics");

  final PrometheusMetricsReporter reporter = PrometheusMetricsReporter.newMetricsReporter()
      .withCollectorRegistry(collectorRegistry)
      .withConstLabel("service", getName())
      .build();

  final Tracer tracer = getTracer();
  final Tracer metricsTracer = io.opentracing.contrib.metrics.Metrics.decorate(tracer, reporter);
  GlobalTracer.register(metricsTracer);

  final DynamicFeature tracing = new ServerTracingDynamicFeature.Builder(metricsTracer).build();
  environment.jersey().register(tracing);

  final HttpHost httpHost = new HttpHost("tweets-elasticsearch", 9200);
  final RestClientBuilder restClientBuilder =
      RestClient.builder(httpHost).setHttpClientConfigCallback(new TracingHttpClientConfigCallback(metricsTracer));
  final RestClient restClient = restClientBuilder.build();
  final RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClient);
  final TweetRepository tweetRepository = new ElasticsearchTweetRepository(restHighLevelClient);
  final TweetsResource tweetsResource = new TweetsResource(tweetRepository);
  environment.jersey().register(tweetsResource);
}
 
開發者ID:jeqo,項目名稱:talk-observing-distributed-systems,代碼行數:29,代碼來源:SearchServiceApplication.java

示例7: Server

import javax.ws.rs.container.DynamicFeature; //導入依賴的package包/類
public Server() {
    register(FreemarkerMvcFeature.class);

    register(new DynamicFeature() {
        @Override
        public void configure(ResourceInfo resourceInfo, FeatureContext context) {
            context.register(DatabaseProvider.class);
            context.register(AuthUserProvider.class);
        }
    });

    packages(Server.class.getPackage().getName());
}
 
開發者ID:autoschool,項目名稱:ya.blogo,代碼行數:14,代碼來源:Server.java

示例8: Server

import javax.ws.rs.container.DynamicFeature; //導入依賴的package包/類
public Server() {
    register(FreemarkerMvcFeature.class);

    register(new DynamicFeature() {
        @Override
        public void configure(ResourceInfo resourceInfo, FeatureContext context) {
            context.register(DatabaseProvider.class);
        }
    });

    packages(Server.class.getPackage().getName());
}
 
開發者ID:autoschool,項目名稱:switter,代碼行數:13,代碼來源:Server.java

示例9: Server

import javax.ws.rs.container.DynamicFeature; //導入依賴的package包/類
public Server() {
    Splinter splinter = new Splinter();
    registerBinders(splinter);
    
    SimpleContainer.getLogger().debug(
            String.format(
                    "Starting application in `%s` environment using `%s` database driver",
                    splinter.getEnvironment().toString().toLowerCase(),
                    splinter.getConfiguration().getDatabaseConfiguration().getDriver().toString().toLowerCase()
            )
    );
    
    property(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
    property(ServerProperties.BV_DISABLE_VALIDATE_ON_EXECUTABLE_OVERRIDE_CHECK, true);
    register(FreemarkerMvcFeature.class);

    register(new DynamicFeature() {
        @Override
        public void configure(ResourceInfo resourceInfo, FeatureContext context) {
            context.register(DatabaseProvider.class);
            context.register(AuthProvider.class);
        }
    });

    packages(Server.class.getPackage().getName());
    
    registerSharedVariables();
}
 
開發者ID:autoschool,項目名稱:splinter,代碼行數:29,代碼來源:Server.java

示例10: Server

import javax.ws.rs.container.DynamicFeature; //導入依賴的package包/類
public Server() {
    register(FreemarkerMvcFeature.class);

    register(new DynamicFeature() {
        @Override
        public void configure(ResourceInfo resourceInfo, FeatureContext context) {

            context.register(DatabaseProvider.class);
            context.register(AuthUserProvider.class);
        }
    });

    packages(Server.class.getPackage().getName());
}
 
開發者ID:autoschool,項目名稱:twister,代碼行數:15,代碼來源:Server.java

示例11: removeRegistrations

import javax.ws.rs.container.DynamicFeature; //導入依賴的package包/類
/**
 * Unregisters a @Provider type from this factory.
 */
public void removeRegistrations(final Class<?> type) {
  checkNotNull(type);

  log.debug("Removing registrations for: {}", type.getName());

  classContracts.remove(type);

  removeInstancesOf(type, providerInstances);
  providerClasses.remove(type);

  if (ExceptionMapper.class.isAssignableFrom(type)) {
    removeInstancesOf(type, exceptionMappers.values());
  }
  else if (MessageBodyReader.class.isAssignableFrom(type)) {
    clearInstancesOf(type, clientMessageBodyReaders, DUMMY_READER);
    clearInstancesOf(type, serverMessageBodyReaders, DUMMY_READER);
  }
  else if (MessageBodyWriter.class.isAssignableFrom(type)) {
    clearInstancesOf(type, clientMessageBodyWriters, DUMMY_WRITER);
    clearInstancesOf(type, serverMessageBodyWriters, DUMMY_WRITER);
  }
  else if (ContextResolver.class.isAssignableFrom(type)) {
    Type[] args = Types.getActualTypeArgumentsOfAnInterface(type, ContextResolver.class);
    contextResolvers.remove(Types.getRawType(args[0]));
  }
  else if (Feature.class.isAssignableFrom(type)) {
    removeInstancesOf(type, featureInstances);
    removeInstancesOf(type, enabledFeatures);
    featureClasses.remove(type);
  }
  else if (DynamicFeature.class.isAssignableFrom(type)) {
    removeInstancesOf(type, clientDynamicFeatures);
    removeInstancesOf(type, serverDynamicFeatures);
  }
  else if (ParamConverterProvider.class.isAssignableFrom(type)) {
    removeInstancesOf(type, paramConverterProviders);
  }
  else if (StringConverter.class.isAssignableFrom(type)) {
    removeInstancesOf(type, stringConverters.values());
  }
  else if (StringParameterUnmarshaller.class.isAssignableFrom(type)) {
    stringParameterUnmarshallers.values().remove(type);
  }
  else {
    log.warn("Unable to remove registrations for: {}", type.getName());
  }
}
 
開發者ID:sonatype,項目名稱:nexus-public,代碼行數:51,代碼來源:SisuResteasyProviderFactory.java

示例12: addDynamicFeature

import javax.ws.rs.container.DynamicFeature; //導入依賴的package包/類
public JerseyModuleExtender addDynamicFeature(DynamicFeature feature) {
    contributeDynamicFeatures().addBinding().toInstance(feature);
    return this;
}
 
開發者ID:bootique,項目名稱:bootique-jersey,代碼行數:5,代碼來源:JerseyModuleExtender.java

示例13: contributeDynamicFeatures

import javax.ws.rs.container.DynamicFeature; //導入依賴的package包/類
protected Multibinder<DynamicFeature> contributeDynamicFeatures() {
    if (dynamicFeatures == null) {
        dynamicFeatures = newSet(DynamicFeature.class);
    }
    return dynamicFeatures;
}
 
開發者ID:bootique,項目名稱:bootique-jersey,代碼行數:7,代碼來源:JerseyModuleExtender.java

示例14: contributeDynamicFeatures

import javax.ws.rs.container.DynamicFeature; //導入依賴的package包/類
/**
 * @param binder DI binder passed to the Module that invokes this method.
 * @return returns a {@link Multibinder} for JAX-RS DynamicFeatures.
 * @since 0.12
 * @deprecated since 0.21 call {@link #extend(Binder)} and then call
 * {@link JerseyModuleExtender#addDynamicFeature(DynamicFeature)}.
 */
@Deprecated
public static Multibinder<DynamicFeature> contributeDynamicFeatures(Binder binder) {
    return Multibinder.newSetBinder(binder, DynamicFeature.class);
}
 
開發者ID:bootique,項目名稱:bootique-jersey,代碼行數:12,代碼來源:JerseyModule.java


注:本文中的javax.ws.rs.container.DynamicFeature類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。