當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。