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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations