Search in sources :

Example 41 with DefaultHttpResponse

use of org.apache.flink.shaded.netty4.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);
}
Also used : HttpHeaders(io.netty.handler.codec.http.HttpHeaders) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse)

Example 42 with DefaultHttpResponse

use of org.apache.flink.shaded.netty4.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);
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse)

Example 43 with DefaultHttpResponse

use of org.apache.flink.shaded.netty4.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));
}
Also used : DFSClient(org.apache.hadoop.hdfs.DFSClient) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) OutputStream(java.io.OutputStream)

Example 44 with DefaultHttpResponse

use of org.apache.flink.shaded.netty4.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);
}
Also used : QueryStringDecoder(io.netty.handler.codec.http.QueryStringDecoder) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse)

Example 45 with DefaultHttpResponse

use of org.apache.flink.shaded.netty4.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;
}
Also used : DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) HttpObject(io.netty.handler.codec.http.HttpObject) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)64 HttpResponse (io.netty.handler.codec.http.HttpResponse)34 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)23 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)18 HttpContent (io.netty.handler.codec.http.HttpContent)14 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)11 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)11 ChannelFuture (io.netty.channel.ChannelFuture)10 HttpRequest (io.netty.handler.codec.http.HttpRequest)10 ByteBuf (io.netty.buffer.ByteBuf)9 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)9 HttpObject (io.netty.handler.codec.http.HttpObject)9 RandomAccessFile (java.io.RandomAccessFile)9 Test (org.junit.Test)9 FileNotFoundException (java.io.FileNotFoundException)7 IOException (java.io.IOException)7 Channel (io.netty.channel.Channel)6 File (java.io.File)6 HttpChunkedInput (io.netty.handler.codec.http.HttpChunkedInput)5 URL (java.net.URL)5