Java Code Examples for org.jboss.netty.handler.codec.http.DefaultHttpResponse

The following are top voted examples for showing how to use org.jboss.netty.handler.codec.http.DefaultHttpResponse. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: traccar-service   File: PathAwayProtocolDecoder.java   Source Code and License 6 votes vote down vote up
@Override
protected Object decode(
        Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {

    HttpRequest request = (HttpRequest) msg;
    QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());

    DeviceSession deviceSession = getDeviceSession(
            channel, remoteAddress, decoder.getParameters().get("UserName").get(0));
    if (deviceSession == null) {
        return null;
    }

    Parser parser = new Parser(PATTERN, decoder.getParameters().get("LOC").get(0));
    if (!parser.matches()) {
        return null;
    }

    Position position = new Position();
    position.setProtocol(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());

    position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));

    position.setValid(true);
    position.setLatitude(parser.nextDouble(0));
    position.setLongitude(parser.nextDouble(0));
    position.setAltitude(parser.nextDouble(0));
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));

    if (channel != null) {
        HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
        channel.write(response).addListener(ChannelFutureListener.CLOSE);
    }

    return position;
}
 
Example 2
Project: hadoop   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);

  Credentials creds = new Credentials();
  creds.addToken(new Text(serviceUrl), token);
  DataOutputBuffer out = new DataOutputBuffer();
  creds.write(out);
  int fileLength = out.getData().length;
  ChannelBuffer cbuffer = ChannelBuffers.buffer(fileLength);
  cbuffer.writeBytes(out.getData());
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
      String.valueOf(fileLength));
  response.setContent(cbuffer);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 3
Project: big-c   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);

  Credentials creds = new Credentials();
  creds.addToken(new Text(serviceUrl), token);
  DataOutputBuffer out = new DataOutputBuffer();
  creds.write(out);
  int fileLength = out.getData().length;
  ChannelBuffer cbuffer = ChannelBuffers.buffer(fileLength);
  cbuffer.writeBytes(out.getData());
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
      String.valueOf(fileLength));
  response.setContent(cbuffer);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 4
Project: opentsdb-flume   File: LegacyHttpSource.java   Source Code and License 6 votes vote down vote up
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
  try {
    final HttpRequest req = (HttpRequest) e.getMessage();
    if (req.getMethod().equals(HttpMethod.POST)) {
      doPost(ctx, e, req);
    } else if (req.getMethod().equals(HttpMethod.GET)) {
      doGet(ctx, e, req);
    } else {
      writeResponseAndClose(e, new DefaultHttpResponse(
              HttpVersion.HTTP_1_1,
              HttpResponseStatus.BAD_REQUEST));
    }
  } catch (Exception ex) {
    if (logger.isDebugEnabled())
      logger.debug("Failed to process message", ex);
    HttpResponse response = new DefaultHttpResponse(
            HttpVersion.HTTP_1_1,
            HttpResponseStatus.INTERNAL_SERVER_ERROR);
    response.setContent(
            ChannelBuffers.copiedBuffer(ex.getMessage().getBytes()));
    writeResponseAndClose(e, response);
  }
}
 
Example 5
Project: opentsdb-flume   File: LegacyHttpSource.java   Source Code and License 6 votes vote down vote up
private void doPost(ChannelHandlerContext ctx, MessageEvent e, HttpRequest req)
        throws IOException {

  final QueryStringDecoder decoded = new QueryStringDecoder(req.getUri());
  if (!decoded.getPath().equalsIgnoreCase("/write")) {
    writeResponseAndClose(e,
            new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND));
    return;
  }

  try {
    metricParser.parse(req);
  } catch (IllegalArgumentException iae) {
    logger.warn("Metric parser failed: " + iae.getMessage());
  }

  HttpResponse response = new DefaultHttpResponse(
          HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
  response.setContent(ChannelBuffers.copiedBuffer(
          ("Seen events").getBytes()
  ));
  writeResponseAndClose(e, response);
}
 
Example 6
Project: Camel   File: HttpServerMultiplexChannelHandler.java   Source Code and License 6 votes vote down vote up
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent messageEvent) throws Exception {
    // store request, as this channel handler is created per pipeline
    HttpRequest request = (HttpRequest) messageEvent.getMessage();

    LOG.debug("Message received: {}", request);

    HttpServerChannelHandler handler = getHandler(request);
    if (handler != null) {
        // store handler as attachment
        ctx.setAttachment(handler);
        handler.messageReceived(ctx, messageEvent);
    } else {
        // this resource is not found, so send empty response back
        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
        response.headers().set(Exchange.CONTENT_TYPE, "text/plain");
        response.headers().set(Exchange.CONTENT_LENGTH, 0);
        response.setContent(ChannelBuffers.copiedBuffer(new byte[]{}));
        messageEvent.getChannel().write(response).syncUninterruptibly();
        // close the channel after send error message
        messageEvent.getChannel().close();
    }
}
 
