Examples of FullHttpResponse


Examples of io.netty.handler.codec.http.FullHttpResponse

        this.producer = producer;
    }

    @Override
    protected Message getResponseMessage(Exchange exchange, ChannelHandlerContext ctx, Object message) throws Exception {
        FullHttpResponse response = (FullHttpResponse) message;
        // use the binding
        return producer.getEndpoint().getNettyHttpBinding().toCamelMessage(response, exchange, producer.getConfiguration());
    }
View Full Code Here

Examples of io.netty.handler.codec.http.FullHttpResponse

        @Override
        public void done(boolean doneSync) {
            try {
                NettyHttpMessage nettyMessage = exchange.hasOut() ? exchange.getOut(NettyHttpMessage.class) : exchange.getIn(NettyHttpMessage.class);
                if (nettyMessage != null) {
                    FullHttpResponse response = nettyMessage.getHttpResponse();
                    // Need to retain the ByteBuffer for producer to consumer
                    // TODO Remove this part of ByteBuffer right away
                    response.content().retain();
                    if (response != null) {
                        // the actual url is stored on the IN message in the getRequestBody method as its accessed on-demand
                        String actualUrl = exchange.getIn().getHeader(Exchange.HTTP_URL, String.class);
                        int code = response.getStatus() != null ? response.getStatus().code() : -1;
                        log.debug("Http responseCode: {}", code);

                        // if there was a http error code (300 or higher) then check if we should throw an exception
                        if (code >= 300 && getConfiguration().isThrowExceptionOnFailure()) {
                            // operation failed so populate exception to throw
View Full Code Here

Examples of io.netty.handler.codec.http.FullHttpResponse

    public static boolean matches(final String path) {
        return path.startsWith("/info");
    }

    public static FullHttpResponse response(final SockJsConfig config, final HttpRequest request) throws Exception {
        final FullHttpResponse response = createResponse(request);
        Transports.setNoCacheHeaders(response);
        Transports.writeContent(response, infoContent(config), "application/json; charset=UTF-8");
        return response;
    }
View Full Code Here

Examples of io.netty.handler.codec.http.FullHttpResponse

        // Hixie 75 does not contain these headers while Hixie 76 does
        boolean isHixie76 = req.headers().contains(SEC_WEBSOCKET_KEY1) && req.headers().contains(SEC_WEBSOCKET_KEY2);

        // Create the WebSocket handshake response.
        FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, new HttpResponseStatus(101,
                isHixie76 ? "WebSocket Protocol Handshake" : "Web Socket Protocol Handshake"));
        if (headers != null) {
            res.headers().add(headers);
        }

        res.headers().add(Names.UPGRADE, WEBSOCKET);
        res.headers().add(CONNECTION, Values.UPGRADE);

        // Fill in the headers and contents depending on handshake getMethod.
        if (isHixie76) {
            // New handshake getMethod with a challenge:
            res.headers().add(SEC_WEBSOCKET_ORIGIN, req.headers().get(ORIGIN));
            res.headers().add(SEC_WEBSOCKET_LOCATION, uri());
            String subprotocols = req.headers().get(SEC_WEBSOCKET_PROTOCOL);
            if (subprotocols != null) {
                String selectedSubprotocol = selectSubprotocol(subprotocols);
                if (selectedSubprotocol == null) {
                    throw new WebSocketHandshakeException("Requested subprotocol(s) not supported: " + subprotocols);
                } else {
                    res.headers().add(SEC_WEBSOCKET_PROTOCOL, selectedSubprotocol);
                }
            }

            // Calculate the answer of the challenge.
            key1 = req.headers().get(SEC_WEBSOCKET_KEY1);
            key2 = req.headers().get(SEC_WEBSOCKET_KEY2);
        } else {
            // Old Hixie 75 handshake getMethod with no challenge:
            res.headers().add(WEBSOCKET_ORIGIN, req.headers().get(ORIGIN));
            res.headers().add(WEBSOCKET_LOCATION, uri());
            String protocol = req.headers().get(WEBSOCKET_PROTOCOL);
            if (protocol != null) {
                res.headers().add(WEBSOCKET_PROTOCOL, selectSubprotocol(protocol));
            }
        }
        return res;
    }
View Full Code Here

Examples of io.netty.handler.codec.http.FullHttpResponse

        return key;
    }

    @Override
    public ChannelFuture handshake(Channel channel, FullHttpRequest req) {
        final FullHttpResponse response = newHandshakeResponse(req, null);
        return channel.writeAndFlush(response).addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                if (future.isSuccess()) {
                    ChannelPipeline p = future.channel().pipeline();
View Full Code Here

Examples of io.netty.handler.codec.http.FullHttpResponse

            throws Exception {
        if (msg instanceof Frame) {
            final Frame frame = (Frame) msg;
            final ByteBuf content = wrapWithFunction(frame.content(), ctx);
            frame.release();
            final FullHttpResponse response = new DefaultFullHttpResponse(request.getProtocolVersion(), OK, content);
            response.headers().set(CONTENT_TYPE, Transports.CONTENT_TYPE_JAVASCRIPT);
            response.headers().set(CONTENT_LENGTH, content.readableBytes());
            response.headers().set(CONNECTION, HttpHeaders.Values.CLOSE);
            Transports.setNoCacheHeaders(response);
            Transports.setSessionIdCookie(response, config, request);
            ctx.writeAndFlush(response, promise);
        } else {
            ctx.write(ReferenceCountUtil.retain(msg), promise);
View Full Code Here

Examples of io.netty.handler.codec.http.FullHttpResponse

    private static void respond(final ChannelHandlerContext ctx,
                                final HttpVersion httpVersion,
                                final HttpResponseStatus status,
                                final String message) throws Exception {
        final FullHttpResponse response = new DefaultFullHttpResponse(httpVersion, status);
        Transports.writeContent(response, message, Transports.CONTENT_TYPE_JAVASCRIPT);
        Transports.writeResponse(ctx, response);
    }
View Full Code Here

Examples of io.netty.handler.codec.http.FullHttpResponse

     *
     * @param version the HttpVersion to be used.
     * @return {@link FullHttpResponse} with the {@link HttpResponseStatus#METHOD_NOT_ALLOWED}.
     */
    public static FullHttpResponse methodNotAllowedResponse(final HttpVersion version) {
        final FullHttpResponse response = responseWithoutContent(version, METHOD_NOT_ALLOWED);
        response.headers().add(ALLOW, GET);
        return response;
    }
View Full Code Here

Examples of io.netty.handler.codec.http.FullHttpResponse

        }
        return path.isEmpty() || "/".equals(path);
    }

    public static FullHttpResponse response(final HttpRequest request) {
        final FullHttpResponse response = new DefaultFullHttpResponse(
                request.getProtocolVersion(),
                OK,
                CONTENT.duplicate());
        response.headers().set(CONTENT_TYPE, Transports.CONTENT_TYPE_PLAIN);
        return response;
    }
View Full Code Here

Examples of io.netty.handler.codec.http.FullHttpResponse

        }
        return session;
    }

    private static void writeNotFoundResponse(final HttpRequest request, final ChannelHandlerContext ctx) {
        final FullHttpResponse response = new DefaultFullHttpResponse(request.getProtocolVersion(), NOT_FOUND,
                Unpooled.copiedBuffer("Not found", CharsetUtil.UTF_8));
        writeResponse(ctx.channel(), request, response);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.