当前位置: 首页>>代码示例>>Java>>正文


Java FullHttpRequest类代码示例

本文整理汇总了Java中io.netty.handler.codec.http.FullHttpRequest的典型用法代码示例。如果您正苦于以下问题:Java FullHttpRequest类的具体用法?Java FullHttpRequest怎么用?Java FullHttpRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


FullHttpRequest类属于io.netty.handler.codec.http包,在下文中一共展示了FullHttpRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getHttpRequest

import io.netty.handler.codec.http.FullHttpRequest; //导入依赖的package包/类
public FullHttpRequest getHttpRequest() {
  if (h1Request != null) {
    return h1Request;
  }

  if (h2Headers != null) {
    try {
      // Fake out a full HTTP request.
      FullHttpRequest synthesizedRequest =
          HttpConversionUtil.toFullHttpRequest(0, h2Headers, alloc, true);
      if (data != null) {
        synthesizedRequest.replace(data);
      }

      return synthesizedRequest;
    } catch (Http2Exception e) {
      // TODO(JR): Do something more meaningful with this exception
      e.printStackTrace();
    }
  }

  throw new IllegalStateException("Cannot get the http request for an empty XrpcRequest");
}
 
开发者ID:Nordstrom,项目名称:xrpc,代码行数:24,代码来源:XrpcRequest.java

示例2: handleHttpRequest

import io.netty.handler.codec.http.FullHttpRequest; //导入依赖的package包/类
/**
 * 接受http信息
 * @param ctx
 * @param req
 */
private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req) {
    // Handle a bad request.
    if (!req.getDecoderResult().isSuccess()) {
        sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, BAD_REQUEST));
        return;
    }

    // Handshake
    WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
            getWebSocketLocation(req), null, true);
    handshaker = wsFactory.newHandshaker(req);
    if (handshaker == null) {
        WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
    } else {
        handshaker.handshake(ctx.channel(), req);
    }
}
 
开发者ID:ninelook,项目名称:wecard-server,代码行数:23,代码来源:NettyServerHandler.java

示例3: sendHttpResponse

import io.netty.handler.codec.http.FullHttpRequest; //导入依赖的package包/类
/**
 * 返回http信息
 * @param ctx
 * @param req
 * @param res
 */
private static void sendHttpResponse(
        ChannelHandlerContext ctx, FullHttpRequest req, FullHttpResponse res) {
    // Generate an error page if response getStatus code is not OK (200).
    if (res.getStatus().code() != 200) {
        ByteBuf buf = Unpooled.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8);
        res.content().writeBytes(buf);
        buf.release();
        HttpHeaders.setContentLength(res, res.content().readableBytes());
    }

    // Send the response and close the connection if necessary.
    ChannelFuture f = ctx.channel().writeAndFlush(res);
    if (!HttpHeaders.isKeepAlive(req) || res.getStatus().code() != 200) {
        f.addListener(ChannelFutureListener.CLOSE);
    }
}
 
开发者ID:ninelook,项目名称:wecard-server,代码行数:23,代码来源:NettyServerHandler.java

示例4: sendHttpResponse

import io.netty.handler.codec.http.FullHttpRequest; //导入依赖的package包/类
public void sendHttpResponse(ChannelHandlerContext ctx, FullHttpRequest req, FullHttpResponse res) {
   if (res.getStatus().code() != 200) {
      ByteBuf f = Unpooled.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8);
      res.content().clear();
      res.content().writeBytes(f);
      f.release();
   }

   HttpHeaders.setContentLength(res, res.content().readableBytes());
   ChannelFuture f1;
   f1 = ctx.channel().writeAndFlush(res);

   if (!HttpHeaders.isKeepAlive(req) || res.getStatus().code() != 200) {
      f1.addListener(ChannelFutureListener.CLOSE);
   }
}
 
开发者ID:SpreadServe,项目名称:TFWebSock,代码行数:17,代码来源:NettyHttpFileHandler.java