Example 7
Project: Camel   File: NettyUseRawHttpResponseTest.java   Source Code and License 6 votes vote down vote up
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
    return new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("netty-http:http://0.0.0.0:{{port}}/foo")
                .to("mock:input")
                .process(new Processor() {
                    @Override
                    public void process(Exchange exchange) throws Exception {
                        HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
                        response.setContent(ChannelBuffers.copiedBuffer("Bye World".getBytes()));
                        response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, 9);

                        exchange.getOut().setBody(response);
                    }
                });
        }
    };
}
 
Example 8
Project: hadoop-2.6.0-cdh5.4.3   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);

  Credentials creds = new Credentials();
  creds.addToken(new Text(serviceUrl), token);
  DataOutputBuffer out = new DataOutputBuffer();
  creds.write(out);
  int fileLength = out.getData().length;
  ChannelBuffer cbuffer = ChannelBuffers.buffer(fileLength);
  cbuffer.writeBytes(out.getData());
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
      String.valueOf(fileLength));
  response.setContent(cbuffer);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 9
Project: FlexMap   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);

  Credentials creds = new Credentials();
  creds.addToken(new Text(serviceUrl), token);
  DataOutputBuffer out = new DataOutputBuffer();
  creds.write(out);
  int fileLength = out.getData().length;
  ChannelBuffer cbuffer = ChannelBuffers.buffer(fileLength);
  cbuffer.writeBytes(out.getData());
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
      String.valueOf(fileLength));
  response.setContent(cbuffer);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 10
Project: rest4j   File: RAPServerCodec.java   Source Code and License 6 votes vote down vote up
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg)
        throws Exception
{
  RestResponse response = (RestResponse) msg;

  HttpResponse nettyResponse =
      new DefaultHttpResponse(HttpVersion.HTTP_1_1,
                              HttpResponseStatus.valueOf(response.getStatus()));

  for (Map.Entry<String, String> e : response.getHeaders().entrySet())
  {
    nettyResponse.setHeader(e.getKey(), e.getValue());
  }
  final ByteString entity = response.getEntity();
  ChannelBuffer buf = ChannelBuffers.wrappedBuffer(entity.asByteBuffer());
  nettyResponse.setContent(buf);
  nettyResponse.setHeader(HttpHeaders.Names.CONTENT_LENGTH, entity.length());

  return nettyResponse;
}
 
