コード例 #1
0
ファイル: HttpClientChannel.java プロジェクト: Nacha/xio
  @Override
  protected ChannelFuture writeRequest(@Nullable ByteBuf request) {
    DefaultFullHttpRequest httpRequest;

    if (request == Unpooled.EMPTY_BUFFER || request == null || request.readableBytes() == 0) {
      httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, uri.getPath());
      // httpRequest.headers().add(HttpHeaders.CONTENT_LENGTH, "0");
    } else {
      httpRequest =
          new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri.getPath(), request);
      //      httpRequest.headers().add(HttpHeaders.CONTENT_LENGTH, request.readableBytes());
    }

    if (headerDictionary != null) {
      for (Map.Entry<String, String> entry : headerDictionary.entrySet()) {
        httpRequest.headers().add(entry.getKey(), entry.getValue());
      }
    }

    httpRequest.headers().set(HttpHeaders.CONNECTION, CLOSE);
    //    httpRequest.headers().set(HttpHeaders.ACCEPT_ENCODING, GZIP);

    // TODO(JR): Remove logger before deployment
    // log.debug("\nHTTP Request from XIO:\n" + httpRequest);

    return underlyingNettyChannel.writeAndFlush(httpRequest);
  }
コード例 #2
0
ファイル: RtspClient.java プロジェクト: las1991/rtsp-server
 private HttpRequest buildOptionsRequest(String uri) {
   DefaultFullHttpRequest request =
       new DefaultFullHttpRequest(RtspVersions.RTSP_1_0, RtspMethods.OPTIONS, uri);
   request.headers().set(RtspHeaderNames.CSEQ, "1");
   request.headers().set(RtspHeaderNames.REQUIRE, "implicit-play");
   request.headers().set(RtspHeaderNames.PROXY_REQUIRE, "gzipped-messages");
   return request;
 }
コード例 #3
0
  public void sendDescribe() {
    DefaultFullHttpRequest req =
        new DefaultFullHttpRequest(RtspVersions.RTSP_1_0, RtspMethods.DESCRIBE, rtspStack.getUrl());
    addCSeq(req);
    req.headers().add("Accept", "application/sdp");

    rtspStack.sendRequest(req, rtspStack.getHost(), rtspStack.getPort());
  }
コード例 #4
0
ファイル: RtspClient.java プロジェクト: las1991/rtsp-server
 /**
  * build DESCRIBE request
  *
  * @return
  */
 private HttpRequest buildDescribeRequest(String uri) {
   DefaultFullHttpRequest request =
       new DefaultFullHttpRequest(RtspVersions.RTSP_1_0, RtspMethods.DESCRIBE, uri);
   request.headers().set(RtspHeaderNames.CSEQ, "1");
   request
       .headers()
       .add(RtspHeaderNames.ACCEPT, "application/sdp, application/rtsl, application/mheg");
   return request;
 }
コード例 #5
0
  public void sendPlay() {
    DefaultFullHttpRequest req =
        new DefaultFullHttpRequest(RtspVersions.RTSP_1_0, RtspMethods.PLAY, rtspStack.getUrl());
    addCSeq(req);
    req.headers().add("Session", rtspStack.getSession());
    req.headers().add("Range", "npt=0.000");

    rtspStack.sendRequest(req, rtspStack.getHost(), rtspStack.getPort());
  }
コード例 #6
0
  public void sendTeardown() {
    DefaultFullHttpRequest req =
        new DefaultFullHttpRequest(RtspVersions.RTSP_1_0, RtspMethods.TEARDOWN, rtspStack.getUrl());
    addCSeq(req);

    String session = rtspStack.getSession();
    if (null != session) {
      req.headers().add("Session", session);
    }

    rtspStack.sendRequest(req, rtspStack.getHost(), rtspStack.getPort());
  }
コード例 #7
0
  /** {@inheritDoc} */
  @Override
  public void write(KineticMessage km) throws IOException {

    // interface message
    Message.Builder message = (Builder) km.getMessage();

    // extended message
    ExtendedMessage.Builder extendedMessage = ExtendedMessage.newBuilder();

    // set interface message
    extendedMessage.setInterfaceMessage(message);

    // set optional value
    if (km.getValue() != null) {
      extendedMessage.setValue(ByteString.copyFrom(km.getValue()));
    }

    // get serialized bytes
    byte[] array = extendedMessage.build().toByteArray();

    // Prepare the HTTP request.
    DefaultFullHttpRequest request =
        new DefaultFullHttpRequest(
            HttpVersion.HTTP_1_1, HttpMethod.POST, "/kinetic", Unpooled.copiedBuffer(array));

    request.headers().set(HttpHeaders.Names.HOST, host);

    request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.BINARY);

    request.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);

    request.headers().set(CONNECTION, Values.KEEP_ALIVE);

    request.headers().set(CONTENT_TYPE, "application/octet-stream");

    request.headers().set(HttpHeaders.Names.CONTENT_ENCODING, HttpHeaders.Values.BINARY);

    request.headers().set(HttpHeaders.Names.CONTENT_LENGTH, request.content().readableBytes());

    if (logger.isLoggable(Level.INFO)) {
      logger.info("writing http message, len=" + request.content().readableBytes());
    }

    try {
      this.channel.writeAndFlush(request);
    } finally {
      // request.release();
    }
  }
コード例 #8
0
  /**
   * Transport: RTP/AVP/TCP;interleaved=${rtp}-${rtcp}
   *
   * @param track
   * @param rtp
   * @param rtcp
   */
  public void sendTCPSetup(String track, int rtp, int rtcp) {
    String trackUrl = track;
    if (track.startsWith("rtsp://")) {
      trackUrl = track;
    } else {
      throw new IllegalArgumentException("unsupported track url:" + track);
    }

    DefaultFullHttpRequest req =
        new DefaultFullHttpRequest(RtspVersions.RTSP_1_0, RtspMethods.SETUP, trackUrl);
    addCSeq(req);
    req.headers().add("Transport", "RTP/AVP/TCP;interleaved=" + rtp + "-" + rtcp);

    rtspStack.sendRequest(req, rtspStack.getHost(), rtspStack.getPort());
  }
コード例 #9
0
 private void receiveRequest(String basicAuthHeader) throws Exception {
   request.headers().add(AUTHORIZATION, basicAuthHeader);
   env = new Env(context, request);
   env.getRequest().setPath(request.getUri());
   handler.messageReceived(context, env);
 }
コード例 #10
0
 private void addCSeq(DefaultFullHttpRequest req) {
   req.headers().add("CSeq", cseq.toString());
   cseq.incrementAndGet();
 }