private void renderResponseOrError() { String err = validateResponse(); if (err != null) { doRendering(500, new RespBodyBytes(err.getBytes())); } else { renderResponse(); } }
@Override public void onRequest(Channel channel, RapidoidHelper data) { boolean isKeepAlive = data.isKeepAlive.value; RespBody body = new RespBodyBytes("Not found!".getBytes()); HttpIO.INSTANCE.respond(HttpUtils.noReq(), channel, -1, -1, 404, isKeepAlive, MediaType.PLAIN_TEXT_UTF_8, body, null, null); channel.send().closeIf(!isKeepAlive); } }
static RespBody toRespBody(Req req, RespImpl resp) { try { return createRespBodyFromResult(req, resp); } catch (Throwable e) { HttpIO.INSTANCE.error(req, e, LogLevel.ERROR); try { return createRespBodyFromResult(req, resp); } catch (Exception e1) { Log.error("Internal rendering error!", e1); return new RespBodyBytes(HttpUtils.getErrorMessageAndSetCode(resp, e1).getBytes()); } } }
public static RespBody resultToRespBody(Resp resp, Object result) { if (result instanceof RespBody) return (RespBody) result; byte[] bytes = HttpUtils.responseToBytes(resp.request(), result, resp.contentType(), mediaResponseRenderer(resp)); return new RespBodyBytes(bytes); }
private static RespBody createRespBodyFromResult(Req req, RespImpl resp) { Object result = resp.result(); Object body = resp.body(); if (result instanceof RespBody) { return (RespBody) result; } else if (body instanceof RespBody) { return (RespBody) body; } else if (resp.mvc()) { byte[] bytes = ResponseRenderer.renderMvc((ReqImpl) req, resp); HttpUtils.postProcessResponse(resp); // the response might have been changed, so post-process again return new RespBodyBytes(bytes); } else if (body != null) { return new RespBodyBytes(Msc.toBytes(body)); } else if (result != null) { return resultToRespBody(resp, result); } else { throw U.rte("There's nothing to render!"); } }
private void internalServerError(final Channel channel, final boolean isKeepAlive, final Req req) { MediaType contentType = req != null ? req.contentType() : HttpUtils.getDefaultContentType(); HttpResponseRenderer jsonRenderer = Customization.of(req).jsonResponseRenderer(); RespBody body = new RespBodyBytes(HttpUtils.responseToBytes(req, INTERNAL_SERVER_ERROR, contentType, jsonRenderer)); HttpIO.INSTANCE.respond(HttpUtils.maybe(req), channel, -1, -1, 500, isKeepAlive, contentType, body, null, null); }
private void renderResponseOrError() { String err = validateResponse(); if (err != null) { doRendering(500, new RespBodyBytes(err.getBytes())); } else { renderResponse(); } }
@Override public void onRequest(Channel channel, RapidoidHelper data) { boolean isKeepAlive = data.isKeepAlive.value; RespBody body = new RespBodyBytes("Not found!".getBytes()); HttpIO.INSTANCE.respond(HttpUtils.noReq(), channel, -1, -1, 404, isKeepAlive, MediaType.PLAIN_TEXT_UTF_8, body, null, null); channel.send().closeIf(!isKeepAlive); } }
static RespBody toRespBody(Req req, RespImpl resp) { try { return createRespBodyFromResult(req, resp); } catch (Throwable e) { HttpIO.INSTANCE.error(req, e, LogLevel.ERROR); try { return createRespBodyFromResult(req, resp); } catch (Exception e1) { Log.error("Internal rendering error!", e1); return new RespBodyBytes(HttpUtils.getErrorMessageAndSetCode(resp, e1).getBytes()); } } }
public static RespBody resultToRespBody(Resp resp, Object result) { if (result instanceof RespBody) return (RespBody) result; byte[] bytes = HttpUtils.responseToBytes(resp.request(), result, resp.contentType(), mediaResponseRenderer(resp)); return new RespBodyBytes(bytes); }
private static RespBody createRespBodyFromResult(Req req, RespImpl resp) { Object result = resp.result(); Object body = resp.body(); if (result instanceof RespBody) { return (RespBody) result; } else if (body instanceof RespBody) { return (RespBody) body; } else if (resp.mvc()) { byte[] bytes = ResponseRenderer.renderMvc((ReqImpl) req, resp); HttpUtils.postProcessResponse(resp); // the response might have been changed, so post-process again return new RespBodyBytes(bytes); } else if (body != null) { return new RespBodyBytes(Msc.toBytes(body)); } else if (result != null) { return resultToRespBody(resp, result); } else { throw U.rte("There's nothing to render!"); } }
private void internalServerError(final Channel channel, final boolean isKeepAlive, final Req req) { MediaType contentType = req != null ? req.contentType() : HttpUtils.getDefaultContentType(); HttpResponseRenderer jsonRenderer = Customization.of(req).jsonResponseRenderer(); RespBody body = new RespBodyBytes(HttpUtils.responseToBytes(req, INTERNAL_SERVER_ERROR, contentType, jsonRenderer)); HttpIO.INSTANCE.respond(HttpUtils.maybe(req), channel, -1, -1, 500, isKeepAlive, contentType, body, null, null); }