Search in sources :

Example 1 with DefaultHttpResponse

use of io.netty.handler.codec.http.DefaultHttpResponse in project netty by netty.

the class Http2ServerDowngraderTest method testUpgradeHeaders.

@Test
public void testUpgradeHeaders() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new Http2ServerDowngrader());
    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    assertTrue(ch.writeOutbound(response));
    Http2HeadersFrame headersFrame = ch.readOutbound();
    assertThat(headersFrame.headers().status().toString(), is("200"));
    assertFalse(headersFrame.isEndStream());
    assertThat(ch.readOutbound(), is(nullValue()));
    assertFalse(ch.finish());
}
Also used : DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse) Test(org.junit.Test)

Example 2 with DefaultHttpResponse

use of io.netty.handler.codec.http.DefaultHttpResponse in project hadoop by apache.

the class RestCsrfPreventionFilterHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    LOG.error("Exception in " + this.getClass().getSimpleName(), cause);
    sendResponseAndClose(ctx, new DefaultHttpResponse(HTTP_1_1, INTERNAL_SERVER_ERROR));
}
Also used : DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse)

Example 3 with DefaultHttpResponse

use of io.netty.handler.codec.http.DefaultHttpResponse in project hadoop by apache.

the class HdfsWriter method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    releaseDfsResources();
    DefaultHttpResponse resp = ExceptionHandler.exceptionCaught(cause);
    resp.headers().set(CONNECTION, CLOSE);
    ctx.writeAndFlush(resp).addListener(ChannelFutureListener.CLOSE);
    if (LOG != null && LOG.isDebugEnabled()) {
        LOG.debug("Exception in channel handler ", cause);
    }
}
Also used : DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse)

Example 4 with DefaultHttpResponse

use of io.netty.handler.codec.http.DefaultHttpResponse in project hadoop by apache.

the class WebHdfsHandler method onCreate.

private void onCreate(ChannelHandlerContext ctx) throws IOException, URISyntaxException {
    writeContinueHeader(ctx);
    final String nnId = params.namenodeId();
    final int bufferSize = params.bufferSize();
    final short replication = params.replication();
    final long blockSize = params.blockSize();
    final FsPermission unmaskedPermission = params.unmaskedPermission();
    final FsPermission permission = unmaskedPermission == null ? params.permission() : FsCreateModes.create(params.permission(), unmaskedPermission);
    final boolean createParent = params.createParent();
    EnumSet<CreateFlag> flags = params.createFlag();
    if (flags.equals(EMPTY_CREATE_FLAG)) {
        flags = params.overwrite() ? EnumSet.of(CreateFlag.CREATE, CreateFlag.OVERWRITE) : EnumSet.of(CreateFlag.CREATE);
    } else {
        if (params.overwrite()) {
            flags.add(CreateFlag.OVERWRITE);
        }
    }
    final DFSClient dfsClient = newDfsClient(nnId, confForCreate);
    OutputStream out = dfsClient.createWrappedOutputStream(dfsClient.create(path, permission, flags, createParent, replication, blockSize, null, bufferSize, null), null);
    resp = new DefaultHttpResponse(HTTP_1_1, CREATED);
    final URI uri = new URI(HDFS_URI_SCHEME, nnId, path, null, null);
    resp.headers().set(LOCATION, uri.toString());
    resp.headers().set(CONTENT_LENGTH, 0);
    resp.headers().set(ACCESS_CONTROL_ALLOW_ORIGIN, "*");
    ctx.pipeline().replace(this, HdfsWriter.class.getSimpleName(), new HdfsWriter(dfsClient, out, resp));
}
Also used : CreateFlag(org.apache.hadoop.fs.CreateFlag) DFSClient(org.apache.hadoop.hdfs.DFSClient) OutputStream(java.io.OutputStream) URI(java.net.URI) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) FsPermission(org.apache.hadoop.fs.permission.FsPermission)

Example 5 with DefaultHttpResponse

use of io.netty.handler.codec.http.DefaultHttpResponse in project netty-socketio by mrniko.

the class PollingTransport method sendError.

private void sendError(ChannelHandlerContext ctx) {
    HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
    ctx.channel().writeAndFlush(res).addListener(ChannelFutureListener.CLOSE);
}
Also used : DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpResponse(io.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(io.netty.handler.codec.http.HttpResponse)

Aggregations

DefaultHttpResponse (io.netty.handler.codec.http.DefaultHttpResponse)63 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 ChannelFuture (io.netty.channel.ChannelFuture)10 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)10 HttpRequest (io.netty.handler.codec.http.HttpRequest)10 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)10 HttpObject (io.netty.handler.codec.http.HttpObject)9 RandomAccessFile (java.io.RandomAccessFile)9 Test (org.junit.Test)9 ByteBuf (io.netty.buffer.ByteBuf)8 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)8 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