@Override public FullHttpResponse duplicate() { return replace(content().duplicate()); }
@Override public FullHttpResponse copy() { return replace(content().copy()); }
@Override public FullHttpResponse retainedDuplicate() { return replace(content().retainedDuplicate()); }
response.content().writeBytes(buffer); buffer.release();
response.content().writeBytes(buffer); buffer.release();
private FullHttpResponse createResponseByByteBuf(Response response, ByteBuf byteBuf) { Map<String, String> headers = response.headers(); var httpResponse = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(response.statusCode()), byteBuf); httpResponse.headers().set(CONTENT_LENGTH, httpResponse.content().readableBytes()); setDefaultHeaders(httpResponse.headers()); if (response.cookiesRaw().size() > 0) { this.appendCookie(response, httpResponse); } for (Map.Entry<String, String> next : headers.entrySet()) { httpResponse.headers().set(HttpConst.getAsciiString(next.getKey()), next.getValue()); } return httpResponse; }
private FullHttpResponse createResponseByByteBuf(Response response, ByteBuf byteBuf) { Map<String, String> headers = response.headers(); var httpResponse = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(response.statusCode()), byteBuf); httpResponse.headers().set(CONTENT_LENGTH, httpResponse.content().readableBytes()); setDefaultHeaders(httpResponse.headers()); if (response.cookiesRaw().size() > 0) { this.appendCookie(response, httpResponse); } for (Map.Entry<String, String> next : headers.entrySet()) { httpResponse.headers().set(HttpConst.getAsciiString(next.getKey()), next.getValue()); } return httpResponse; }
@Override public int hashCode() { int hash = this.hash; if (hash == 0) { if (content().refCnt() != 0) { try { hash = 31 + content().hashCode(); } catch (IllegalReferenceCountException ignored) { // Handle race condition between checking refCnt() == 0 and using the object. hash = 31; } } else { hash = 31; } hash = 31 * hash + trailingHeaders().hashCode(); hash = 31 * hash + super.hashCode(); this.hash = hash; } return hash; }
final ByteBuf chunk = ((DefaultFullHttpResponse) httpResponse).content(); zuulResponse.bufferBodyContents(new DefaultLastHttpContent(chunk));
final ByteBuf chunk = ((DefaultFullHttpResponse) httpResponse).content(); zuulResponse.bufferBodyContents(new DefaultLastHttpContent(chunk));
public static void sendResponse(ChannelHandlerContext channel, FullHttpRequest request, String messageBody, HttpResponseStatus status, Map<String, String> headers) { DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status); if (headers!=null && !headers.keySet().isEmpty()){ Iterator<String> itr = headers.keySet().iterator(); while(itr.hasNext()){ String headerKey = itr.next(); response.headers().add(headerKey, headers.get(headerKey)); } } final Timer.Context sendResponseTimerContext = sendResponseTimer.time(); try { if (messageBody != null && !messageBody.isEmpty()) { response.content().writeBytes(Unpooled.copiedBuffer(messageBody, Constants.DEFAULT_CHARSET)); } responder.respond(channel, request, response); Tracker.getInstance().trackResponse(request, response); } finally { sendResponseTimerContext.stop(); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { Exception e = cause instanceof Exception ? (Exception) cause : new Exception(cause); final String output = JsonUtil.toJsonString(e); ByteBuf content = Unpooled.wrappedBuffer(output.getBytes(Charsets.UTF_8)); final DefaultFullHttpResponse resp = new DefaultFullHttpResponse( HTTP_1_1, INTERNAL_SERVER_ERROR, content); resp.headers().set(CONTENT_TYPE, APPLICATION_JSON_UTF8); if (e instanceof IllegalArgumentException) { resp.setStatus(BAD_REQUEST); } else if (e instanceof FileNotFoundException) { resp.setStatus(NOT_FOUND); } else if (e instanceof IOException) { resp.setStatus(FORBIDDEN); } resp.headers().set(CONTENT_LENGTH, resp.content().readableBytes()); resp.headers().set(CONNECTION, CLOSE); ctx.write(resp).addListener(ChannelFutureListener.CLOSE); }
.getBytes(Charsets.UTF_8))); resp.headers().set(CONTENT_TYPE, APPLICATION_JSON_UTF8); resp.headers().set(CONTENT_LENGTH, resp.content().readableBytes()); resp.headers().set(CONNECTION, CLOSE); ctx.write(resp).addListener(ChannelFutureListener.CLOSE);
@Override public FullHttpResponse handleRequest(Map<String, String> pathParams, Map<String, String> queryParams, ActorGateway jobManager) throws Exception { String result = handleJsonRequest(pathParams, queryParams, jobManager); byte[] bytes = result.getBytes(ENCODING); DefaultFullHttpResponse response = new DefaultFullHttpResponse( HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(bytes)); response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=" + ENCODING.name()); response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, response.content().readableBytes()); return response; }
@Override public FullHttpResponse copy() { return replace(content().copy()); }
@Override public FullHttpResponse duplicate() { return replace(content().duplicate()); }