当前位置: 首页>>代码示例>>Java>>正文


Java ExceptionMapperUtils类代码示例

本文整理汇总了Java中ameba.message.error.ExceptionMapperUtils的典型用法代码示例。如果您正苦于以下问题:Java ExceptionMapperUtils类的具体用法?Java ExceptionMapperUtils怎么用?Java ExceptionMapperUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExceptionMapperUtils类属于ameba.message.error包,在下文中一共展示了ExceptionMapperUtils类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: toResponse

import ameba.message.error.ExceptionMapperUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Response toResponse(final ConstraintViolationException exception) {
    logger.trace(LocalizationMessages.CONSTRAINT_VIOLATIONS_ENCOUNTERED(), exception);
    Response.Status status = ValidationHelper.getResponseStatus(exception);
    ErrorMessage errorMessage = ErrorMessage.fromStatus(status.getStatusCode());
    errorMessage.setThrowable(exception);
    errorMessage.setCode(Hashing.murmur3_32().hashUnencodedChars(exception.getClass().getName()).toString());

    List<Result.Error> errors = ValidationHelper.constraintViolationToValidationErrors(exception);

    errorMessage.setErrors(errors);

    return Response.status(status)
            .entity(errorMessage)
            .type(ExceptionMapperUtils.getResponseType())
            .build();
}
 
开发者ID:icode,项目名称:ameba,代码行数:21,代码来源:ValidationExceptionMapper.java

示例2: toResponse

import ameba.message.error.ExceptionMapperUtils; //导入依赖的package包/类
@Override
public Response toResponse(ShiroException exception) {

    Response.Status status;

    if (exception instanceof UnauthorizedException) {
        status = Response.Status.UNAUTHORIZED;
    } else {
        status = Response.Status.FORBIDDEN;
    }
    ErrorMessage error = ErrorMessage.fromStatus(status.getStatusCode());
    error.setCode(Hashing.murmur3_32().hashUnencodedChars(exception.getClass().getName()).toString());

    return Response.status(status)
            .type(ExceptionMapperUtils.getResponseType())
            .entity(error)
            .build();
}
 
开发者ID:icode,项目名称:ameba-shiro,代码行数:19,代码来源:ShiroExceptionMapper.java

示例3: toResponse

import ameba.message.error.ExceptionMapperUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Response toResponse(PersistenceException exception) {
    logger.error("Executing SQL error", exception);

    ErrorMessage errorMessage = ErrorMessage.fromStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    errorMessage.setThrowable(exception);
    errorMessage.setCode(Hashing.murmur3_32().hashUnencodedChars(exception.getClass().getName()).toString());

    boolean isDev = mode.isDev();
    List<ErrorMessage.Error> errors = Lists.newArrayList();

    errors.add(new Result.Error(
            errorMessage.getCode(),
            exception.getMessage(),
            null,
            isDev ? ErrorMessage.parseSource(resourceInfo) : null
    ));

    if (isDev) {
        errors.addAll(ErrorMessage.parseErrors(exception, errorMessage.getStatus()));
    }
    errorMessage.setErrors(errors);

    return Response.status(errorMessage.getStatus())
            .entity(errorMessage)
            .type(ExceptionMapperUtils.getResponseType())
            .build();
}
 
开发者ID:icode,项目名称:ameba,代码行数:32,代码来源:PersistenceExceptionMapper.java

示例4: toResponse

import ameba.message.error.ExceptionMapperUtils; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Response toResponse(JsonProcessingException exception) {
    Throwable throwable = exception;
    while (throwable != null) {
        if (throwable instanceof PersistenceException) {
            return exceptionMappers.get().findMapping(throwable).toResponse(throwable);
        }
        throwable = throwable.getCause();
    }

    logger.debug("Json Processing error", exception);
    String message = exception.getOriginalMessage();
    String desc = null;
    String source = null;
    if (mode.isDev()) {
        desc = IOUtils.getStackTrace(exception);
        JsonLocation location = exception.getLocation();
        if (location != null) {
            source = "line: " + location.getLineNr() +
                    ", column: " + location.getColumnNr();
        } else {
            source = exception.getStackTrace()[0].toString();
        }
    }

    ErrorMessage errorMessage = ErrorMessage.fromStatus(Response.Status.BAD_REQUEST.getStatusCode());
    errorMessage.setThrowable(exception);
    errorMessage.setCode(Hashing.murmur3_32().hashUnencodedChars(exception.getClass().getName()).toString());

    errorMessage.addError(new Result.Error(
            errorMessage.getCode(),
            message != null ? message : exception.getMessage(),
            desc,
            source
    ));

    return Response.status(errorMessage.getStatus())
            .entity(errorMessage)
            .type(ExceptionMapperUtils.getResponseType())
            .build();
}
 
开发者ID:icode,项目名称:ameba,代码行数:45,代码来源:JsonProcessingExceptionMapper.java

示例5: onReceive

import ameba.message.error.ExceptionMapperUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void onReceive(RequestEvent requestEvent) {
    Reload reload = null;
    ClassLoader cl = app.getClassLoader();
    ReloadClassLoader _classLoader = null;
    if (cl instanceof ReloadClassLoader)
        _classLoader = (ReloadClassLoader) cl;
    try {
        switch (requestEvent.getType()) {
            case START:
                if (RELOADING.get() || _classLoader == null) {
                    reloadPage(requestEvent);
                } else {
                    reload = scanChanges();
                }
                if (reload != null && reload.needReload) {
                    if (reload.classes != null && reload.classes.size() > 0) {
                        reloadThreadLocal.set(reload);
                        reloadPage(requestEvent);
                    }
                }
                break;
            case FINISHED:
                if (RELOADING.get() || _classLoader == null) {
                    Thread.sleep(500);
                    flushResponse(requestEvent);
                } else {
                    reload = reloadThreadLocal.get();
                    if (reload != null) {
                        RELOADING.set(true);
                        flushResponse(requestEvent);
                        reload(reload.classes, _classLoader);
                    }
                }
                break;
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);

        ErrorMessage errorMessage = ErrorMessage.fromStatus(500);
        errorMessage.setThrowable(e);
        errorMessage.setCode(Hashing.murmur3_32().hashUnencodedChars(e.getClass().getName()).toString());
        errorMessage.setErrors(ErrorMessage.parseErrors(e, errorMessage.getStatus()));

        requestEvent.getContainerRequest()
                .abortWith(
                        Response.serverError()
                                .entity(errorMessage)
                                .type(ExceptionMapperUtils.getResponseType(requestEvent.getContainerRequest()))
                                .build()
                );
    }
}
 
开发者ID:icode,项目名称:ameba-dev,代码行数:55,代码来源:ReloadRequestListener.java


注:本文中的ameba.message.error.ExceptionMapperUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。