private void writeResponse(Channel ch, TransportResponse<StreamResponse> response, RestResponse restResponse) { RestResponseBuilder responseBuilder = restResponse.builder() .unsafeOverwriteHeaders(WireAttributeHelper.toWireAttributes(response.getWireAttributes())); ch.writeAndFlush(responseBuilder.build()); }
private void writeError(Channel ch, TransportResponse<StreamResponse> response, Throwable ex) { RestResponseBuilder responseBuilder = new RestResponseBuilder(RestStatus.responseForError(RestStatus.INTERNAL_SERVER_ERROR, ex)) .unsafeOverwriteHeaders(WireAttributeHelper.toWireAttributes(response.getWireAttributes())); ch.writeAndFlush(responseBuilder.build()); }
@Override public void onResponse(TransportResponse<RestResponse> response) { final RestResponseBuilder responseBuilder; if (response.hasError()) { // This onError is only getting called in cases where: // (1) the exception was thrown by the handleRequest() method, and the upper layer // dispatcher did not catch the exception or caught it and passed it here without // turning it into a Response, or // (2) the HttpBridge-installed callback's onError declined to convert the exception to a // response and passed it along to here. responseBuilder = new RestResponseBuilder(RestStatus.responseForError(RestStatus.INTERNAL_SERVER_ERROR, response.getError())); } else { responseBuilder = new RestResponseBuilder(response.getResponse()); } responseBuilder .unsafeOverwriteHeaders(WireAttributeHelper.toWireAttributes(response.getWireAttributes())) .build(); ch.writeAndFlush(responseBuilder.build()); } };