本文整理汇总了Java中io.reactivex.netty.protocol.http.server.HttpServerRequest类的典型用法代码示例。如果您正苦于以下问题:Java HttpServerRequest类的具体用法?Java HttpServerRequest怎么用?Java HttpServerRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpServerRequest类属于io.reactivex.netty.protocol.http.server包,在下文中一共展示了HttpServerRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import io.reactivex.netty.protocol.http.server.HttpServerRequest; //导入依赖的package包/类
/**
* Setups the test environment.
*
* @throws Exception if any error occurs
*/
@Before
public void setUp() throws Exception {
instance = new HealthCheckTaskExecutor();
server = RxNetty.createHttpServer(PORT, new RequestHandler<ByteBuf, ByteBuf>() {
@Override
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
if ("/health".equals(request.getPath())) {
return response.writeStringAndFlush("{\"status\": \"UP\", \"service\": {\"status\": \"UP\"}}");
}
response.setStatus(HttpResponseStatus.NOT_FOUND);
return response.close();
}
}).start();
}
示例2: makeHandler
import io.reactivex.netty.protocol.http.server.HttpServerRequest; //导入依赖的package包/类
@Override
public RequestHandler makeHandler(HttpServerRequest<ByteBuf> request) {
HttpMethod method = request.getHttpMethod();
TusRequest tusRequest = new RxNettyTusRequestAdapter(request);
if (method.equals(HttpMethod.OPTIONS)) {
return new OptionHandler(options, tusRequest);
}
if (method.equals(HttpMethod.POST)) {
return new PostHandler(options, tusRequest, pool);
}
if (method.equals(HttpMethod.HEAD)) {
return new HeadHandler(options, tusRequest, pool);
}
if (method.equals(HttpMethod.PATCH)) {
return new PatchHandler(options, tusRequest, pool);
}
return new NotImplementedHandler();
}
示例3: setup
import io.reactivex.netty.protocol.http.server.HttpServerRequest; //导入依赖的package包/类
@Setup
public void setup() {
server = RxNetty.createHttpServer(SERVER_PORT, new RequestHandler<ByteBuf, ByteBuf>() {
public rx.Observable handle(HttpServerRequest<ByteBuf> request,
HttpServerResponse<ByteBuf> response) {
return response.flush();
}
});
server.start();
client = new OkHttpClient();
client.setRetryOnConnectionFailure(false);
okFeign = Feign.builder()
.client(new feign.okhttp.OkHttpClient(client))
.target(FeignTestInterface.class, "http://localhost:" + SERVER_PORT);
queryRequest = new Request.Builder()
.url("http://localhost:" + SERVER_PORT + "/?Action=GetUser&Version=2010-05-08&limit=1")
.build();
}
示例4: getIntervalObservable
import io.reactivex.netty.protocol.http.server.HttpServerRequest; //导入依赖的package包/类
private Observable<Void> getIntervalObservable(HttpServerRequest<?> request, final HttpServerResponse<ServerSentEvent> response) {
HttpRequest simpleRequest = new HttpRequest(request.getQueryParameters());
return getEvents(simpleRequest)
.flatMap(event -> {
System.out.println("Writing SSE event: " + event);
ByteBuf data = response.getAllocator().buffer().writeBytes(( event + "\n").getBytes());
ServerSentEvent sse = new ServerSentEvent(data);
return response.writeAndFlush(sse);
}).materialize()
.takeWhile(notification -> {
if (notification.isOnError()) {
System.out.println("Write to client failed, stopping response sending.");
notification.getThrowable().printStackTrace(System.err);
}
return !notification.isOnError();
})
.map((Func1<Notification<Void>, Void>) notification -> null);
}
示例5: handle
import io.reactivex.netty.protocol.http.server.HttpServerRequest; //导入依赖的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();
}
示例6: testHandleRequestForAlarm
import io.reactivex.netty.protocol.http.server.HttpServerRequest; //导入依赖的package包/类
@Test
public void testHandleRequestForAlarm() throws Exception {
IWeatherAlarmService alarmService = getMockAlarmService();
WeatherAlarmEndpoint alarmEndpoint = new WeatherAlarmEndpoint();
alarmEndpoint.setAlarmService(alarmService);
WeatherAlarm alarm = alarmService.getAlarms().get(0);
Capture<byte[]> written = EasyMock.newCapture();
Capture<HttpResponseStatus> status = EasyMock.newCapture();
String uri = URI + "/" + URLEncoder.encode(alarm.getName(), "UTF-8");
HttpServerRequest<ByteBuf> request = createMockHttpServerRequest(HttpMethod.GET, uri, Observable.empty());
HttpServerResponse<ByteBuf> response = createMockHttpResponse(status, written);
alarmEndpoint.handle(request, response);
byte[] expected = new ObjectMapper().writeValueAsBytes(alarm);
Assert.assertTrue("Unexpected value written", Arrays.equals(expected, written.getValue()));
}
示例7: testHandleRequestForAddAlarm
import io.reactivex.netty.protocol.http.server.HttpServerRequest; //导入依赖的package包/类
@Test
public void testHandleRequestForAddAlarm() throws Exception {
IWeatherAlarmService alarmService = getEmptyAlarmService();
WeatherAlarmEndpoint alarmEndpoint = new WeatherAlarmEndpoint();
alarmEndpoint.setAlarmService(alarmService);
WeatherAlarm alarm = createWeatherAlarm();
Capture<byte[]> written = EasyMock.newCapture();
Capture<HttpResponseStatus> status = EasyMock.newCapture();
HttpServerRequest<ByteBuf> request = createMockHttpServerRequest(HttpMethod.PUT, URI,
createContent(new ObjectMapper().writeValueAsBytes(alarm)));
HttpServerResponse<ByteBuf> response = createMockHttpResponse(status, written);
alarmEndpoint.handle(request, response);
Assert.assertTrue("Alarm not added from list " + alarm, alarmService.getAlarm(alarm.getName()) != null);
}
示例8: testHandleRequestForDeleteAlarm
import io.reactivex.netty.protocol.http.server.HttpServerRequest; //导入依赖的package包/类
@Test
public void testHandleRequestForDeleteAlarm() throws Exception {
IWeatherAlarmService alarmService = getMockAlarmService();
WeatherAlarmEndpoint alarmEndpoint = new WeatherAlarmEndpoint();
alarmEndpoint.setAlarmService(alarmService);
WeatherAlarm alarm = alarmService.getAlarms().get(0);
Capture<byte[]> written = EasyMock.newCapture();
Capture<HttpResponseStatus> status = EasyMock.newCapture();
String encodedAlarmName = URLEncoder.encode(alarm.getName(), "UTF-8");
String uri = URI + "/" + encodedAlarmName;
HttpServerRequest<ByteBuf> request = createMockHttpServerRequest(HttpMethod.DELETE, uri, Observable.empty());
HttpServerResponse<ByteBuf> response = createMockHttpResponse(status, written);
alarmEndpoint.handle(request, response);
Assert.assertTrue("Alarm not deleted from list " + alarm, !alarmService.getAlarms().contains(alarm));
}
示例9: postApps
import io.reactivex.netty.protocol.http.server.HttpServerRequest; //导入依赖的package包/类
/**
* This endpoint will forward the post data to the selected marathon server.
*
* TODO: Move logic from here
*
* @param request
* @param response
* @return response to be send to the caller
*/
@Override
public Observable<Void> postApps(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
return triathlonService.parseJson(request.getContent())
.flatMap(this::matchDataCenter)
.flatMap(content -> {
response.write(content);
return response.close();
})
.onErrorResumeNext(throwable -> {
LOGGER.info("Service ERROR");
response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
return response.close();
})
.doOnCompleted(() -> response.close(true));
}
示例10: createServer
import io.reactivex.netty.protocol.http.server.HttpServerRequest; //导入依赖的package包/类
public HttpServer<ByteBuf, ByteBuf> createServer() {
HttpServer<ByteBuf, ByteBuf> server = RxNetty.newHttpServerBuilder(port, new RequestHandler<ByteBuf, ByteBuf>() {
@Override
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, final HttpServerResponse<ByteBuf> response) {
if (request.getPath().contains("/v2/apps")) {
if (request.getHttpMethod().equals(HttpMethod.POST)) {
return handleTest(request, response);
}
}
response.setStatus(HttpResponseStatus.NOT_FOUND);
return response.close();
}
}).pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpServerConfigurator()).enableWireLogging(LogLevel.ERROR).build();
System.out.println("RxTetstServer server started...");
return server;
}
示例11: providesKaryonTransport
import io.reactivex.netty.protocol.http.server.HttpServerRequest; //导入依赖的package包/类
@Provides
public HttpServer providesKaryonTransport() {
SimpleUriRouter simpleUriRouter = new SimpleUriRouter();
simpleUriRouter.addUri("/foo", new RequestHandler() {
@Override
public Observable<Void> handle(HttpServerRequest request, HttpServerResponse response) {
response.writeAndFlush("Hello World", StringTransformer.DEFAULT_INSTANCE);
response.setStatus(HttpResponseStatus.OK);
return Observable.empty();
}
@Override
public Observable<Void> handle(Object input, Object output) {
return Observable.empty();
}
});
return KaryonTransport.newHttpServer(8888, simpleUriRouter);
}
示例12: handleRequest
import io.reactivex.netty.protocol.http.server.HttpServerRequest; //导入依赖的package包/类
@Override
protected Observable<Void> handleRequest(HttpServerRequest<?> request, HttpServerResponse<ServerSentEvent> response) {
List<String> videoIds = request.getQueryParameters().get("videoId");
int latency = 1;
if (Random.randomIntFrom0to100() > 80) {
latency = 10;
}
return Observable.from(videoIds).map(videoId -> {
Map<String, Object> video = new HashMap<>();
video.put("videoId", videoId);
video.put("position", (int) (Math.random() * 5000));
return video;
}).flatMap(video -> response.writeStringAndFlush("data: " + SimpleJson.mapToJson(video) + "\n"))
.delay(latency, TimeUnit.MILLISECONDS).doOnCompleted(response::close); // simulate latency
}
示例13: handleRequest
import io.reactivex.netty.protocol.http.server.HttpServerRequest; //导入依赖的package包/类
@Override
protected Observable<Void> handleRequest(HttpServerRequest<?> request, HttpServerResponse<ServerSentEvent> response) {
return request.getContent().flatMap(i -> {
List<String> ips = request.getQueryParameters().get("ip");
Map<String, Object> data = new HashMap<>();
for (String ip : ips) {
Map<String, Object> ip_data = new HashMap<>();
ip_data.put("country_code", "GB");
ip_data.put("longitude", "-0.13");
ip_data.put("latitude", "51.5");
data.put(ip, ip_data);
}
return response.writeStringAndFlush("data: " + SimpleJson.mapToJson(data) + "\n")
.doOnCompleted(response::close);
}).delay(10, TimeUnit.MILLISECONDS);
}
示例14: handleRequest
import io.reactivex.netty.protocol.http.server.HttpServerRequest; //导入依赖的package包/类
@Override
protected Observable<Void> handleRequest(HttpServerRequest<?> request, HttpServerResponse<ServerSentEvent> response) {
List<String> userIds = request.getQueryParameters().get("userId");
if (userIds == null || userIds.size() == 0) {
return writeError(request, response, "At least one parameter of 'userId' must be included.");
}
return Observable.from(userIds).map(userId -> {
Map<String, Object> user = new HashMap<>();
user.put("userId", userId);
user.put("name", "Name Here");
user.put("other_data", "goes_here");
return user;
}).flatMap(user -> response.writeStringAndFlush("data: " + SimpleJson.mapToJson(user) + "\n")
.doOnCompleted(response::close))
.delay(((long) (Math.random() * 500) + 500), TimeUnit.MILLISECONDS); // simulate latency
}
示例15: handle
import io.reactivex.netty.protocol.http.server.HttpServerRequest; //导入依赖的package包/类
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, HttpServerResponse<ByteBuf> response) {
List<String> userId = request.getQueryParameters().get("userId");
if (userId == null || userId.size() != 1) {
return StartGatewayServer.writeError(request, response, "A single 'userId' is required.");
}
return new UserCommand(userId).observe().flatMap(user -> {
Observable<Map<String, Object>> catalog = new PersonalizedCatalogCommand(user).observe()
.flatMap(catalogList -> catalogList.videos().<Map<String, Object>> flatMap(
video -> {
Observable<Bookmark> bookmark = new BookmarkCommand(video).observe();
Observable<Rating> rating = new RatingsCommand(video).observe();
Observable<VideoMetadata> metadata = new VideoMetadataCommand(video).observe();
return Observable.zip(bookmark, rating, metadata, (b, r, m) -> combineVideoData(video, b, r, m));
}));
Observable<Map<String, Object>> social = new SocialCommand(user).observe().map(s -> {
return s.getDataAsMap();
});
return Observable.merge(catalog, social);
}).flatMap(data -> {
String json = SimpleJson.mapToJson(data);
return response.writeStringAndFlush("data: " + json + "\n");
});
}