Example 11
Project: netty-servlet   File: HttpServerHandler.java   Source Code and License 6 votes vote down vote up
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent event) throws Exception {
    if (event.getMessage() instanceof HttpRequest) {
        try {
            HttpServletRequest httpServletRequest = new NettyHttpServletRequestAdaptor((HttpRequest) event.getMessage(), ctx.getChannel());
            HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
            response.setContent(new DynamicChannelBuffer(200));
            HttpServletResponse httpServletResponse = new NettyHttpServletResponseAdaptor(response, ctx.getChannel());
            dispatcher.dispatch(httpServletRequest,httpServletResponse);
            response.headers().set(HttpHeaders.Names.CONTENT_LENGTH,response.getContent().writerIndex());
            ChannelFuture future = ctx.getChannel().write(response);
            future.addListener(ChannelFutureListener.CLOSE);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 12
Project: incubator-twill   File: TrackerService.java   Source Code and License 6 votes vote down vote up
private void writeResponse(MessageEvent e) {
  HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
  response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");

  ChannelBuffer content = ChannelBuffers.dynamicBuffer();
  Writer writer = new OutputStreamWriter(new ChannelBufferOutputStream(content), CharsetUtil.UTF_8);
  reportAdapter.toJson(report.get(), writer);
  try {
    writer.close();
  } catch (IOException e1) {
    LOG.error("error writing resource report", e1);
  }
  response.setContent(content);
  ChannelFuture future = e.getChannel().write(response);
  future.addListener(ChannelFutureListener.CLOSE);
}
 
Example 13
Project: hadoop-on-lustre2   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 6 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);

  Credentials creds = new Credentials();
  creds.addToken(new Text(serviceUrl), token);
  DataOutputBuffer out = new DataOutputBuffer();
  creds.write(out);
  int fileLength = out.getData().length;
  ChannelBuffer cbuffer = ChannelBuffers.buffer(fileLength);
  cbuffer.writeBytes(out.getData());
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
      String.valueOf(fileLength));
  response.setContent(cbuffer);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 14
Project: java-test-demo   File: HttpServerHandler.java   Source Code and License 6 votes vote down vote up
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
        throws Exception {
    HttpRequest request = (HttpRequest) e.getMessage();
    String uri = request.getUri();
    
    System.out.println("uri:" + uri);
    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    ChannelBuffer buffer = new DynamicChannelBuffer(2048);
    buffer.writeBytes("hello!! 你好".getBytes("UTF-8"));
    response.setContent(buffer);
    response.setHeader("Content-Type", "text/html; charset=UTF-8");
    response.setHeader("Content-Length", response.getContent().writerIndex());
    Channel ch = e.getChannel();
    // Write the initial line and the header.
    ch.write(response);
    ch.disconnect();
    ch.close();

}
 
Example 15
Project: feluca   File: WorkerJobRequest.java   Source Code and License 6 votes vote down vote up
private void handleInfoRequest(NettyHttpRequest req, DefaultHttpResponse resp){
	String jobName = req.param("jobName");
	WorkerModule m = ((WorkerModule)module);

	if (jobName != null){
		JSONObject searchJobInfo = m.searchJobInfo(jobName);
		if (searchJobInfo == null){
			HttpResponseUtil.setResponse(resp, " query job :" + jobName, "null");
		}else{
			HttpResponseUtil.setResponse(resp, " query job :" + jobName, searchJobInfo);
		}
	}else{
		HttpResponseUtil.setResponse(resp, "feluca job status", m.getLatestJobStates());
	}

}
 
Example 16
Project: feluca   File: LeaderJobRequest.java   Source Code and License 6 votes vote down vote up
private void handleInfoRequest(NettyHttpRequest req, DefaultHttpResponse resp){
	String numJobs = req.param("last", "5"); //default 5
	String jobType = req.param("isLocal", "true");
	String jobName = req.param("jobName");
	LeaderModule m = ((LeaderModule)module);
	if (!jobType.equalsIgnoreCase("true") && !jobType.equalsIgnoreCase("false")){
		HttpResponseUtil.setResponse(resp, "info action", "require 'isLocal' == 'true' OR 'false'");
		resp.setStatus(HttpResponseStatus.BAD_REQUEST);
	}else{
		boolean isLocal = new Boolean(jobType.toLowerCase());
		if (jobName != null){
			JSONObject searchJobInfo = m.searchJobInfo(jobName, isLocal);
			if (searchJobInfo == null){
				HttpResponseUtil.setResponse(resp, " query job :" + jobName, "null");
			}else{
				HttpResponseUtil.setResponse(resp, " query job :" + jobName, searchJobInfo);
			}
		}else if (numJobs != null){
			int num = new Integer(numJobs);
			HttpResponseUtil.setResponse(resp, "latest jobs", m.getLatestJobStates(num,isLocal));
		}else{
			HttpResponseUtil.setResponse(resp, "feluca job status", m.getLatestJobStates(1,isLocal));
		}
	}
}
 
Example 17
Project: feluca   File: LeaderJobRequest.java   Source Code and License 6 votes vote down vote up
private  void handleJobSubmit(NettyHttpRequest req, DefaultHttpResponse resp){
	LeaderModule m = (LeaderModule)this.module;
	String content = req.contentAsString();
	JSONObject parameters = new JSONObject();
	
	if (StringUtils.isBlank(content)){
		HttpResponseUtil.setResponse(resp, "submitJob failed! you need to post content : currently we have tasks:", FelucaJob.getTaskList());
		return;
	}
	
	try{
		parameters.putAll(JSONObject.parseObject(content));
		String submitJob = m.submitJob(FelucaJob.class, parameters);
		if (submitJob == null){
			HttpResponseUtil.setResponse(resp, "submitJob", "failed!");
		}else{
			HttpResponseUtil.setResponse(resp, "submitJob", submitJob);
		}
	} catch (Exception e) {
		HttpResponseUtil.setExceptionResponse(resp, Strings.keyValuesToJson("action", "submitJob"), 
				"submit error", e);
	}
}
 
Example 18
Project: jersey-netty   File: NettyContainer.java   Source Code and License 6 votes vote down vote up
@Override
public void failure(Throwable error) {
    log.error("Uncaught exception in transport layer. This is likely a bug, closing channel.", error);
    if (channel.isOpen()) {
        if (channel.isWritable()) {
            final DefaultHttpResponse internalServerResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_0, HttpResponseStatus.INTERNAL_SERVER_ERROR);
            try {
                internalServerResponse.setContent(ChannelBuffers.wrappedBuffer(("Uncaught exception!\n"
                        + error.getMessage()).getBytes("UTF-8")));
            } catch (UnsupportedEncodingException ignored) {}
            channel.write(internalServerResponse).addListener(ChannelFutureListener.CLOSE);
        } else {
            channel.close();
        }
    }
}
 
