@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); }
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; }
/** * 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; }
public void sendDescribe(String auth) { DefaultFullHttpRequest req = new DefaultFullHttpRequest(RtspVersions.RTSP_1_0, RtspMethods.DESCRIBE, rtspStack.getUrl()); addCSeq(req); req.headers().add("Accept", "application/sdp"); if (null != auth) { req.headers().add("Authorization", auth); } rtspStack.sendRequest(req, rtspStack.getHost(), rtspStack.getPort()); }
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()); }
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()); }
/** * 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()); }
/** {@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(); } }
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); }
private void addCSeq(DefaultFullHttpRequest req) { req.headers().add("CSeq", cseq.toString()); cseq.incrementAndGet(); }