Search in sources :

Example 1 with HeadDto

use of com.duangframework.core.common.dto.result.HeadDto in project duangframework by tcrct.

the class BaseController method returnFailJson.

protected void returnFailJson(int ret, String msg, Object dto) {
    ReturnDto<Object> returnDto = new ReturnDto<Object>();
    HeadDto head = ToolsKit.getThreadLocalDto();
    if (ToolsKit.isEmpty(head)) {
        head = new HeadDto();
        head.setUri(request.getRequestURI());
    }
    head.setMsg(msg);
    head.setRet(ret);
    returnDto.setHead(head);
    returnDto.setData(dto);
    returnJson(returnDto);
}
Also used : HeadDto(com.duangframework.core.common.dto.result.HeadDto) JSONObject(com.alibaba.fastjson.JSONObject) ReturnDto(com.duangframework.core.common.dto.result.ReturnDto)

Example 2 with HeadDto

use of com.duangframework.core.common.dto.result.HeadDto in project duangframework by tcrct.

the class BaseController method returnFailJson.

/**
 * 返回错误信息到客户端
 *
 * @param ex
 *            自定义ServiceException异常
 */
protected void returnFailJson(Exception ex) {
    String message = ex.getMessage();
    int code = IEnums.IENUMS_FAIL_CODE;
    if (ex instanceof ServiceException) {
        ServiceException se = (ServiceException) ex;
        IEnums enums = se.getEnums();
        if (ToolsKit.isEmpty(enums)) {
            code = ToolsKit.isEmpty(se.getCode()) ? IEnums.IENUMS_FAIL_CODE : se.getCode();
            message = ToolsKit.isEmpty(se.getMessage()) ? IEnums.IENUMS_FAIL_MESSAGE : se.getMessage();
        } else {
            code = enums.getCode();
            message = enums.getMessage();
        }
        ToolsKit.console("returnFail:" + se.getStackTrace()[0].getClassName() + "-->" + se.getStackTrace()[0].getMethodName() + "-->" + se.getStackTrace()[0].getLineNumber() + ":" + message + ":" + request.getRequestURI() + ":" + JSON.toJSONString(getAllParams()));
    } else {
        logger.warn(ex.getMessage(), ex);
    }
    ReturnDto<Map<String, Object>> dto = new ReturnDto<Map<String, Object>>();
    HeadDto head = ToolsKit.getThreadLocalDto();
    if (ToolsKit.isEmpty(head)) {
        head = new HeadDto();
        head.setUri(request.getRequestURI());
    }
    head.setRet(code);
    head.setMsg(message);
    dto.setHead(head);
    dto.setData(getAllParams());
    returnJson(dto);
}
Also used : HeadDto(com.duangframework.core.common.dto.result.HeadDto) ServiceException(com.duangframework.core.exceptions.ServiceException) IEnums(com.duangframework.core.common.enums.IEnums) ReturnDto(com.duangframework.core.common.dto.result.ReturnDto) JSONObject(com.alibaba.fastjson.JSONObject)

Example 3 with HeadDto

use of com.duangframework.core.common.dto.result.HeadDto in project duangframework by tcrct.

the class AbstractAsyncContext method buildExceptionResponse.

protected IResponse buildExceptionResponse(String message) {
    HttpResponse httpResponse = new HttpResponse(asyncResponse.getHeaders(), asyncResponse.getCharacterEncoding(), asyncRequest.getContentType());
    ReturnDto<String> returnDto = new ReturnDto<>();
    returnDto.setData(null);
    HeadDto headDto = new HeadDto();
    int index = message.indexOf(":");
    headDto.setMsg((index > -1) ? message.substring(index + 1, message.length()) : message);
    headDto.setRet(1);
    headDto.setUri(asyncRequest.getRequestURI());
    headDto.setTimestamp(System.currentTimeMillis());
    headDto.setRequestId(requestId);
    headDto.setClientId(IpUtils.getLocalHostIP());
    headDto.setMethod(asyncRequest.getMethod());
    returnDto.setHead(headDto);
    httpResponse.write(returnDto);
    httpResponse.setHeader("status", (headDto.getRet() == 0) ? "200" : "500");
    return httpResponse;
}
Also used : HeadDto(com.duangframework.core.common.dto.result.HeadDto) HttpResponse(com.duangframework.core.common.dto.http.response.HttpResponse) ReturnDto(com.duangframework.core.common.dto.result.ReturnDto)

Example 4 with HeadDto

use of com.duangframework.core.common.dto.result.HeadDto in project duangframework by tcrct.

the class ToolsKit method buildReturnDto.

/**
 * @param enums
 * @param obj
 * @return
 */
public static ReturnDto<Object> buildReturnDto(IEnums enums, Object obj) {
    ReturnDto<Object> dto = new ReturnDto<Object>();
    HeadDto head = getThreadLocalDto();
    if (isEmpty(head)) {
        head = new HeadDto();
    }
    if (ToolsKit.isEmpty(enums)) {
        head.setRet(IEnums.IENUMS_SUCCESS_CODE);
        head.setMsg(IEnums.IENUMS_SUCCESS_MESSAGE);
    } else {
        head.setRet(enums.getCode());
        head.setMsg(enums.getMessage());
    }
    dto.setHead(head);
    dto.setData(obj);
    return dto;
}
Also used : HeadDto(com.duangframework.core.common.dto.result.HeadDto) ReturnDto(com.duangframework.core.common.dto.result.ReturnDto)

Example 5 with HeadDto

use of com.duangframework.core.common.dto.result.HeadDto in project duangframework by tcrct.

the class BaseController method returnJson.

public void returnJson(int ret, String msg, Object obj) {
    ReturnDto<Object> dto = new ReturnDto<>();
    HeadDto head = ToolsKit.getThreadLocalDto();
    head.setRet(ret);
    head.setMsg(msg);
    head.setUri(request.getRequestURI());
    dto.setHead(head);
    dto.setData(obj);
    render = new JsonRender(dto);
}
Also used : HeadDto(com.duangframework.core.common.dto.result.HeadDto) JsonRender(com.duangframework.mvc.render.JsonRender) JSONObject(com.alibaba.fastjson.JSONObject) ReturnDto(com.duangframework.core.common.dto.result.ReturnDto)

Aggregations

HeadDto (com.duangframework.core.common.dto.result.HeadDto)7 ReturnDto (com.duangframework.core.common.dto.result.ReturnDto)6 JSONObject (com.alibaba.fastjson.JSONObject)3 HttpResponse (com.duangframework.core.common.dto.http.response.HttpResponse)1 IEnums (com.duangframework.core.common.enums.IEnums)1 ServiceException (com.duangframework.core.exceptions.ServiceException)1 VerificationException (com.duangframework.core.exceptions.VerificationException)1 JsonRender (com.duangframework.mvc.render.JsonRender)1