Example 19
Project: jersey-netty   File: NettyContainer.java   Source Code and License 6 votes vote down vote up
public void invalidRequestSent(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    Channel channel = ctx.getChannel();
    if (channel == null || !channel.isOpen()) {
        log.debug("Not writing any response, channel is already closed.", e.getCause());
        return;
    }

    final DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_0, HttpResponseStatus.BAD_REQUEST);
    response.headers().add(HttpHeaders.Names.CONTENT_TYPE, "text/plain");
    response.headers().add(HttpHeaders.Names.CONNECTION, "close");
    final ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    new ChannelBufferOutputStream(buffer).writeBytes("Your client has sent a malformed or illegal request.\n");
    response.setContent(buffer);

    final ChannelFuture channelFuture = channel.write(response);

    channelFuture.addListener(ChannelFutureListener.CLOSE);
}
 
Example 20
Project: tez   File: ShuffleHandler.java   Source Code and License 6 votes vote down vote up
private boolean deleteDagDirectories(MessageEvent evt,
                                     List<String> dagCompletedQ, List<String> jobQ,
                                     List<String> dagIdQ) {
  if (jobQ == null || jobQ.isEmpty()) {
    return false;
  }
  if (dagCompletedQ != null && !dagCompletedQ.isEmpty() && dagCompletedQ.get(0).contains("delete")
      && dagIdQ != null && !dagIdQ.isEmpty()) {
    String base = getDagLocation(jobQ.get(0), dagIdQ.get(0), userRsrc.get(jobQ.get(0)));
    try {
      FileContext lfc = FileContext.getLocalFSFileContext();
      for(Path dagPath : lDirAlloc.getAllLocalPathsToRead(base, conf)) {
        lfc.delete(dagPath, true);
      }
    } catch (IOException e) {
      LOG.warn("Encountered exception during dag delete "+ e);
    }
    evt.getChannel().write(new DefaultHttpResponse(HTTP_1_1, OK));
    evt.getChannel().close();
    return true;
  }
  return false;
}
 
Example 21
Project: ptp_proxy   File: Utils.java   Source Code and License 6 votes vote down vote up
public static String httpMessageToJson(DefaultHttpMessage message) throws JSONException {
    JSONObject jsonResult = new JSONObject();

    jsonResult.put(HTTP_VERSION, message.getProtocolVersion());
    jsonResult.put(HTTP_CONTENT, new String(message.getContent().array()));
    jsonResult.put(HTTP_IS_CHUNKED, message.isChunked());
    jsonResult.put(HTTP_HEADERS, message.getHeaders());

    if (message instanceof DefaultHttpRequest) {
        jsonResult.put(HTTP_MESSAGE_TYPE, HTTP_REQUEST);
        DefaultHttpRequest request = (DefaultHttpRequest) message;
        jsonResult.put(HTTP_METHOD, request.getMethod());
        jsonResult.put(HTTP_URI, request.getUri());
    } else if (message instanceof DefaultHttpResponse) {
        jsonResult.put(HTTP_MESSAGE_TYPE, HTTP_RESPONSE);
        jsonResult.put(HTTP_STATUS, ((DefaultHttpResponse) message).getStatus().getCode());
    }

    return jsonResult.toString();
}
 
Example 22
Project: traccar-service   File: DmtHttpProtocolDecoder.java   Source Code and License 5 votes vote down vote up
private void sendResponse(Channel channel, HttpResponseStatus status) {
    if (channel != null) {
        HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
        response.headers().add(HttpHeaders.Names.CONTENT_LENGTH, 0);
        channel.write(response);
    }
}
 
Example 23
Project: traccar-service   File: PiligrimProtocolDecoder.java   Source Code and License 5 votes vote down vote up
private void sendResponse(Channel channel, String message) {
    if (channel != null) {
        HttpResponse response = new DefaultHttpResponse(
                HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
        response.setContent(ChannelBuffers.copiedBuffer(
                ByteOrder.BIG_ENDIAN, message, StandardCharsets.US_ASCII));
        channel.write(response);
    }
}
 
Example 24
Project: traccar-service   File: OsmAndProtocolDecoder.java   Source Code and License 5 votes vote down vote up
private void sendResponse(Channel channel, HttpResponseStatus status) {
    if (channel != null) {
        HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
        response.headers().add(HttpHeaders.Names.CONTENT_LENGTH, 0);
        channel.write(response);
    }
}
 
Example 25
Project: traccar-service   File: Mta6ProtocolDecoder.java   Source Code and License 5 votes vote down vote up
private void sendResponse(Channel channel, short packetId, short packetCount) {
    HttpResponse response = new DefaultHttpResponse(
            HttpVersion.HTTP_1_1, HttpResponseStatus.OK);

    ChannelBuffer begin = ChannelBuffers.copiedBuffer("#ACK#", StandardCharsets.US_ASCII);
    ChannelBuffer end = ChannelBuffers.directBuffer(3);
    end.writeByte(packetId);
    end.writeByte(packetCount);
    end.writeByte(0);

    response.setContent(ChannelBuffers.wrappedBuffer(begin, end));
    channel.write(response);
}
 
Example 26
Project: traccar-service   File: OwnTracksProtocolDecoder.java   Source Code and License 5 votes vote down vote up
private void sendResponse(Channel channel, HttpResponseStatus status) {
    if (channel != null) {
        HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
        response.headers().add(HttpHeaders.Names.CONTENT_LENGTH, 0);
        channel.write(response);
    }
}
 
Example 27
Project: Elasticsearch   File: CorsHandler.java   Source Code and License 5 votes vote down vote up
private void handlePreflight(final ChannelHandlerContext ctx, final HttpRequest request) {
    final HttpResponse response = new DefaultHttpResponse(request.getProtocolVersion(), OK);
    if (setOrigin(response)) {
        setAllowMethods(response);
        setAllowHeaders(response);
        setAllowCredentials(response);
        setMaxAge(response);
        setPreflightHeaders(response);
        ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE);
    } else {
        forbidden(ctx, request);
    }
}
 
