Search in sources :

Example 1 with ByteBufInputStream

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project jersey by jersey.

the class JerseyServerHandler method channelRead.

@Override
public void channelRead(final ChannelHandlerContext ctx, Object msg) {
    if (msg instanceof HttpRequest) {
        final HttpRequest req = (HttpRequest) msg;
        if (HttpUtil.is100ContinueExpected(req)) {
            ctx.write(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE));
        }
        // clearing the content - possible leftover from previous request processing.
        isList.clear();
        final ContainerRequest requestContext = createContainerRequest(ctx, req);
        requestContext.setWriter(new NettyResponseWriter(ctx, req, container));
        // must be like this, since there is a blocking read from Jersey
        container.getExecutorService().execute(new Runnable() {

            @Override
            public void run() {
                container.getApplicationHandler().handle(requestContext);
            }
        });
    }
    if (msg instanceof HttpContent) {
        HttpContent httpContent = (HttpContent) msg;
        ByteBuf content = httpContent.content();
        if (content.isReadable()) {
            isList.add(new ByteBufInputStream(content));
        }
        if (msg instanceof LastHttpContent) {
            isList.add(NettyInputStream.END_OF_INPUT);
        }
    }
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) ByteBuf(io.netty.buffer.ByteBuf) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) HttpContent(io.netty.handler.codec.http.HttpContent)

Example 2 with ByteBufInputStream

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project ratpack by ratpack.

the class DefaultSession method hydrate.

private void hydrate(ByteBuf bytes) throws Exception {
    if (bytes.readableBytes() > 0) {
        SerializedForm deserialized = defaultSerializer.deserialize(SerializedForm.class, new ByteBufInputStream(bytes));
        entries = deserialized.entries;
    } else {
        this.entries = new HashMap<>();
    }
}
Also used : ByteBufInputStream(io.netty.buffer.ByteBufInputStream)

Example 3 with ByteBufInputStream

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project rskj by rsksmart.

the class JsonRpcWeb3ServerHandler method processRequest.

private HttpResponse processRequest(FullHttpRequest request) throws JsonProcessingException {
    HttpResponse response;
    ByteBuf responseContent = Unpooled.buffer();
    HttpResponseStatus responseStatus = HttpResponseStatus.OK;
    try (ByteBufOutputStream os = new ByteBufOutputStream(responseContent);
        ByteBufInputStream is = new ByteBufInputStream(request.content().retain())) {
        int result = jsonRpcServer.handleRequest(is, os);
        responseStatus = HttpResponseStatus.valueOf(DefaultHttpStatusCodeProvider.INSTANCE.getHttpStatusCode(result));
    } catch (Exception e) {
        LOGGER.error("Unexpected error", e);
        responseContent = buildErrorContent(JSON_RPC_SERVER_ERROR_HIGH_CODE, HttpResponseStatus.INTERNAL_SERVER_ERROR.reasonPhrase());
        responseStatus = HttpResponseStatus.INTERNAL_SERVER_ERROR;
    } finally {
        response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, responseStatus, responseContent);
    }
    return response;
}
Also used : ByteBufOutputStream(io.netty.buffer.ByteBufOutputStream) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) ByteBuf(io.netty.buffer.ByteBuf) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 4 with ByteBufInputStream

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project bookkeeper by apache.

the class LedgerEntry method getEntryInputStream.

/**
 * Returns the content of the entry.
 * This method can be called only once. While using v2 wire protocol this method will automatically release
 * the internal ByteBuf when calling the close
 * method of the returned InputStream
 *
 * @return an InputStream which gives access to the content of the entry
 * @throws IllegalStateException if this method is called twice
 */
public InputStream getEntryInputStream() {
    checkState(null != data, "entry content can be accessed only once");
    ByteBufInputStream res = new ByteBufInputStream(data);
    data = null;
    return res;
}
Also used : ByteBufInputStream(io.netty.buffer.ByteBufInputStream)

Example 5 with ByteBufInputStream

use of org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream in project jocean-http by isdom.

the class Nettys method dumpByteBufAsBytes.

public static byte[] dumpByteBufAsBytes(final ByteBuf bytebuf) throws IOException {
    try (final InputStream is = new ByteBufInputStream(bytebuf)) {
        final byte[] bytes = new byte[is.available()];
        is.read(bytes);
        return bytes;
    }
}
Also used : ByteBufInputStream(io.netty.buffer.ByteBufInputStream) InputStream(java.io.InputStream) ByteBufInputStream(io.netty.buffer.ByteBufInputStream)

Aggregations

ByteBufInputStream (io.netty.buffer.ByteBufInputStream)69 ByteBuf (io.netty.buffer.ByteBuf)22 IOException (java.io.IOException)22 InputStreamReader (java.io.InputStreamReader)18 BadRequestException (co.cask.cdap.common.BadRequestException)16 Reader (java.io.Reader)16 JsonSyntaxException (com.google.gson.JsonSyntaxException)11 InputStream (java.io.InputStream)10 Path (javax.ws.rs.Path)9 ObjectInputStream (java.io.ObjectInputStream)8 NamespaceId (co.cask.cdap.proto.id.NamespaceId)6 POST (javax.ws.rs.POST)6 Test (org.junit.jupiter.api.Test)5 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)4 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)4 ByteBufOutputStream (io.netty.buffer.ByteBufOutputStream)4 RpcException (org.apache.drill.exec.rpc.RpcException)4 UnsupportedTypeException (co.cask.cdap.api.data.schema.UnsupportedTypeException)3 DatasetManagementException (co.cask.cdap.api.dataset.DatasetManagementException)3 ObjectOutputStream (java.io.ObjectOutputStream)3