Package org.glassfish.grizzly.http

Examples of org.glassfish.grizzly.http.HttpContent


            if (logger.isDebugEnabled()) {
                logger.debug("REQUEST: {}", requestPacket);
            }
            isWriteComplete = bodyHandler.doHandle(ctx, request, requestPacket);
        } else {
            HttpContent content = HttpContent.builder(requestPacket).last(true).build();
            if (logger.isDebugEnabled()) {
                logger.debug("REQUEST: {}", requestPacket);
            }
            ctx.write(content, ctx.getTransportContext().getCompletionHandler());
        }
View Full Code Here


    }

    @SuppressWarnings({ "unchecked" })
    public boolean doHandle(final FilterChainContext ctx, final Request request, final HttpRequestPacket requestPacket) throws IOException {

        final HttpContent content = requestPacket.httpContentBuilder().content(Buffers.EMPTY_BUFFER).build();
        content.setLast(true);
        ctx.write(content, ((!requestPacket.isCommitted()) ? ctx.getTransportContext().getCompletionHandler() : null));
        return true;
    }
View Full Code Here

        }
        if (sb != null) {
            final byte[] data = sb.toString().getBytes(charset);
            final MemoryManager mm = ctx.getMemoryManager();
            final Buffer gBuffer = Buffers.wrap(mm, data);
            final HttpContent content = requestPacket.httpContentBuilder()
                    .content(gBuffer)
                    .last(true)
                    .build();
            if (requestPacket.getContentLength() == -1) {
                requestPacket.setContentLengthLong(data.length);
View Full Code Here

                    if (b != Buffers.EMPTY_BUFFER) {
                        written.addAndGet(read);
                        b = Buffers.wrap(mm, buf, 0, read);
                    }

                    final HttpContent content = requestPacket.httpContentBuilder().content(b).last(last).build();
                    ctx.write(content, ((!requestPacket.isCommitted()) ? ctx.getTransportContext().getCompletionHandler() : null));
                }
            } finally {
                try {
                    fis.close();
View Full Code Here

        final MemoryManager mm = ctx.getMemoryManager();
        final Buffer gBuffer = Buffers.wrap(mm, data);
        if (requestPacket.getContentLength() == -1) {
            requestPacket.setContentLengthLong(data.length);
        }
        final HttpContent content = requestPacket.httpContentBuilder()
                .content(gBuffer)
                .last(true)
                .build();
        ctx.write(content, ((!requestPacket.isCommitted()) ? ctx.getTransportContext().getCompletionHandler() : null));
        return true;
View Full Code Here

        final MemoryManager mm = ctx.getMemoryManager();
        final Buffer gBuffer = Buffers.wrap(mm, data);
        if (requestPacket.getContentLength() == -1) {
            requestPacket.setContentLengthLong(data.length);
        }
        final HttpContent content = requestPacket.httpContentBuilder()
                .content(gBuffer)
                .last(true)
                .build();
        ctx.write(content, ((!requestPacket.isCommitted()) ? ctx.getTransportContext().getCompletionHandler() : null));
        return true;
View Full Code Here

                        throw new IllegalStateException("BodyGenerator unexpectedly returned 0 bytes available");
                    }
                }
            }

            final HttpContent content = requestPacket.httpContentBuilder().content(buffer).last(last).build();
            ctx.write(content, ((!requestPacket.isCommitted()) ? ctx.getTransportContext().getCompletionHandler() : null));
        }

        return true;
    }
View Full Code Here

            }
            if (!feedableBodyGenerator.asyncTransferInitiated) {
                throw new IllegalStateException("Asynchronous transfer has not been initiated.");
            }
            blockUntilQueueFree(feedableBodyGenerator.context);
            final HttpContent content = feedableBodyGenerator.contentBuilder.content(buffer).last(last).build();
            final CompletionHandler<WriteResult> handler = ((last) ? new LastPacketCompletionHandler() : null);
            feedableBodyGenerator.context.write(content, handler);
        }