Example 28
Project: hadoop   File: ShuffleHandler.java   Source Code and License 5 votes vote down vote up
protected void sendError(ChannelHandlerContext ctx, String message,
    HttpResponseStatus status) {
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
  response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
  // Put shuffle version into http header
  response.setHeader(ShuffleHeader.HTTP_HEADER_NAME,
      ShuffleHeader.DEFAULT_HTTP_HEADER_NAME);
  response.setHeader(ShuffleHeader.HTTP_HEADER_VERSION,
      ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION);
  response.setContent(
    ChannelBuffers.copiedBuffer(message, CharsetUtil.UTF_8));

  // Close the connection as soon as the error message is sent.
  ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 29
Project: hadoop   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 5 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);
  byte[] bytes = EXP_DATE.getBytes();
  ChannelBuffer cbuffer = ChannelBuffers.buffer(bytes.length);
  cbuffer.writeBytes(bytes);
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
      String.valueOf(bytes.length));
  response.setContent(cbuffer);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 30
Project: hadoop   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 5 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, 
      HttpResponseStatus.METHOD_NOT_ALLOWED);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 31
Project: hadoop   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 5 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 32
Project: aliyun-oss-hadoop-fs   File: ShuffleHandler.java   Source Code and License 5 votes vote down vote up
protected void sendError(ChannelHandlerContext ctx, String message,
    HttpResponseStatus status) {
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
  response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
  // Put shuffle version into http header
  response.setHeader(ShuffleHeader.HTTP_HEADER_NAME,
      ShuffleHeader.DEFAULT_HTTP_HEADER_NAME);
  response.setHeader(ShuffleHeader.HTTP_HEADER_VERSION,
      ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION);
  response.setContent(
    ChannelBuffers.copiedBuffer(message, CharsetUtil.UTF_8));

  // Close the connection as soon as the error message is sent.
  ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 33
Project: big-c   File: ShuffleHandler.java   Source Code and License 5 votes vote down vote up
protected void sendError(ChannelHandlerContext ctx, String message,
    HttpResponseStatus status) {
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
  response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
  // Put shuffle version into http header
  response.setHeader(ShuffleHeader.HTTP_HEADER_NAME,
      ShuffleHeader.DEFAULT_HTTP_HEADER_NAME);
  response.setHeader(ShuffleHeader.HTTP_HEADER_VERSION,
      ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION);
  response.setContent(
    ChannelBuffers.copiedBuffer(message, CharsetUtil.UTF_8));

  // Close the connection as soon as the error message is sent.
  ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 34
Project: big-c   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 5 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);
  byte[] bytes = EXP_DATE.getBytes();
  ChannelBuffer cbuffer = ChannelBuffers.buffer(bytes.length);
  cbuffer.writeBytes(bytes);
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
      String.valueOf(bytes.length));
  response.setContent(cbuffer);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 35
Project: big-c   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 5 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, 
      HttpResponseStatus.METHOD_NOT_ALLOWED);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 36
Project: big-c   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 5 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 37
Project: OpenMobster   File: HttpServerHandler.java   Source Code and License 5 votes vote down vote up
private void writeResponse(MessageEvent e) 
{
    // Build the response object.
    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
    
    response.setContent(ChannelBuffers.copiedBuffer(buf.toString(), CharsetUtil.UTF_8));
    response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");

    // Write the response.
    ChannelFuture future = e.getChannel().write(response);

    // Close the non-keep-alive connection after the write operation is done.
    future.addListener(ChannelFutureListener.CLOSE);
}
 
