本文整理汇总了Java中io.dropwizard.setup.Environment.jersey方法的典型用法代码示例。如果您正苦于以下问题:Java Environment.jersey方法的具体用法?Java Environment.jersey怎么用?Java Environment.jersey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.dropwizard.setup.Environment
的用法示例。
在下文中一共展示了Environment.jersey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import io.dropwizard.setup.Environment; //导入方法依赖的package包/类
@Override
public void run(ApiConfig configuration, Environment environment) throws Exception {
LOGGER.info("api started up");
injector = guiceBundle.getInjector();
JerseyEnvironment jersey = environment.jersey();
register(environment.lifecycle(), REFLECTIONS.getSubTypesOf(Managed.class)); // registers NbdServer
// injector.getInstance(SessionFactory.class); //init DB
installCorsFilter(environment);
//init all Singletons semi-eagerly
REFLECTIONS.getTypesAnnotatedWith(Singleton.class).forEach(injector::getInstance);
final Set<Class<?>> resources = REFLECTIONS.getTypesAnnotatedWith(Path.class);
register(jersey, resources);
jersey.register(new LoggingExceptionMapper<Throwable>() {
@Override
protected String formatErrorMessage(long id, Throwable exception) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
exception.printStackTrace(pw);
return sw.toString();
}
});
jersey.register(new JsonProcessingExceptionMapper(true));
jersey.register(new EarlyEofExceptionMapper());
final TrivialAuthenticator instance = injector.getInstance(TrivialAuthenticator.class);
environment.jersey().register(new AuthDynamicFeature(
new BasicCredentialAuthFilter.Builder<Principal>()
.setAuthenticator(instance)
.setAuthorizer((principal, role) -> false)
.buildAuthFilter()));
environment.jersey().register(RolesAllowedDynamicFeature.class);
}