Package org.jboss.netty.handler.codec.http

Examples of org.jboss.netty.handler.codec.http.DefaultHttpResponse


    callback.clearLastMsg();
    objCapture.clear();

    //send back some response
    HttpResponse sourcesResp = new DefaultHttpResponse(HttpVersion.HTTP_1_1,
                                                       HttpResponseStatus.OK);
    sourcesResp.setHeader(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
    sourcesResp.setHeader(HttpHeaders.Names.TRANSFER_ENCODING, HttpHeaders.Values.CHUNKED);
    HttpChunk body =
        new DefaultHttpChunk(ChannelBuffers.wrappedBuffer("[{\"id\":1,\"name\":\"test.source1\"}]".getBytes(Charset.defaultCharset())));
    NettyTestUtils.sendServerResponses(_dummyServer, clientAddr, sourcesResp, body);

    waitForCallback(callback,
View Full Code Here


            int bt = -1;
            while((bt=is.read())!=-1) {
              baos.write(bt);
            }
            byte[] content = baos.toByteArray();
            response = new DefaultHttpResponse(HTTP_1_1, OK);
                setContentLength(response, content.length);
                setContentTypeHeader(response, resourcePath);
                setDateAndCacheHeaders(response, resourcePath);
                response.setContent(ChannelBuffers.wrappedBuffer(content));
                contentCache.put(resourcePath, response);
View Full Code Here

            sendError(ctx, NOT_FOUND);
            return null;
        }
        long fileLength = raf.length();

        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
        setContentLength(response, fileLength);
        setContentTypeHeader(response, file.getAbsolutePath());
        setDateAndCacheHeaders(response, file);
       
        Channel ch = e.getChannel();
View Full Code Here

        }
    }


    private void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, status);
        response.setHeader(CONTENT_TYPE, "text/plain; charset=UTF-8");
        response.setContent(ChannelBuffers.copiedBuffer(
                "Failure: " + status.toString() + "\r\n",
                CharsetUtil.UTF_8));

        // Close the connection as soon as the error message is sent.
        ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE);
View Full Code Here

     *
     * @param ctx
     *            Context
     */
    private void sendNotModified(ChannelHandlerContext ctx) {
        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.NOT_MODIFIED);
        setDateHeader(response);

        // Close the connection as soon as the error message is sent.
        ctx.getChannel().write(response).addListener(ChannelFutureListener.CLOSE);
    }
View Full Code Here

            ctx.sendDownstream(e);
            return;     
    }
   
    ChannelBuffer cb = ChannelBuffers.copiedBuffer(message.toString(), CharsetUtil.UTF_8);
    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
    response.setHeader(CONTENT_LENGTH, cb.readableBytes());
    response.setHeader(CONTENT_TYPE, "application/json");
    response.setHeader(CACHE_CONTROL, "no-cache");
    response.setContent(cb);
    ChannelFuture cf = Channels.future(channel);
    ctx.sendDownstream(new DownstreamMessageEvent(channel, cf, response, channel.getRemoteAddress()));
   
  }
View Full Code Here

   * @param ctx The channel handler context
   * @param req The HTTP request
   */
  public void handleRequest(ChannelHandlerContext ctx, HttpRequest req) {
        if (req.getMethod() != GET) {
            sendHttpResponse(ctx, req, new DefaultHttpResponse(HTTP_1_1, FORBIDDEN));
            return;
        }
        // Handshake
        WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(getWebSocketLocation(req), null, false);
        this.handshaker = wsFactory.newHandshaker(req);
View Full Code Here

      MessageEvent messageEvent = (MessageEvent)e;
      Object message = messageEvent.getMessage();
      if(message instanceof HttpRequest) {
        HttpRequest request = (HttpRequest)message;
        int metricCount = processMetric(request);
        HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
        response.setContent(ChannelBuffers.copiedBuffer("\n" + metricCount + "\n", CharsetUtil.UTF_8));
        response.setHeader(CONTENT_TYPE, "text/plain");
        ChannelFuture future = Channels.future(channel);
        ctx.sendDownstream(new DownstreamMessageEvent(channel, future, response, channel.getRemoteAddress()));
        future.addListener(ChannelFutureListener.CLOSE);       
      }
    }
View Full Code Here

            ctx.sendDownstream(e);
            return;     
    }
    Channel channel = e.getChannel();
    StringBuilder b = new StringBuilder("\n").append(message).append("--").append(channel.getId()).append("\n");
    HttpResponse response = new DefaultHttpResponse(HTTP_1_1, PARTIAL_CONTENT);
    response.setContent(ChannelBuffers.copiedBuffer(b, CharsetUtil.UTF_8));
    response.setHeader(CONTENT_TYPE, "application/json");
    ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), response, channel.getRemoteAddress()));
  }
View Full Code Here

  @Override
  public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
    final Channel channel = e.getChannel();
    if(channel.isOpen() && SharedChannelGroup.getInstance().add(channel)) {
      StringBuilder b = new StringBuilder("\n--").append(channel.getId()).append("\n");
      HttpResponse response = new DefaultHttpResponse(HTTP_1_1, PARTIAL_CONTENT);
      response.setContent(ChannelBuffers.copiedBuffer(b, CharsetUtil.UTF_8));
      response.setHeader(CONTENT_TYPE, String.format("multipart/x-mixed-replace;boundary=\"%s\"", channel.getId()));
      ctx.sendDownstream(new DownstreamMessageEvent(channel, Channels.future(channel), response, channel.getRemoteAddress()));
    }
    ctx.sendUpstream(e);   
  }
View Full Code Here

TOP

Related Classes of org.jboss.netty.handler.codec.http.DefaultHttpResponse

Copyright © 2018 www.massapicom. 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.