Example 38
Project: Android-Airplay-Server   File: RaopAudioHandler.java   Source Code and License 5 votes vote down vote up
/**
 * Handles RECORD request. We did all the work during ANNOUNCE and SETUP, so there's nothing
 * more to do.
 * 
 * iTunes reports the initial RTP sequence and playback time here, which would actually be
 * helpful. But iOS doesn't, so we ignore it all together.
 */
public synchronized void recordReceived(final ChannelHandlerContext ctx, final HttpRequest req) throws Exception {
	if (audioStreamInformationProvider == null){
		throw new ProtocolException("Audio stream not configured, cannot start recording");
	}		
	LOG.info("Client started streaming");
	
	audioOutputQueue.startAudioProcessing();
	timingHandler.startTimeSync();
	
	final HttpResponse response = new DefaultHttpResponse(RtspVersions.RTSP_1_0,  RtspResponseStatuses.OK);
	ctx.getChannel().write(response);
}
 
Example 39
Project: Android-Airplay-Server   File: RaopAudioHandler.java   Source Code and License 5 votes vote down vote up
/**
 * Handle FLUSH requests.
 * 
 * iTunes reports the last RTP sequence and playback time here, which would actually be
 * helpful. But iOS doesn't, so we ignore it all together.
 */
private synchronized void flushReceived(final ChannelHandlerContext ctx, final HttpRequest req) {
	if (audioOutputQueue != null){
		audioOutputQueue.flush();
	}

	LOG.info("Client paused streaming, flushed audio output queue");

	final HttpResponse response = new DefaultHttpResponse(RtspVersions.RTSP_1_0,  RtspResponseStatuses.OK);
	ctx.getChannel().write(response);
}
 
Example 40
Project: Android-Airplay-Server   File: RaopAudioHandler.java   Source Code and License 5 votes vote down vote up
/**
 * Handle TEARDOWN requests. 
 */
private synchronized void teardownReceived(final ChannelHandlerContext ctx, final HttpRequest req) {
	final HttpResponse response = new DefaultHttpResponse(RtspVersions.RTSP_1_0,  RtspResponseStatuses.OK);
	ctx.getChannel().setReadable(false);
	ctx.getChannel().write(response).addListener(new ChannelFutureListener() {
		@Override
		public void operationComplete(final ChannelFuture future) throws Exception {
			future.getChannel().close();
			LOG.info("RTSP connection closed after client initiated teardown");
		}
	});
}
 
Example 41
Project: Android-Airplay-Server   File: RaopAudioHandler.java   Source Code and License 5 votes vote down vote up
/**
 * Handle SET_PARAMETER request. Currently only {@code volume} is supported
 */
public synchronized void setParameterReceived(final ChannelHandlerContext ctx, final HttpRequest req) throws ProtocolException {
	/* Body in ASCII encoding with unix newlines */
	final String body = req.getContent().toString(Charset.forName("ASCII")).replace("\r", "");

	/* Handle parameters */
	for(final String line: body.split("\n")) {
		try {
			/* Split parameter into name and value */
			final Matcher m_parameter = s_pattern_parameter.matcher(line);
			if (!m_parameter.matches()){
				throw new ProtocolException("Cannot parse line " + line);
			}

			final String name = m_parameter.group(1);
			final String value = m_parameter.group(2);

			if ("volume".equals(name)) {
				if (audioOutputQueue != null){
					float vol = Math.abs(Float.parseFloat(value));
					vol = (float) (1.0 - (vol / 29.0));
					audioOutputQueue.setRequestedVolume(vol);
				}
			}
		}
		catch (final Throwable e) {
			throw new ProtocolException("Unable to parse line " + line);
		}
	}

	final HttpResponse response = new DefaultHttpResponse(RtspVersions.RTSP_1_0,  RtspResponseStatuses.OK);
	ctx.getChannel().write(response);
}
 
Example 42
Project: Android-Airplay-Server   File: RaopAudioHandler.java   Source Code and License 5 votes vote down vote up
/**
 * Handle GET_PARAMETER request. Currently only {@code volume} is supported
 */
public synchronized void getParameterReceived(final ChannelHandlerContext ctx, final HttpRequest req) throws ProtocolException {
	final StringBuilder body = new StringBuilder();

	if (audioOutputQueue != null) {
		/* Report output gain */
		body.append("volume: ");
		body.append(audioOutputQueue.getRequestedVolume());
		body.append("\r\n");
	}

	final HttpResponse response = new DefaultHttpResponse(RtspVersions.RTSP_1_0,  RtspResponseStatuses.OK);
	response.setContent(ChannelBuffers.wrappedBuffer(body.toString().getBytes(Charset.forName("ASCII"))));
	ctx.getChannel().write(response);
}
 
