本文整理汇总了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);
}