use of io.netty.handler.codec.http.DefaultHttpResponse in project hadoop by apache.
the class WebHdfsHandler method allowCORSOnCreate.
//Accept preflighted CORS requests
private void allowCORSOnCreate(ChannelHandlerContext ctx) throws IOException, URISyntaxException {
resp = new DefaultHttpResponse(HTTP_1_1, OK);
HttpHeaders headers = resp.headers();
headers.set(ACCESS_CONTROL_ALLOW_ORIGIN, "*");
headers.set(ACCESS_CONTROL_ALLOW_HEADERS, ACCEPT);
headers.set(ACCESS_CONTROL_ALLOW_METHODS, PUT);
headers.set(ACCESS_CONTROL_MAX_AGE, 1728000);
headers.set(CONTENT_LENGTH, 0);
headers.set(CONNECTION, KEEP_ALIVE);
ctx.writeAndFlush(resp).addListener(ChannelFutureListener.CLOSE);
}
use of io.netty.handler.codec.http.DefaultHttpResponse in project hadoop by apache.
the class WebHdfsHandler method writeContinueHeader.
private static void writeContinueHeader(ChannelHandlerContext ctx) {
DefaultHttpResponse r = new DefaultFullHttpResponse(HTTP_1_1, CONTINUE, Unpooled.EMPTY_BUFFER);
ctx.writeAndFlush(r);
}
use of io.netty.handler.codec.http.DefaultHttpResponse in project hadoop by apache.
the class WebHdfsHandler method onAppend.
private void onAppend(ChannelHandlerContext ctx) throws IOException {
writeContinueHeader(ctx);
final String nnId = params.namenodeId();
final int bufferSize = params.bufferSize();
DFSClient dfsClient = newDfsClient(nnId, conf);
OutputStream out = dfsClient.append(path, bufferSize, EnumSet.of(CreateFlag.APPEND), null, null);
resp = new DefaultHttpResponse(HTTP_1_1, OK);
resp.headers().set(CONTENT_LENGTH, 0);
ctx.pipeline().replace(this, HdfsWriter.class.getSimpleName(), new HdfsWriter(dfsClient, out, resp));
}
use of io.netty.handler.codec.http.DefaultHttpResponse in project hadoop by apache.
the class FSImageHandler method channelRead0.
@Override
public void channelRead0(ChannelHandlerContext ctx, HttpRequest request) throws Exception {
if (request.getMethod() != HttpMethod.GET) {
DefaultHttpResponse resp = new DefaultHttpResponse(HTTP_1_1, METHOD_NOT_ALLOWED);
resp.headers().set(CONNECTION, CLOSE);
ctx.write(resp).addListener(ChannelFutureListener.CLOSE);
return;
}
QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
final String op = getOp(decoder);
final String content;
String path = getPath(decoder);
switch(op) {
case "GETFILESTATUS":
content = image.getFileStatus(path);
break;
case "LISTSTATUS":
content = image.listStatus(path);
break;
case "GETACLSTATUS":
content = image.getAclStatus(path);
break;
case "GETXATTRS":
List<String> names = getXattrNames(decoder);
String encoder = getEncoder(decoder);
content = image.getXAttrs(path, names, encoder);
break;
case "LISTXATTRS":
content = image.listXAttrs(path);
break;
case "GETCONTENTSUMMARY":
content = image.getContentSummary(path);
break;
default:
throw new IllegalArgumentException("Invalid value for webhdfs parameter" + " \"op\"");
}
LOG.info("op=" + op + " target=" + path);
DefaultFullHttpResponse resp = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(content.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);
}
use of io.netty.handler.codec.http.DefaultHttpResponse in project riposte by Nike-Inc.
the class ResponseSender method createActualResponseObjectForFirstChunk.
protected HttpResponse createActualResponseObjectForFirstChunk(ResponseInfo<?> responseInfo, ObjectMapper serializer, ChannelHandlerContext ctx) {
HttpResponse actualResponseObject;
HttpResponseStatus httpStatus = HttpResponseStatus.valueOf(responseInfo.getHttpStatusCodeWithDefault(DEFAULT_HTTP_STATUS_CODE));
determineAndSetCharsetAndMimeTypeForResponseInfoIfNecessary(responseInfo);
if (responseInfo.isChunkedResponse()) {
// Chunked response. No content (yet).
actualResponseObject = new DefaultHttpResponse(HTTP_1_1, httpStatus);
} else {
// Full response. There may or may not be content.
if (responseInfo.getContentForFullResponse() == null) {
// No content, so create a simple full response.
actualResponseObject = new DefaultFullHttpResponse(HTTP_1_1, httpStatus);
} else {
// There is content. If it's a raw byte buffer then use it as-is. Otherwise serialize it to a string
// using the provided serializer.
Object content = responseInfo.getContentForFullResponse();
ByteBuf bytesForResponse;
if (content instanceof byte[])
bytesForResponse = Unpooled.wrappedBuffer((byte[]) content);
else {
bytesForResponse = Unpooled.copiedBuffer(serializeOutput(responseInfo.getContentForFullResponse(), serializer, responseInfo, ctx), responseInfo.getDesiredContentWriterEncoding());
}
// Turn the serialized string to bytes for the response content, create the full response with content,
// and set the content type header.
actualResponseObject = new DefaultFullHttpResponse(HTTP_1_1, httpStatus, bytesForResponse);
}
}
return actualResponseObject;
}
Aggregations