Example 43
Project: Camel   File: HttpServerMultiplexChannelHandler.java   Source Code and License 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
    HttpServerChannelHandler handler = (HttpServerChannelHandler) ctx.getAttachment();
    if (handler != null) {
        handler.exceptionCaught(ctx, e);
    } else {
        if (e.getCause() instanceof ClosedChannelException) {
            // The channel is closed so we do nothing here
            LOG.debug("Channel already closed. Ignoring this exception.");
            return;
        } else {
            if ("Broken pipe".equals(e.getCause().getMessage())) {
                // Can't recover channel at this point. Only valid thing to do is close. A TCP RST is a possible cause for this.
                // Note that trying to write to channel in this state will cause infinite recursion in netty 3.x
                LOG.debug("Channel pipe is broken. Closing channel now.", e);                    
                ctx.getChannel().close();
            } else {
                // we cannot throw the exception here
                LOG.warn("HttpServerChannelHandler is not found as attachment to handle exception, send 404 back to the client.", e.getCause());
                // Now we just send 404 back to the client
                HttpResponse response = new DefaultHttpResponse(HTTP_1_1, NOT_FOUND);
                response.headers().set(Exchange.CONTENT_TYPE, "text/plain");
                response.headers().set(Exchange.CONTENT_LENGTH, 0);
                // Here we don't want to expose the exception detail to the client
                response.setContent(ChannelBuffers.copiedBuffer(new byte[]{}));                
                
                ctx.getChannel().write(response).syncUninterruptibly();
                // close the channel after send error message
                ctx.getChannel().close();
            }
        }
    }
}
 
Example 44
Project: Camel   File: NettyHttpAccessHttpRequestAndResponseBeanTest.java   Source Code and License 5 votes vote down vote up
/**
 * We can use both a netty http request and response type for transformation
 */
public static HttpResponse myTransformer(HttpRequest request) {
    String in = request.getContent().toString(Charset.forName("UTF-8"));
    String reply = "Bye " + in;

    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    response.setContent(ChannelBuffers.copiedBuffer(reply.getBytes()));
    response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, reply.length());

    return response;
}
 
Example 45
Project: hadoop-2.6.0-cdh5.4.3   File: ShuffleHandler.java   Source Code and License 5 votes vote down vote up
protected void sendError(ChannelHandlerContext ctx, String message,
    HttpResponseStatus status) {
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
  response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
  // Put shuffle version into http header
  response.setHeader(ShuffleHeader.HTTP_HEADER_NAME,
      ShuffleHeader.DEFAULT_HTTP_HEADER_NAME);
  response.setHeader(ShuffleHeader.HTTP_HEADER_VERSION,
      ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION);
  response.setContent(
    ChannelBuffers.copiedBuffer(message, CharsetUtil.UTF_8));

  // Close the connection as soon as the error message is sent.
  ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 46
Project: hadoop-2.6.0-cdh5.4.3   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 5 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);
  byte[] bytes = EXP_DATE.getBytes();
  ChannelBuffer cbuffer = ChannelBuffers.buffer(bytes.length);
  cbuffer.writeBytes(bytes);
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
      String.valueOf(bytes.length));
  response.setContent(cbuffer);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 47
Project: hadoop-2.6.0-cdh5.4.3   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 5 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, 
      HttpResponseStatus.METHOD_NOT_ALLOWED);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 48
Project: hadoop-2.6.0-cdh5.4.3   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 5 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 49
Project: hadoop-EAR   File: ShuffleHandler.java   Source Code and License 5 votes vote down vote up
private void sendError(ChannelHandlerContext ctx, String message,
    HttpResponseStatus status) {
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
  response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
  response.setContent(
      ChannelBuffers.copiedBuffer(message, CharsetUtil.UTF_8));

  // Close the connection as soon as the error message is sent.
  ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 50
Project: hadoop-plus   File: ShuffleHandler.java   Source Code and License 5 votes vote down vote up
protected void sendError(ChannelHandlerContext ctx, String message,
    HttpResponseStatus status) {
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
  response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
  // Put shuffle version into http header
  response.setHeader(ShuffleHeader.HTTP_HEADER_NAME,
      ShuffleHeader.DEFAULT_HTTP_HEADER_NAME);
  response.setHeader(ShuffleHeader.HTTP_HEADER_VERSION,
      ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION);
  response.setContent(
    ChannelBuffers.copiedBuffer(message, CharsetUtil.UTF_8));

  // Close the connection as soon as the error message is sent.
  ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 51
Project: finagle-java-example-master-slave   File: GeneratorMaster.java   Source Code and License 5 votes vote down vote up
private HttpResponse createJsonResponse(String content) {
    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    ChannelBuffer buffer = ChannelBuffers.copiedBuffer(content, UTF_8);
    response.setContent(buffer);
    response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
    response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.readableBytes());
    return response;
}
 
Example 52
Project: finagle-java-example-master-slave   File: GeneratorMasterZk.java   Source Code and License 5 votes vote down vote up
private HttpResponse createJsonResponse(String content) {
    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    ChannelBuffer buffer = ChannelBuffers.copiedBuffer(content, UTF_8);
    response.setContent(buffer);
    response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
    response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.readableBytes());
    return response;
}
 