示例5: handleHttpRequest

import io.netty.handler.codec.http.FullHttpRequest; //导入依赖的package包/类
/**
 * HTTP握手反馈
 */
private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest request){
    //判断是否是WebSocket协议
    if (!request.decoderResult().isSuccess() || !"websocket".equals(request.headers().get("Upgrade"))) {
        logger.warn("protobuf don't support WebSocket");
        ctx.channel().close();
        return;
    }
    WebSocketServerHandshakerFactory handshakerFactory = new WebSocketServerHandshakerFactory(
            WEBSOCKET_URL, null, true);
    handshaker = handshakerFactory.newHandshaker(request);
    if (handshaker == null){
        WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
    }else {
        // 动态加入websocket的编解码处理
        handshaker.handshake(ctx.channel(), request);
        // 存储已经连接的Channel
        manager.addChannel(ctx.channel());
    }
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:23,代码来源:UserAuthHandler.java

示例6: channelRead

import io.netty.handler.codec.http.FullHttpRequest; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    LOGGER.info("[Client ({})] => [Server ({})] : {}",
                connectionInfo.getClientAddr(), connectionInfo.getServerAddr(),
                msg);

    if (msg instanceof FullHttpRequest) {
        String streamId = ((HttpRequest) msg).headers().get(
                HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text());
        if (streamId == null) {
            throw new IllegalStateException("No streamId");
        }
        streams.offer(streamId);
    } else if (msg instanceof HttpObject) {
        throw new IllegalStateException("Cannot handle message: " + msg.getClass());
    }

    outboundChannel.writeAndFlush(msg);
}
 
开发者ID:chhsiao90,项目名称:nitmproxy,代码行数:20,代码来源:Http2FrontendHandler.java

示例7: testReleaseOnSendToClosedChannel

import io.netty.handler.codec.http.FullHttpRequest; //导入依赖的package包/类
public void testReleaseOnSendToClosedChannel() {
    final Settings settings = Settings.builder().build();
    final NamedXContentRegistry registry = xContentRegistry();
    try (Netty4HttpServerTransport httpServerTransport =
                 new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, registry, new NullDispatcher())) {
        final FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
        final EmbeddedChannel embeddedChannel = new EmbeddedChannel();
        final Netty4HttpRequest request = new Netty4HttpRequest(registry, httpRequest, embeddedChannel);
        final HttpPipelinedRequest pipelinedRequest = randomBoolean() ? new HttpPipelinedRequest(request.request(), 1) : null;
        final Netty4HttpChannel channel =
                new Netty4HttpChannel(httpServerTransport, request, pipelinedRequest, randomBoolean(), threadPool.getThreadContext());
        final TestResponse response = new TestResponse(bigArrays);
        assertThat(response.content(), instanceOf(Releasable.class));
        embeddedChannel.close();
        channel.sendResponse(response);
        // ESTestCase#after will invoke ensureAllArraysAreReleased which will fail if the response content was not released
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:Netty4HttpChannelTests.java

示例8: executeRequest

import io.netty.handler.codec.http.FullHttpRequest; //导入依赖的package包/类
private FullHttpResponse executeRequest(final Settings settings, final String originValue, final String host) {
    // construct request and send it over the transport layer
    try (Netty4HttpServerTransport httpServerTransport =
                 new Netty4HttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry(),
                         new NullDispatcher())) {
        httpServerTransport.start();
        final FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
        if (originValue != null) {
            httpRequest.headers().add(HttpHeaderNames.ORIGIN, originValue);
        }
        httpRequest.headers().add(HttpHeaderNames.HOST, host);
        final WriteCapturingChannel writeCapturingChannel = new WriteCapturingChannel();
        final Netty4HttpRequest request = new Netty4HttpRequest(xContentRegistry(), httpRequest, writeCapturingChannel);

        Netty4HttpChannel channel =
                new Netty4HttpChannel(httpServerTransport, request, null, randomBoolean(), threadPool.getThreadContext());
        channel.sendResponse(new TestResponse());

        // get the response
        List<Object> writtenObjects = writeCapturingChannel.getWrittenObjects();
        assertThat(writtenObjects.size(), is(1));
        return (FullHttpResponse) writtenObjects.get(0);
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:25,代码来源:Netty4HttpChannelTests.java

示例9: channelRead

import io.netty.handler.codec.http.FullHttpRequest; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof FullHttpRequest) {
        FullHttpRequest request = (FullHttpRequest) msg;
        Object response = null;
        if (staticFilePattern.matcher(request.uri()).find()) {
            super.channelRead(ctx, msg);
            return;
        }
        try {
            response = dispatcher.doDispatcher(request);
        } catch (Exception ex) {
            // TODO: 异常处理
            ex.printStackTrace();
        }
        ObjectMapper om = new ObjectMapper();
        String jsonStr = om.writer().writeValueAsString(response);


        sendResponse(ctx, request, jsonStr);
    }

}
 
