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


Java HttpServerResponse.writeStringAndFlush方法代码示例

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


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

示例1: handle

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
@Override
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
    if (request.getUri().startsWith(healthCheckUri)) {
        return healthCheckEndpoint.handle(request, response);
    } else if (request.getUri().startsWith("/hello/to/")) {
        int prefixLength = "/hello/to".length();
        String userName = request.getPath().substring(prefixLength);
        if (userName.isEmpty() || userName.length() == 1 /*The uri is /hello/to/ but no name */) {
            response.setStatus(HttpResponseStatus.BAD_REQUEST);
            return response.writeStringAndFlush(
                    "{\"Error\":\"Please provide a username to say hello. The URI should be /hello/to/{username}\"}");
        } else {
            String msg = "Hello " + userName.substring(1) /*Remove the / prefix*/ + " from Netflix OSS";
            return response.writeStringAndFlush("{\"Message\":\"" + msg + "\"}");
        }
    } else if (request.getUri().startsWith("/hello")) {
        return response.writeStringAndFlush("{\"Message\":\"Hello newbee from Netflix OSS\"}");
    } else {
        response.setStatus(HttpResponseStatus.NOT_FOUND);
        return response.close();
    }
}
 
开发者ID:Netflix,项目名称:karyon,代码行数:23,代码来源:RxNettyHandler.java

示例2: HystrixMetricsStreamHandler

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
public HystrixMetricsStreamHandler(String hystrixPrefix, long intervalInMillis) {
    this.hystrixPrefix = hystrixPrefix;
    this.interval = intervalInMillis;
    this.appHandler = (HttpServerRequest<I> request, HttpServerResponse<O> response) -> {
        return response.writeStringAndFlush("Only supported path is /" + hystrixPrefix);
    };
}
 
开发者ID:Netflix,项目名称:ReactiveLab,代码行数:8,代码来源:HystrixMetricsStreamHandler.java

示例3: handleRequest

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
private static Observable<Void> handleRequest(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {

        if (request.getUri().startsWith("/hello")) {
            return response.writeStringAndFlush("Hello world!");
        }

        List<String> _id = request.getQueryParameters().get("id");
        if (_id == null || _id.size() != 1) {
            return writeError(request, response,
                              "Please provide a numerical 'id' value. It can be a random number (uuid). Received => "
                              + _id);
        }
        long id = Long.parseLong(String.valueOf(_id.get(0)));

        int delay = getParameter(request, "delay", 50); // default to 50ms server-side delay
        int itemSize = getParameter(request, "itemSize", 128); // default to 128 bytes item size (assuming ascii text)
        int numItems = getParameter(request, "numItems", 10); // default to 10 items in a list

        // no more than 100 items
        if (numItems < 1 || numItems > 100) {
            return writeError(request, response, "Please choose a 'numItems' value from 1 to 100.");
        }

        // no larger than 50KB per item
        if (itemSize < 1 || itemSize > 1024 * 50) {
            return writeError(request, response, "Please choose an 'itemSize' value from 1 to 1024*50 (50KB).");
        }

        // no larger than 60 second delay
        if (delay < 0 || delay > 60000) {
            return writeError(request, response, "Please choose a 'delay' value from 0 to 60000 (60 seconds).");
        }

        response.setStatus(HttpResponseStatus.OK);
        return MockResponse.generateJson(id, delay, itemSize, numItems)
                           .doOnNext(json -> counter.add(CounterEvent.BYTES, json.readableBytes()))
                           .flatMap(response::writeAndFlush)
                           .doOnTerminate(response::close);
    }
 
开发者ID:Netflix-Skunkworks,项目名称:WSPerfLab,代码行数:40,代码来源:StartMockService.java

示例4: writeError

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
protected static Observable<Void> writeError(HttpServerRequest<?> request, HttpServerResponse<?> response, String message) {
    System.err.println("Server => Error [" + request.getPath() + "] => " + message);
    response.setStatus(HttpResponseStatus.BAD_REQUEST);
    return response.writeStringAndFlush("Error 500: " + message + "\n");
}
 
开发者ID:Netflix,项目名称:ReactiveLab,代码行数:6,代码来源:AbstractMiddleTierService.java

示例5: writeError

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
private static Observable<Void> writeError(HttpServerRequest<?> request, HttpServerResponse<?> response, String message) {
    System.err.println("Server => Error [" + request.getPath() + "] => " + message);
    response.setStatus(HttpResponseStatus.BAD_REQUEST);
    return response.writeStringAndFlush("Error 500: " + message + "\n");
}
 
开发者ID:Netflix,项目名称:ReactiveLab,代码行数:6,代码来源:TestRouteWithSimpleFaultTolerance.java

示例6: writeError

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
public static Observable<Void> writeError(HttpServerRequest<?> request, HttpServerResponse<ByteBuf> response, String message) {
    System.err.println("Server => Error [" + request.getPath() + "] => " + message);
    response.setStatus(HttpResponseStatus.BAD_REQUEST);
    return response.writeStringAndFlush("Error 500: " + message);
}
 
开发者ID:Netflix,项目名称:ReactiveLab,代码行数:6,代码来源:StartGatewayServer.java

示例7: writeError

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
protected static Observable<Void> writeError(HttpServerRequest<?> request, HttpServerResponse<?> response, String message) {
    System.err.println("Server => Error [" + request.getPath() + "] => " + message);
    response.setStatus(HttpResponseStatus.BAD_REQUEST);
    counter.increment(CounterEvent.HTTP_ERROR);
    return response.writeStringAndFlush("Error 500: " + message + '\n');
}
 
开发者ID:Netflix-Skunkworks,项目名称:WSPerfLab,代码行数:7,代码来源:StartMockService.java


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