Example 53
Project: finagle-java-example-master-slave   File: GeneratorSlave.java   Source Code and License 5 votes vote down vote up
private HttpResponse createJsonResponse(String content) {
    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    ChannelBuffer buffer = ChannelBuffers.copiedBuffer(content, UTF_8);
    response.setContent(buffer);
    response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
    response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, buffer.readableBytes());
    return response;
}
 
Example 54
Project: FlexMap   File: ShuffleHandler.java   Source Code and License 5 votes vote down vote up
protected void sendError(ChannelHandlerContext ctx, String message,
    HttpResponseStatus status) {
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
  response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
  // Put shuffle version into http header
  response.setHeader(ShuffleHeader.HTTP_HEADER_NAME,
      ShuffleHeader.DEFAULT_HTTP_HEADER_NAME);
  response.setHeader(ShuffleHeader.HTTP_HEADER_VERSION,
      ShuffleHeader.DEFAULT_HTTP_HEADER_VERSION);
  response.setContent(
    ChannelBuffers.copiedBuffer(message, CharsetUtil.UTF_8));

  // Close the connection as soon as the error message is sent.
  ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 55
Project: FlexMap   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 5 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);
  byte[] bytes = EXP_DATE.getBytes();
  ChannelBuffer cbuffer = ChannelBuffers.buffer(bytes.length);
  cbuffer.writeBytes(bytes);
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  response.setHeader(HttpHeaders.Names.CONTENT_LENGTH,
      String.valueOf(bytes.length));
  response.setContent(cbuffer);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 56
Project: FlexMap   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 5 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, 
      HttpResponseStatus.METHOD_NOT_ALLOWED);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 57
Project: FlexMap   File: TestDelegationTokenRemoteFetcher.java   Source Code and License 5 votes vote down vote up
@Override
public void handle(Channel channel, Token<DelegationTokenIdentifier> token,
    String serviceUrl) throws IOException {
  Assert.assertEquals(testToken, token);
  HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
  channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
Example 58
Project: AirSpeakerMobile   File: RaopAudioHandler.java   Source Code and License 5 votes vote down vote up
/**
 * Handles RECORD request. We did all the work during ANNOUNCE and SETUP, so there's nothing
 * more to do.
 * 
 * iTunes reports the initial RTP sequence and playback time here, which would actually be
 * helpful. But iOS doesn't, so we ignore it all together.
 */
public synchronized void recordReceived(final ChannelHandlerContext ctx, final HttpRequest req) throws Exception {
	if (audioStreamInformationProvider == null){
		throw new ProtocolException("Audio stream not configured, cannot start recording");
	}		
	LogManager.w("Client started streaming");
	
	audioOutputQueue.startAudioProcessing();
	timingHandler.startTimeSync();
	
	final HttpResponse response = new DefaultHttpResponse(RtspVersions.RTSP_1_0,  RtspResponseStatuses.OK);
	ctx.getChannel().write(response);
}
 
Example 59
Project: AirSpeakerMobile   File: RaopAudioHandler.java   Source Code and License 5 votes vote down vote up
/**
 * Handle FLUSH requests.
 * 
 * iTunes reports the last RTP sequence and playback time here, which would actually be
 * helpful. But iOS doesn't, so we ignore it all together.
 */
private synchronized void flushReceived(final ChannelHandlerContext ctx, final HttpRequest req) {
	if (audioOutputQueue != null){
		audioOutputQueue.flush();
	}

	LogManager.w("Client paused streaming, flushed audio output queue");

	final HttpResponse response = new DefaultHttpResponse(RtspVersions.RTSP_1_0,  RtspResponseStatuses.OK);
	ctx.getChannel().write(response);
}
 
Example 60
Project: AirSpeakerMobile   File: RaopAudioHandler.java   Source Code and License 5 votes vote down vote up
/**
 * Handle TEARDOWN requests. 
 */
private synchronized void teardownReceived(final ChannelHandlerContext ctx, final HttpRequest req) {
	final HttpResponse response = new DefaultHttpResponse(RtspVersions.RTSP_1_0,  RtspResponseStatuses.OK);
	ctx.getChannel().setReadable(false);
	ctx.getChannel().write(response).addListener(new ChannelFutureListener() {
		@Override
		public void operationComplete(final ChannelFuture future) throws Exception {
			future.getChannel().close();
			LogManager.w("RTSP connection closed after client initiated teardown");
		}
	});
}