开发者ID:ChenXun1989,项目名称:ace,代码行数:24,代码来源:HttpServerInboundHandler.java

示例10: doDispatcher

import io.netty.handler.codec.http.FullHttpRequest; //导入依赖的package包/类
/**
 * 请求分发与处理
 *
 * @param request http协议请求
 * @return 处理结果
 * @throws InvocationTargetException 调用异常
 * @throws IllegalAccessException    参数异常
 */
public Object doDispatcher(FullHttpRequest request) throws InvocationTargetException, IllegalAccessException {
    Object[] args;
    String uri = request.uri();
    if (uri.endsWith("favicon.ico")) {
        return "";
    }

    AceServiceBean aceServiceBean = Context.getAceServiceBean(uri);
    AceHttpMethod aceHttpMethod = AceHttpMethod.getAceHttpMethod(request.method().toString());
    ByteBuf content = request.content();
    //如果要多次解析,请用 request.content().copy()
    QueryStringDecoder decoder = new QueryStringDecoder(uri);
    Map<String, List<String>> requestMap = decoder.parameters();
    Object result = aceServiceBean.exec(uri, aceHttpMethod, requestMap, content == null ? null : content.toString(CharsetUtil.UTF_8));
    String contentType = request.headers().get("Content-Type");
    if (result == null) {
        ApplicationInfo mock = new ApplicationInfo();
        mock.setName("ace");
        mock.setVersion("1.0");
        mock.setDesc(" mock  !!! ");
        result = mock;
    }
    return result;

}
 
开发者ID:ChenXun1989,项目名称:ace,代码行数:34,代码来源:DefaultDispatcher.java

示例11: channelRead0

import io.netty.handler.codec.http.FullHttpRequest; //导入依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req)
		throws Exception {
	if (!req.getDecoderResult().isSuccess()) {
		logger.debug("invalid http request");
		sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1,
				BAD_REQUEST));
		return;
	}

	if (req.getUri().equalsIgnoreCase(this.websocketUri)) {
		logger.debug("it is websocket request");
		ctx.fireChannelRead(req.retain());
		return;
	}

	HttpTransport transport = getTransport(req);
	if (transport == null) {
		sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1,
				BAD_REQUEST));
	} else {
		transport.handleRequest(ctx, req);
	}
}
 
开发者ID:osswangxining,项目名称:mqttserver,代码行数:25,代码来源:HttpRequestHandler.java

示例12: handleRequest

import io.netty.handler.codec.http.FullHttpRequest; //导入依赖的package包/类
@Override
public void handleRequest(ChannelHandlerContext ctx, FullHttpRequest req)
		throws Exception {
	if (req.getUri().contains("/jsonp/connect")) {
		handleConnect(ctx, req);
	} else if (req.getUri().contains("/jsonp/subscribe")) {
		handleSubscrible(ctx, req);
	} else if (req.getUri().contains("/jsonp/waiting")) {
		handleWaitingMsg(ctx, req);
	} else if (req.getUri().contains("/jsonp/unsubscrible")) {
		handleUnsubscrible(ctx, req);
	} else if (req.getUri().contains("/jsonp/publish")) {
		handlePublish(ctx, req);
	} else if (req.getUri().contains("/jsonp/disconnect")) {
		handleDisconnect(ctx, req);
	} else { // invalid request
		sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1,
				BAD_REQUEST));
	}
}
 
