private void sendError(final ChannelHandlerContext ctx, final HttpResponseStatus status) { final HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status); setHeader(response, CONTENT_TYPE, "text/plain; charset=UTF-8"); response.setContent(ChannelBuffers.copiedBuffer( "Failure: " + status.toString() + "\r\n", CharsetUtil.UTF_8)); // Close the connection as soon as the error message is sent. ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE); } }
final HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK); response.setStatus(MOVED_PERMANENTLY); setHeader(response, LOCATION, "/fake-stream"); } else { final HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK); setHeader(response, TRANSFER_ENCODING, "chunked"); response.setChunked(true); final Channel ch = e.getChannel();
private void handle(HttpResponse message) throws Exception { State state = getState(State.class); // convert back to netty http response org.jboss.netty.handler.codec.http.HttpResponse nettyResponse = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(message.getStatusCode())); // @todo: copy the headers from the message HttpHeaders.setHeader(nettyResponse,HttpHeaders.Names.CONTENT_TYPE,message.getContentType()); nettyResponse.setContent(ChannelBuffers.wrappedBuffer(message.getContent())); // we don't support keep alive as of yet state.getResponseChannel().write(nettyResponse).addListener(ChannelFutureListener.CLOSE); // need to remove myself getSystem().stop(getSelf()); }
private void handle(HttpResponse message) throws Exception { State state = getState(State.class); // convert back to netty http response org.jboss.netty.handler.codec.http.HttpResponse nettyResponse = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(message.getStatusCode())); // @todo: copy the headers from the message HttpHeaders.setHeader(nettyResponse,HttpHeaders.Names.CONTENT_TYPE,message.getContentType()); nettyResponse.setContent(ChannelBuffers.wrappedBuffer(message.getContent())); // we don't support keep alive as of yet state.getResponseChannel().write(nettyResponse).addListener(ChannelFutureListener.CLOSE); // need to remove myself getSystem().stop(getSelf()); }