本文整理汇总了Java中io.dropwizard.jersey.errors.LoggingExceptionMapper类的典型用法代码示例。如果您正苦于以下问题:Java LoggingExceptionMapper类的具体用法?Java LoggingExceptionMapper怎么用?Java LoggingExceptionMapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LoggingExceptionMapper类属于io.dropwizard.jersey.errors包,在下文中一共展示了LoggingExceptionMapper类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: run
import io.dropwizard.jersey.errors.LoggingExceptionMapper; //导入依赖的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);
}
开发者ID:MineboxOS,项目名称:minebox,代码行数:39,代码来源:MinebdApplication.java
示例2: toResponse
import io.dropwizard.jersey.errors.LoggingExceptionMapper; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Response toResponse(UncheckedExecutionException e) {
ExceptionMapper mapper = _providers.getExceptionMapper(e.getCause().getClass());
if (mapper == null) {
return null;
} else if (mapper instanceof LoggingExceptionMapper) {
return mapper.toResponse(e);
} else {
return mapper.toResponse(e.getCause());
}
}
开发者ID:bazaarvoice,项目名称:emodb,代码行数:13,代码来源:UncheckedExecutionExceptionMapper.java
示例3: configure
import io.dropwizard.jersey.errors.LoggingExceptionMapper; //导入依赖的package包/类
@Override
protected void configure() {
bind(new LoggingExceptionMapper<Throwable>() {
}).to(ExceptionMapper.class);
bind(new JerseyViolationExceptionMapper()).to(ExceptionMapper.class);
bind(new JsonProcessingExceptionMapper(isShowDetails())).to(ExceptionMapper.class);
bind(new EarlyEofExceptionMapper()).to(ExceptionMapper.class);
// bind(new EmptyOptionalExceptionMapper()).to(ExceptionMapper.class);
}
开发者ID:robeio,项目名称:robe,代码行数:10,代码来源:ExceptionMapperBinder.java
示例4: createAppServlet
import io.dropwizard.jersey.errors.LoggingExceptionMapper; //导入依赖的package包/类
@Override
protected Handler createAppServlet(Server server,
JerseyEnvironment jersey,
ObjectMapper objectMapper,
Validator validator,
MutableServletContextHandler handler,
@Nullable Servlet jerseyContainer,
MetricRegistry metricRegistry) {
if (jerseyContainer != null) {
jersey.register(new LoggingExceptionMapper<Throwable>() {
@Override
public Response toResponse(Throwable exception) {
final int status;
final StatusEntity statusEntity;
if (exception instanceof WebApplicationException) {
final Response response = ((WebApplicationException) exception).getResponse();
if (response.getStatusInfo().getFamily().equals(Response.Status.Family.SERVER_ERROR)) {
logException(exception);
}
status = response.getStatus();
statusEntity = new StatusEntity(status, new StatusMessage(µService.WEB_APPLICATION_ERROR, exception.getLocalizedMessage()));
} else {
final long id = logException(exception);
status = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
StatusMessage message = new StatusMessage(StatusMessage.Type.ERROR, String.format("%016x", id), µService.INTERNAL_SERVER_ERROR, formatErrorMessage(id, exception), null);
statusEntity = new StatusEntity(status, message);
}
return Response.status(status)
.type(MediaType.APPLICATION_JSON_TYPE)
.entity(statusEntity)
.build();
}
});
jersey.register(new ConstraintViolationExceptionMapper());
jersey.register(new JsonProcessingExceptionMapper());
jersey.register(new EarlyEofExceptionMapper());
}
Handler appServlet = super.createAppServlet(server, jersey, objectMapper, validator, handler, jerseyContainer, metricRegistry);
return appServlet;
}
开发者ID:rvs-fluid-it,项目名称:microservice-bundle,代码行数:43,代码来源:µServiceFactory.java
注:本文中的io.dropwizard.jersey.errors.LoggingExceptionMapper类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论