开发者ID:osswangxining,项目名称:mqttserver,代码行数:21,代码来源:HttpJsonpTransport.java

示例13: channelRead0

import io.netty.handler.codec.http.FullHttpRequest; //导入依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) {  
    StringUtils.Pair url = HttpUtils.parseUriIntoUrlBaseAndPath(msg.uri());
    HttpRequest request = new HttpRequest();
    if (url.left == null) {
        String requestScheme = provider.isSsl() ? "https" : "http";
        String host = msg.headers().get(HttpUtils.HEADER_HOST);
        request.setUrlBase(requestScheme + "://" + host);
    } else {
        request.setUrlBase(url.left);            
    }                                
    request.setUri(url.right);
    request.setMethod(msg.method().name());
    msg.headers().forEach(h -> request.addHeader(h.getKey(), h.getValue()));
    QueryStringDecoder decoder = new QueryStringDecoder(url.right);                
    decoder.parameters().forEach((k, v) -> request.putParam(k, v));
    HttpContent httpContent = (HttpContent) msg;
    ByteBuf content = httpContent.content();
    if (content.isReadable()) {
        byte[] bytes = new byte[content.readableBytes()];
        content.readBytes(bytes);
        request.setBody(bytes);
    }
    writeResponse(request, ctx);
    ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
}
 
开发者ID:intuit,项目名称:karate,代码行数:27,代码来源:FeatureServerHandler.java

示例14: handleHttpRequest

import io.netty.handler.codec.http.FullHttpRequest; //导入依赖的package包/类
private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest request) {
    if (!request.decoderResult().isSuccess() || !"websocket".equals(request.headers().get("Upgrade"))) {
        logger.warn("protobuf don't support websocket");
        ctx.channel().close();
        return;
    }
    WebSocketServerHandshakerFactory handshakerFactory = new WebSocketServerHandshakerFactory(
            Constants.WEBSOCKET_URL, null, true);
    handshaker = handshakerFactory.newHandshaker(request);
    if (handshaker == null) {
        WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
    } else {
        // 动态加入websocket的编解码处理
        handshaker.handshake(ctx.channel(), request);
        UserInfo userInfo = new UserInfo();
        userInfo.setAddr(NettyUtil.parseChannelRemoteAddr(ctx.channel()));
        // 存储已经连接的Channel
        UserInfoManager.addChannel(ctx.channel());
    }
}
 
开发者ID:beyondfengyu,项目名称:HappyChat,代码行数:21,代码来源:UserAuthHandler.java

示例15: getSessionId

import io.netty.handler.codec.http.FullHttpRequest; //导入依赖的package包/类
public static String getSessionId(FullHttpRequest msg, boolean anonymousAccessAllowed) {
    final StringBuilder buf = new StringBuilder();
    msg.headers().getAll(Names.COOKIE).forEach(h -> {
        ServerCookieDecoder.STRICT.decode(h).forEach(c -> {
            if (c.name().equals(Constants.COOKIE_NAME)) {
                if (buf.length() == 0) {
                    buf.append(c.value());
                }
            }
        });
    });
    String sessionId = buf.toString();
    if (sessionId.length() == 0 && anonymousAccessAllowed) {
        sessionId = NO_AUTHORIZATIONS;
    } else if (sessionId.length() == 0) {
        sessionId = null;
    }
    return sessionId;
}
 
开发者ID:NationalSecurityAgency,项目名称:qonduit,代码行数:20,代码来源:HttpRequestDecoder.java


注:本文中的io.netty.handler.codec.http.FullHttpRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。