Search in sources :

Example 1 with HttpResponse

use of com.duangframework.core.common.dto.http.response.HttpResponse 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 2 with HttpResponse

use of com.duangframework.core.common.dto.http.response.HttpResponse in project duangframework by tcrct.

the class MainProcess method doWork.

@Override
public IResponse doWork(IRequest req, IResponse res) throws Exception {
    HttpRequest request = (HttpRequest) req;
    HttpResponse response = (HttpResponse) res;
    if (ToolsKit.isEmpty(request)) {
        throw new EmptyNullException("request is null");
    }
    if (ToolsKit.isEmpty(response)) {
        throw new EmptyNullException("response is null");
    }
    String target = request.getRequestURI().toString();
    AsyncContext asyncContext = new AsyncContextThreadImpl(target, request, response);
    return asyncContext.complete();
// AsyncContext asyncContext = new AsyncContextQueueImpl(target, request, response);
// return asyncContext.complete();
}
Also used : HttpRequest(com.duangframework.core.common.dto.http.request.HttpRequest) EmptyNullException(com.duangframework.core.exceptions.EmptyNullException) HttpResponse(com.duangframework.core.common.dto.http.response.HttpResponse) AsyncContext(com.duangframework.core.common.dto.http.request.AsyncContext)

Aggregations

HttpResponse (com.duangframework.core.common.dto.http.response.HttpResponse)2 AsyncContext (com.duangframework.core.common.dto.http.request.AsyncContext)1 HttpRequest (com.duangframework.core.common.dto.http.request.HttpRequest)1 HeadDto (com.duangframework.core.common.dto.result.HeadDto)1 ReturnDto (com.duangframework.core.common.dto.result.ReturnDto)1 EmptyNullException (com.duangframework.core.exceptions.EmptyNullException)1