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


Java HttpServerResponse.close方法代码示例

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


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

示例1: handle

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
@Override
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
    if (alarmService == null) {
        response.setStatus(HttpResponseStatus.SERVICE_UNAVAILABLE);
        return response.close();
    }
    if (HttpMethod.GET.equals(request.getHttpMethod())) {
        handleGet(response, request.getUri());
    } else if (HttpMethod.PUT.equals(request.getHttpMethod())) {
        handlePut(response, request.getContent());
    } else if (HttpMethod.DELETE.equals(request.getHttpMethod())) {
        handleDelete(response, request.getUri());
    } else {
        response.setStatus(HttpResponseStatus.NOT_IMPLEMENTED);
    }
    return response.close();
}
 
开发者ID:jscattergood,项目名称:WeatherAlarm,代码行数:18,代码来源:WeatherAlarmEndpoint.java

示例2: handleRecommendationsByUserId

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
private Observable<Void> handleRecommendationsByUserId(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
    System.out.println("HTTP request -> recommendations by user id request: " + request.getPath());
    final String userId = userIdFromPath(request.getPath());
    if (userId == null) {
        response.setStatus(HttpResponseStatus.BAD_REQUEST);
        return response.close();
    }
    if (!userRecommendations.containsKey(userId)) {
        response.setStatus(HttpResponseStatus.NOT_FOUND);
        return response.close();
    }

    StringBuilder builder = new StringBuilder();
    for (String movieId : userRecommendations.get(userId)) {
        System.out.println("    returning: " + movies.get(movieId));
        builder.append(movies.get(movieId)).append('\n');
    }

    ByteBuf byteBuf = UnpooledByteBufAllocator.DEFAULT.buffer();
    byteBuf.writeBytes(builder.toString().getBytes(Charset.defaultCharset()));

    response.write(byteBuf);
    return response.close();
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:25,代码来源:RxMovieServer.java

示例3: 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

示例4: sayHelloToUser

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
public Observable<Void> sayHelloToUser(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
    JSONObject content = new JSONObject();

    int prefixLength = "/hello/to".length();
    String userName = request.getPath().substring(prefixLength);

    try {
        if (userName.isEmpty() || userName.length() == 1 /*The uri is /hello/to/ but no name */) {
            response.setStatus(HttpResponseStatus.BAD_REQUEST);
            content.put("Error", "Please provide a username to say hello. The URI should be /hello/to/{username}");
        } else {
            content.put("Message", "Hello " + userName.substring(1) /*Remove the / prefix*/ + " from Netflix OSS");
        }
    } catch (JSONException e) {
        logger.error("Error creating json response.", e);
        return Observable.error(e);
    }

    response.write(content.toString(), StringTransformer.DEFAULT_INSTANCE);
    return response.close();

}
 
开发者ID:Netflix,项目名称:karyon,代码行数:23,代码来源:HelloWorldEndpoint.java

示例5: handle

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
@Override
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
    RequestHandler<ByteBuf, ByteBuf> handler = findRequestHandler(request.getUri());
    if (handler != null) {
        return handler.handle(request, response);
    } else {
        response.setStatus(HttpResponseStatus.NOT_FOUND);
        return response.close();
    }
}
 
开发者ID:jscattergood,项目名称:WeatherAlarm,代码行数:11,代码来源:HttpRequestHandler.java

示例6: handleTest

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

    ByteBuf byteBuf = UnpooledByteBufAllocator.DEFAULT.buffer();
    byteBuf.writeBytes("test".getBytes(Charset.defaultCharset()));

    response.write(byteBuf);
    return response.close();
}
 
开发者ID:schibsted,项目名称:triathlon,代码行数:10,代码来源:RxTestServer.java

示例7: respondWithServiceResponse

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
private Observable<? extends Void> respondWithServiceResponse(NettyRequestWrapper request, HttpServerResponse<ByteBuf> response, FoundHandlerDefinition handlerDefinition) {
  HandlerDefinition currentHandler = handlerDefinition.getHandlerDefinition();
  request.withPathParams(handlerDefinition.getMatchResult().getPathParams());

  RestResponse handlerResponse = handleService(request, currentHandler);
  responseWriter.writeResponse(handlerResponse, response, currentHandler);

  return response.close(false);
}
 
