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


Java HttpResponseStatus.OK属性代码示例

本文整理汇总了Java中org.jboss.netty.handler.codec.http.HttpResponseStatus.OK属性的典型用法代码示例。如果您正苦于以下问题:Java HttpResponseStatus.OK属性的具体用法?Java HttpResponseStatus.OK怎么用?Java HttpResponseStatus.OK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.jboss.netty.handler.codec.http.HttpResponseStatus的用法示例。


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

示例1: decode

@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;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:38,代码来源:PathAwayProtocolDecoder.java

示例2: doPost

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);
}
 
开发者ID:yandex,项目名称:opentsdb-flume,代码行数:23,代码来源:LegacyHttpSource.java

示例3: writeResponse

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);
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:16,代码来源:TrackerService.java

示例4: messageReceived

@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();

}
 
开发者ID:laizhihuan,项目名称:java-test-demo,代码行数:20,代码来源:HttpServerHandler.java

示例5: sendResponse

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);
    }
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:9,代码来源:PiligrimProtocolDecoder.java

示例6: sendResponse

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);
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:13,代码来源:Mta6ProtocolDecoder.java

示例7: myTransformer

/**
 * 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;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:NettyHttpAccessHttpRequestAndResponseBeanTest.java

示例8: createJsonResponse

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;
}
 
开发者ID:eternalthinker,项目名称:finagle-java-example-master-slave,代码行数:8,代码来源:GeneratorMaster.java

示例9: main

public static void main(String[] args) {
    Service<HttpRequest, HttpResponse> service = new Service<HttpRequest, HttpResponse>() {
        @Override
        public Future<HttpResponse> apply(HttpRequest request) {
            String reqContent = request.getContent().toString(CharsetUtil.UTF_8);
            System.out.println("[Helper] Request received: " + reqContent);
            
            // Parsing JSON request
            JSONObject jreq;
            try {
                jreq = (JSONObject) jsonParser.parse(reqContent);
                System.out.println("[Main] Param received - pname:" + jreq.get("pname"));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            
            HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
            res.setContent(ChannelBuffers.copiedBuffer("{\"v_id\":100, \"price\":0.2}", CharsetUtil.UTF_8));
            res.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/plain; charset=UTF-8");
            return Future.<HttpResponse> value(res);
        }
    };
    
    ServerBuilder.safeBuild(service,
            ServerBuilder.get().codec(Http.get()).name("HttpServer")
            .bindTo(new InetSocketAddress("localhost", 9004)));
}
 
开发者ID:eternalthinker,项目名称:finagle-6.x-java-example,代码行数:27,代码来源:HelperServer.java

示例10: apply

public Future<HttpResponse> apply(HttpResponse res) {
    String resContent = res.getContent().toString(CharsetUtil.UTF_8);
    System.out.println("[Main] Received helper response: " + resContent);
    
    System.out.println("[Main] Sending response to main client");
    HttpResponse finalRes = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    finalRes.setContent(ChannelBuffers.copiedBuffer("{\"bid\":" + resContent + "}", CharsetUtil.UTF_8));
    finalRes.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/json; charset=UTF-8");
    return Future.<HttpResponse> value(finalRes);
}
 
开发者ID:eternalthinker,项目名称:finagle-6.x-java-example,代码行数:10,代码来源:MainServer.java

示例11: sendResponse

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, Charset.defaultCharset()));
        channel.write(response);
    }
}
 
开发者ID:michaelloliveira,项目名称:traccar-mongodb,代码行数:9,代码来源:PiligrimProtocolDecoder.java

示例12: sendResponse

private void sendResponse(Channel channel, short packetId, short packetCount) {
    HttpResponse response = new DefaultHttpResponse(
            HttpVersion.HTTP_1_1, HttpResponseStatus.OK);

    ChannelBuffer begin = ChannelBuffers.copiedBuffer("#ACK#", Charset.defaultCharset());
    ChannelBuffer end = ChannelBuffers.directBuffer(3);
    end.writeByte(packetId);
    end.writeByte(packetCount);
    end.writeByte(0);
    
    response.setContent(ChannelBuffers.wrappedBuffer(begin, end));
    channel.write(response);
}
 
开发者ID:michaelloliveira,项目名称:traccar-mongodb,代码行数:13,代码来源:Mta6ProtocolDecoder.java

示例13: writeResponse

private void writeResponse(MessageEvent e) throws Exception {
    HttpResponse response =
            new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    response.setContent(ChannelBuffers.copiedBuffer("Hello world", CharsetUtil.UTF_8));
    addHeader(response, HttpHeaders.Names.CONTENT_TYPE, "text/plain; charset=UTF-8");
    ChannelFuture future = e.getChannel().write(response);
    future.addListener(ChannelFutureListener.CLOSE);
}
 
开发者ID:glowroot,项目名称:glowroot,代码行数:8,代码来源:HttpServerHandler.java

示例14: messageReceived

public void messageReceived(ChannelHandlerContext ctx, final MessageEvent e)
			throws Exception {
		// common http request
		HttpRequest req = (HttpRequest)e.getMessage();
		NettyHttpRequest nhr = new NettyHttpRequest(req);
		String path = nhr.path();

		Handler handler = handlers.getHandler(path);
		DefaultHttpResponse resp = new DefaultHttpResponse(req.getProtocolVersion(), HttpResponseStatus.OK);
		if (handler == null){
			Set<String> handlerPaths = this.handlers.getHandlerPaths();
			
//			handlerPaths.remove(DataAllocateHandler.PATH);
//			handlerPaths.remove(JobMessageFromSlaveHandler.PATH);
			JSONArray ja = new JSONArray();
			ja.addAll(handlerPaths);
			HttpResponseUtil.setResponse(resp, "request path :" + path, 
					Strings.keyValuesToJson("code",404, "available_path", ja),
					HttpResponseStatus.NOT_FOUND);
		}else{
			handler.handle(nhr, resp);
		}
		
		resp.setHeader(HttpHeaders.Names.CONTENT_TYPE, Strings.CONTENT_TYPE);
		resp.setHeader("Content-Length", resp.getContent().readableBytes());

		boolean close = !HttpHeaders.isKeepAlive(req);

		resp.setHeader(HttpHeaders.Names.CONNECTION,
				close ? HttpHeaders.Values.CLOSE
						: HttpHeaders.Values.KEEP_ALIVE);
		
		ChannelFuture cf = e.getChannel().write(resp);

		if (close) 
			cf.addListener(ChannelFutureListener.CLOSE);
		writeAccessLog(e.getChannel(), req, resp);
	
	}
 
开发者ID:lgnlgn,项目名称:feluca,代码行数:39,代码来源:LeaderNettyChannel.java

示例15: service

@Override
protected void service(ResourceProvider provider, Channel channel, HttpRequest request) throws IOException {
	String path = request.getUri();
	ByteBuffer buf = provider.get(path);

	ChannelBuffer wrapped;
	HttpResponseStatus status = HttpResponseStatus.OK;

	String mime = getMimeType(request.getUri());

	if (buf == null) {
		status = HttpResponseStatus.NOT_FOUND;
		wrapped = createErrorPage(status, "The page you requested could not be found.");
		mime = "text/html";
	} else {
		wrapped = ChannelBuffers.wrappedBuffer(buf);
	}

	HttpResponse response = new DefaultHttpResponse(request.getProtocolVersion(), status);

	response.setHeader("Date", new Date());
	response.setHeader("Server", SERVER_IDENTIFIER);
	response.setHeader("Content-type", mime + ", charset=" + CHARACTER_SET.name());
	response.setHeader("Cache-control", "no-cache");
	response.setHeader("Pragma", "no-cache");
	response.setHeader("Expires", new Date(0));
	response.setHeader("Connection", "close");
	response.setHeader("Content-length", wrapped.readableBytes());
	response.setChunked(false);
	response.setContent(wrapped);

	channel.write(response).addListener(ChannelFutureListener.CLOSE);
}
 
开发者ID:DealerNextDoor,项目名称:ApolloDev,代码行数:33,代码来源:HttpRequestWorker.java


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