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


Java HttpServer类代码示例

本文整理汇总了Java中reactor.ipc.netty.http.server.HttpServer的典型用法代码示例。如果您正苦于以下问题:Java HttpServer类的具体用法?Java HttpServer怎么用?Java HttpServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: httpRespondsEmpty

import reactor.ipc.netty.http.server.HttpServer; //导入依赖的package包/类
@Test
public void httpRespondsEmpty() {
	NettyContext server =
			HttpServer.create(0)
			          .newRouter(r ->
			              r.post("/test/{param}", (req, res) -> Mono.empty()))
			          .block(Duration.ofSeconds(30));

	HttpClient client =
			HttpClient.create("localhost", server.address().getPort());

	Mono<ByteBuf> content = client
			            .post("/test/World", req -> req.header("Content-Type", "text/plain")
			                                           .sendString(Mono.just("Hello")
			                                           .log("client-send")))
			            .flatMap(res -> res.receive()
			                               .log("client-received")
			                               .next())
			            .doOnError(t -> System.err.println("Failed requesting server: " + t.getMessage()));

	StepVerifier.create(content)
			    .expectComplete()
			    .verify(Duration.ofSeconds(5000));

	server.dispose();
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:27,代码来源:HttpTests.java

示例2: startContentServer

import reactor.ipc.netty.http.server.HttpServer; //导入依赖的package包/类
@Test
@Ignore
public void startContentServer() throws Exception {
	Random random = new Random(0);
	byte[] content = new byte[1024 * 10];
	random.nextBytes(content);

	HttpServer server = HttpServer.create(options -> options.host("0.0.0.0")
	                                                        .port(CONTENT_SERVER_PORT)
	                                                        .option(ChannelOption.SO_LINGER,
			                                                        -1));

	server.startRouterAndAwait(routes -> routes.get("/**",
			(req, res) -> res.header("Content-length", String.valueOf(content.length))
			                 .header("Content-type", "application/octet-stream")
			                 .header("Connection", "Close")
			                 .sendByteArray(Flux.just(content))));

}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:20,代码来源:ProxyClientIssue.java

示例3: WebSocketSubscriber

import reactor.ipc.netty.http.server.HttpServer; //导入依赖的package包/类
/**
 * Creates a new subscriber which receives {@link Serializable} data and emits it on a websocket.
 *
 * @param writer The writer for serializing received Serializables
 * @param uri    The URI  of the websocket (eg. '/route').
 * @param port   The port of the websocket (eg. 1337).
 */
public WebSocketSubscriber(
    final Function<T, String> writer,
    final String uri,
    final int port) {
  this.writer = writer;
  HttpServer.create(port)
      .newHandler((in, out) ->
          in.uri().equals(uri)
              ? out.sendWebsocket((inboundWebsocket, outboundWebsocket) ->
              outboundWebsocket
                  .options(NettyPipeline.SendOptions::flushOnEach)
                  .sendString(this.outputPublisher))
              : out.sendNotFound())
      .subscribeOn(Schedulers.single())
      .subscribe();
}
 
开发者ID:delta-leonis,项目名称:zosma,代码行数:24,代码来源:WebSocketSubscriber.java

示例4: setupFakeProtocolListener

import reactor.ipc.netty.http.server.HttpServer; //导入依赖的package包/类
private void setupFakeProtocolListener() throws Exception {
	broadcaster = TopicProcessor.create();
	final Processor<List<String>, List<String>> processor =
			WorkQueueProcessor.<List<String>>builder().autoCancel(false).build();
	Flux.from(broadcaster)
	    .buffer(5)
	    .subscribe(processor);

	httpServer = HttpServer.create(0)
	                       .newRouter(r -> r.get("/data",
			                       (req, resp) -> resp.options(NettyPipeline.SendOptions::flushOnEach)
			                                          .send(Flux.from(processor)
			                                                    .log("server")
			                                                    .timeout(Duration.ofSeconds(
					                                                    2),
					                                                    Flux.empty())
			                                                    .concatWith(Flux.just(
					                                                    new ArrayList<>()))
			                                                    .map(new DummyListEncoder(
					                                                    resp.alloc()
			                                                    )))))
	                       .block(Duration.ofSeconds(30));
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:24,代码来源:ClientServerHttpTests.java

示例5: doTestGzip

import reactor.ipc.netty.http.server.HttpServer; //导入依赖的package包/类
private void doTestGzip(boolean gzipEnabled) {
	String expectedResponse = gzipEnabled ? "gzip" : "no gzip";
	NettyContext server = HttpServer.create(0)
	        .newHandler((req,res) -> res.sendString(
	                Mono.just(req.requestHeaders().get(HttpHeaderNames.ACCEPT_ENCODING, "no gzip"))))
	        .block(Duration.ofSeconds(30));
	StepVerifier.create(
	        HttpClient.create(ops -> ops.port(server.address().getPort()).compression(gzipEnabled))
	                  .get("/")
	                  .flatMap(r -> r.receive()
	                                 .asString()
	                                 .elementAt(0)
	                                 .zipWith(Mono.just(r)))
	        )
	            .expectNextMatches(tuple -> {
	                tuple.getT2().dispose();
	                return expectedResponse.equals(tuple.getT1());
	            })
	            .expectComplete()
	            .verify(Duration.ofSeconds(30));

	server.dispose();
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:24,代码来源:HttpClientTest.java

示例6: sshExchangeAbsoluteGet

import reactor.ipc.netty.http.server.HttpServer; //导入依赖的package包/类
@Test
public void sshExchangeAbsoluteGet() throws CertificateException, SSLException {
	SelfSignedCertificate ssc = new SelfSignedCertificate();
	SslContext sslServer = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
	SslContext sslClient = SslContextBuilder.forClient()
	                                        .trustManager(ssc.cert()).build();

	NettyContext context =
			HttpServer.create(opt -> opt.sslContext(sslServer))
			          .newHandler((req, resp) -> resp.sendString(Flux.just("hello ", req.uri())))
			          .block();

	HttpClientResponse response = HttpClient.create(
			opt -> applyHostAndPortFromContext(opt, context)
					.sslContext(sslClient))
			.get("/foo").block();
	context.dispose();
	context.onClose().block();

	String responseString = response.receive().aggregate().asString(CharsetUtil.UTF_8).block();
	assertThat(responseString).isEqualTo("hello /foo");
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:23,代码来源:HttpClientTest.java

示例7: simpleTest

import reactor.ipc.netty.http.server.HttpServer; //导入依赖的package包/类
@Test
public void simpleTest() {
	httpServer = HttpServer.create(0)
	                       .newHandler((in, out) -> out.sendWebsocket((i, o) -> o.sendString(
			                       Mono.just("test"))))
	                       .block(Duration.ofSeconds(30));

	String res = HttpClient.create(httpServer.address()
	                                  .getPort())
	                .get("/test",
			                out -> out.addHeader("Authorization", auth)
			                          .sendWebsocket())
	                .flatMapMany(in -> in.receive()
	                                 .asString())
	                .log()
	                .collectList()
	                .block(Duration.ofSeconds(30))
	                .get(0);

	Assert.assertThat(res, is("test"));
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:22,代码来源:WebsocketTest.java

示例8: simpleSubprotocolServerNoSubprotocol

import reactor.ipc.netty.http.server.HttpServer; //导入依赖的package包/类
@Test
public void simpleSubprotocolServerNoSubprotocol() throws Exception {
	httpServer = HttpServer.create(0)
	                                    .newHandler((in, out) -> out.sendWebsocket((i, o) -> o.sendString(
			                                    Mono.just("test"))))
	                                    .block(Duration.ofSeconds(30));

	StepVerifier.create(
			HttpClient.create(
					httpServer.address().getPort())
			          .get("/test",
					          out -> out.addHeader("Authorization", auth)
					                    .sendWebsocket("SUBPROTOCOL,OTHER"))
			          .flatMapMany(in -> in.receive().asString())
	)
	            .verifyErrorMessage("Invalid subprotocol. Actual: null. Expected one of: SUBPROTOCOL,OTHER");
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:18,代码来源:WebsocketTest.java

示例9: simpleSubprotocolServerNotSupported

import reactor.ipc.netty.http.server.HttpServer; //导入依赖的package包/类
@Test
public void simpleSubprotocolServerNotSupported() throws Exception {
	httpServer = HttpServer.create(0)
	                       .newHandler((in, out) -> out.sendWebsocket(
			                       "protoA,protoB",
			                       (i, o) -> o.sendString(Mono.just("test"))))
	                       .block(Duration.ofSeconds(30));

	StepVerifier.create(
			HttpClient.create(
					httpServer.address().getPort())
			          .get("/test",
					          out -> out.addHeader("Authorization", auth)
					                    .sendWebsocket("SUBPROTOCOL,OTHER"))
			          .flatMapMany(in -> in.receive().asString())
	)
	            //the SERVER returned null which means that it couldn't select a protocol
	            .verifyErrorMessage("Invalid subprotocol. Actual: null. Expected one of: SUBPROTOCOL,OTHER");
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:20,代码来源:WebsocketTest.java

示例10: simpleSubprotocolServerSupported

import reactor.ipc.netty.http.server.HttpServer; //导入依赖的package包/类
@Test
public void simpleSubprotocolServerSupported() throws Exception {
	httpServer = HttpServer.create(0)
	                       .newHandler((in, out) -> out.sendWebsocket(
			                       "SUBPROTOCOL",
			                       (i, o) -> o.sendString(
					                       Mono.just("test"))))
	                       .block(Duration.ofSeconds(30));

	String res = HttpClient.create(httpServer.address().getPort())
	                       .get("/test",
			                out -> out.addHeader("Authorization", auth)
			                          .sendWebsocket("SUBPROTOCOL,OTHER"))
	                .flatMapMany(in -> in.receive().asString()).log().collectList().block(Duration.ofSeconds(30)).get(0);

	Assert.assertThat(res, is("test"));
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:18,代码来源:WebsocketTest.java

示例11: simpleSubprotocolSelected

import reactor.ipc.netty.http.server.HttpServer; //导入依赖的package包/类
@Test
public void simpleSubprotocolSelected() throws Exception {
	httpServer = HttpServer.create(0)
	                       .newHandler((in, out) -> out.sendWebsocket(
			                       "NOT, Common",
			                       (i, o) -> o.sendString(
					                       Mono.just("SERVER:" + o.selectedSubprotocol()))))
	                       .block(Duration.ofSeconds(30));

	String res = HttpClient.create(httpServer.address().getPort())
	                       .get("/test",
			                out -> out.addHeader("Authorization", auth)
			                          .sendWebsocket("Common,OTHER"))
	                       .map(HttpClientResponse::receiveWebsocket)
	                       .flatMapMany(in -> in.receive().asString()
			                       .map(srv -> "CLIENT:" + in.selectedSubprotocol() + "-" + srv))
	                       .log().collectList().block(Duration.ofSeconds(30)).get(0);

	Assert.assertThat(res, is("CLIENT:Common-SERVER:Common"));
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:21,代码来源:WebsocketTest.java

示例12: noSubprotocolSelected

import reactor.ipc.netty.http.server.HttpServer; //导入依赖的package包/类
@Test
public void noSubprotocolSelected() {
	httpServer = HttpServer.create(0)
	                       .newHandler((in, out) -> out.sendWebsocket((i, o) -> o.sendString(
			                       Mono.just("SERVER:" + o.selectedSubprotocol()))))
	                       .block(Duration.ofSeconds(30));

	String res = HttpClient.create(httpServer.address()
	                                         .getPort())
	                       .get("/test",
			                       out -> out.addHeader("Authorization", auth)
			                                 .sendWebsocket())
	                       .map(HttpClientResponse::receiveWebsocket)
	                       .flatMapMany(in -> in.receive()
	                                        .asString()
	                                        .map(srv -> "CLIENT:" + in.selectedSubprotocol() + "-" + srv))
	                       .log()
	                       .collectList()
	                       .block(Duration.ofSeconds(30))
	                       .get(0);

	Assert.assertThat(res, is("CLIENT:null-SERVER:null"));
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:24,代码来源:WebsocketTest.java

示例13: anySubprotocolSelectsFirstClientProvided

import reactor.ipc.netty.http.server.HttpServer; //导入依赖的package包/类
@Test
public void anySubprotocolSelectsFirstClientProvided() {
	httpServer = HttpServer.create(0)
	                       .newHandler((in, out) -> out.sendWebsocket("proto2,*", (i, o) -> o.sendString(
			                       Mono.just("SERVER:" + o.selectedSubprotocol()))))
	                       .block(Duration.ofSeconds(30));

	String res = HttpClient.create(httpServer.address()
	                                         .getPort())
	                       .get("/test",
			                       out -> out.addHeader("Authorization", auth)
			                                 .sendWebsocket("proto1, proto2"))
	                       .map(HttpClientResponse::receiveWebsocket)
	                       .flatMapMany(in -> in.receive()
	                                        .asString()
	                                        .map(srv -> "CLIENT:" + in.selectedSubprotocol() + "-" + srv))
	                       .log()
	                       .collectList()
	                       .block(Duration.ofSeconds(30))
	                       .get(0);

	Assert.assertThat(res, is("CLIENT:proto1-SERVER:proto1"));
}
 
开发者ID:reactor,项目名称:reactor-netty,代码行数:24,代码来源:WebsocketTest.java

示例14: httpServer

import reactor.ipc.netty.http.server.HttpServer; //导入依赖的package包/类
@Bean public HttpServer httpServer(RouterFunction<?> routerFunction) {
  HttpHandler httpHandler = RouterFunctions.toHttpHandler(routerFunction);
  ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler);
  HttpServer server = HttpServer
      .create(serverConfigBean.getAddress(), serverConfigBean.getPort());
  server.newHandler(adapter);
  return server;
}
 
开发者ID:saintdan,项目名称:spring-webflux-microservices-boilerplate,代码行数:9,代码来源:HttpServerConfig.java

示例15: startReactorServer

import reactor.ipc.netty.http.server.HttpServer; //导入依赖的package包/类
private void startReactorServer() {
    RouterFunction<?> route = routingFunction();
    HttpHandler httpHandler = toHttpHandler(route);

    ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler);
    HttpServer server = HttpServer.create(HOST, PORT);
    server.newHandler(adapter).block();
}
 
开发者ID:aliaksei-lithium,项目名称:spring5demo,代码行数:9,代码来源:ReactorApplication.java


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