本文整理匯總了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);
}
示例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");
}
示例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;
}
示例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);
}
}
});
}
示例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);
}
示例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());
}
示例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());
}
示例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();
}
示例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());
}
示例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());
}
}
示例12: addDynamicFeature
import javax.ws.rs.container.DynamicFeature; //導入依賴的package包/類
public JerseyModuleExtender addDynamicFeature(DynamicFeature feature) {
contributeDynamicFeatures().addBinding().toInstance(feature);
return this;
}
示例13: contributeDynamicFeatures
import javax.ws.rs.container.DynamicFeature; //導入依賴的package包/類
protected Multibinder<DynamicFeature> contributeDynamicFeatures() {
if (dynamicFeatures == null) {
dynamicFeatures = newSet(DynamicFeature.class);
}
return dynamicFeatures;
}
示例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);
}