开发者ID:adrobisch,项目名称:nibbler,代码行数:10,代码来源:NettyServiceRequestHandler.java

示例8: handleUpdateRecommendationsForUser

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
private Observable<Void> handleUpdateRecommendationsForUser(HttpServerRequest<ByteBuf> request, final HttpServerResponse<ByteBuf> response) {
    System.out.println("HTTP request -> update recommendations for user: " + request.getPath());
    final String userId = userIdFromPath(request.getPath());
    if (userId == null) {
        response.setStatus(HttpResponseStatus.BAD_REQUEST);
        return response.close();
    }
    return request.getContent().flatMap(new Func1<ByteBuf, Observable<Void>>() {
        @Override
        public Observable<Void> call(ByteBuf byteBuf) {
            String movieId = byteBuf.toString(Charset.defaultCharset());
            System.out.println(format("    updating: {user=%s, movie=%s}", userId, movieId));
            synchronized (this) {
                Set<String> recommendations;
                if (userRecommendations.containsKey(userId)) {
                    recommendations = userRecommendations.get(userId);
                } else {
                    recommendations = new ConcurrentSet<String>();
                    userRecommendations.put(userId, recommendations);
                }
                recommendations.add(movieId);
            }
            response.setStatus(HttpResponseStatus.OK);
            return response.close();
        }
    });
}
 
开发者ID:Netflix,项目名称:ribbon,代码行数:28,代码来源:RxMovieServer.java

示例9: handle

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
@Override
public Observable<Void> handle(HttpServerRequest<I> request, HttpServerResponse<O> response) {
    HttpKeyEvaluationContext context = new HttpKeyEvaluationContext(response.getChannel());
    for (Route route : routes) {
        if (route.key.apply(request, context)) {
            return route.getHandler().handle(request, response);
        }
    }

    // None of the routes matched.
    response.setStatus(HttpResponseStatus.NOT_FOUND);
    return response.close();
}
 
开发者ID:Netflix,项目名称:karyon,代码行数:14,代码来源:SimpleUriRouter.java

示例10: sayHello

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
public Observable<Void> sayHello(HttpServerResponse<ByteBuf> response) {
    JSONObject content = new JSONObject();
    try {
        content.put("Message", "Hello from Netflix OSS");
        response.write(content.toString(), StringTransformer.DEFAULT_INSTANCE);
        return response.close();
    } catch (JSONException e) {
        logger.error("Error creating json response.", e);
        return Observable.error(e);
    }
}
 
开发者ID:Netflix,项目名称:karyon,代码行数:12,代码来源:HelloWorldEndpoint.java

示例11: respondWithStatusAndMessage

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
private Observable<Void> respondWithStatusAndMessage(HttpServerResponse<ByteBuf> response, HttpResponseStatus status, Optional<String> message) {
  response.setStatus(status);
  response.writeString(message.orElse(""));
  response.getHeaders().set(Header.ContentType.name(), MediaType.TEXT_PLAIN.contentType());
  return response.close();
}
 
开发者ID:adrobisch,项目名称:nibbler,代码行数:7,代码来源:NettyServiceRequestHandler.java

示例12: handle

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
@Override
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
    response.setStatus(HttpResponseStatus.OK);
    return response.close();
}
 
开发者ID:Netflix,项目名称:Prana,代码行数:6,代码来源:HealthCheckHandlerTest.java

示例13: handle

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
@Override
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
    int httpStatus = healthCheckHandler.getStatus();
    response.setStatus(HttpResponseStatus.valueOf(httpStatus));
    return response.close();
}
 
开发者ID:Netflix,项目名称:karyon,代码行数:7,代码来源:HealthCheckEndpoint.java

示例14: handle

import io.reactivex.netty.protocol.http.server.HttpServerResponse; //导入方法依赖的package包/类
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
    response.flushOnlyOnChannelReadComplete(true);
    response.getHeaders().set(HttpHeaders.Names.CONTENT_LENGTH, HELLO_WORLD_LENGTH_STR);
    response.write(response.getAllocator().buffer(HELLO_WORLD_LENGTH).writeBytes(MSG));
    return response.close();
}
 
开发者ID:Netflix-Skunkworks,项目名称:WSPerfLab,代码行数:7,代码来源:TestRouteHello.java


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