View Full Code Here

     */
    @Override
    @SuppressWarnings("unchecked")
    public NextAction handleRead(FilterChainContext ctx) throws IOException {
        // Get the parsed HttpContent (we assume prev. filter was HTTP)
        final HttpContent message = ctx.getMessage();

        final org.glassfish.tyrus.spi.Connection tyrusConnection = getConnection(ctx);

        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, "handleRead websocket: {0} content-size={1} headers=\n{2}",
                    new Object[]{tyrusConnection, message.getContent().remaining(), message.getHttpHeader()});
        }

        if (tyrusConnection == null) {
            // Get the HTTP header
            final HttpHeader header = message.getHttpHeader();

            // If websocket is null - it means either non-websocket Connection
            if (!UpgradeRequest.WEBSOCKET.equalsIgnoreCase(header.getUpgrade()) && message.getHttpHeader().isRequest()) {
                // if it's not a websocket connection - pass the processing to the next filter
                return ctx.getInvokeAction();
            }

            final String ATTR_NAME = "org.glassfish.tyrus.container.grizzly.WebSocketFilter.HANDSHAKE_PROCESSED";

            final AttributeHolder attributeHolder = ctx.getAttributes();
            if (attributeHolder != null) {
                final Object attribute = attributeHolder.getAttribute(ATTR_NAME);
                if (attribute != null) {
                    // handshake was already performed on this context.
                    return ctx.getInvokeAction();
                } else {
                    attributeHolder.setAttribute(ATTR_NAME, true);
                }
            }
            // Handle handshake
            return handleHandshake(ctx, message);
        }

        // tyrusConnection is not null
        // this is websocket with the completed handshake
        if (message.getContent().hasRemaining()) {
            // get the frame(s) content

            Buffer buffer = message.getContent();
            message.recycle();
            final ReadHandler readHandler = tyrusConnection.getReadHandler();
            if (!buffer.isComposite()) {
                taskQueue.add(new ProcessTask(buffer.toByteBuffer(), readHandler));
            } else {
                final ByteBufferArray byteBufferArray = buffer.toByteBufferArray();
View Full Code Here

     */
    @Override
    @SuppressWarnings("unchecked")
    public NextAction handleRead(FilterChainContext ctx) throws IOException {
        // Get the parsed HttpContent (we assume prev. filter was HTTP)
        final HttpContent message = ctx.getMessage();

        final org.glassfish.tyrus.spi.Connection tyrusConnection = getConnection(ctx);

        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, "handleRead websocket: {0} content-size={1} headers=\n{2}",
                    new Object[]{tyrusConnection, message.getContent().remaining(), message.getHttpHeader()});
        }

        if (tyrusConnection == null) {
            // Get the HTTP header
            final HttpHeader header = message.getHttpHeader();

            // If websocket is null - it means either non-websocket Connection
            if (!UpgradeRequest.WEBSOCKET.equalsIgnoreCase(header.getUpgrade()) && message.getHttpHeader().isRequest()) {
                // if it's not a websocket connection - pass the processing to the next filter
                return ctx.getInvokeAction();
            }

            final String ATTR_NAME = "org.glassfish.tyrus.container.grizzly.WebSocketFilter.HANDSHAKE_PROCESSED";

            final AttributeHolder attributeHolder = ctx.getAttributes();
            if (attributeHolder != null) {
                final Object attribute = attributeHolder.getAttribute(ATTR_NAME);
                if (attribute != null) {
                    // handshake was already performed on this context.
                    return ctx.getInvokeAction();
                } else {
                    attributeHolder.setAttribute(ATTR_NAME, true);
                }
            }
            // Handle handshake
            return handleHandshake(ctx, message);
        }

        // tyrusConnection is not null
        // this is websocket with the completed handshake
        if (message.getContent().hasRemaining()) {
            // get the frame(s) content

            Buffer buffer = message.getContent();
            message.recycle();
            final ReadHandler readHandler = tyrusConnection.getReadHandler();
            if (!buffer.isComposite()) {
                taskQueue.add(new ProcessTask(buffer.toByteBuffer(), readHandler));
            } else {
                final ByteBufferArray byteBufferArray = buffer.toByteBufferArray();
View Full Code Here

TOP

Related Classes of org.glassfish.grizzly.http.HttpContent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.