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


Java HttpServer.listen方法代码示例

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


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

示例1: EmulatorLaunchpad

import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
/**
 * Constructor.
 *
 * @param httpPort The HTTP port on which the emulator should run.
 */
public EmulatorLaunchpad(int httpPort) {

    vertx = VertxFactory.newVertx();

    // Static files
    HttpServer httpServer = vertx.createHttpServer();
    httpServer.requestHandler(new WebResourceHandler());

    // Eventbus bridge
    JsonObject bridgeConfig = new JsonObject().putString("prefix", EVENTBUS_ADDRESS);
    JsonArray credentialsPermitAll = new JsonArray().add(new JsonObject());
    vertx.createSockJSServer(httpServer).bridge(bridgeConfig, credentialsPermitAll, credentialsPermitAll);
    vertx.eventBus().registerLocalHandler(EVENTBUS_SERVER_HANDLER_ID, eventBusHandler);

    System.out.println("Launchpad emulator is ready on http://localhost:" + httpPort + "/");
    httpServer.listen(httpPort);
}
 
开发者ID:OlivierCroisier,项目名称:LP4J,代码行数:23,代码来源:EmulatorLaunchpad.java

示例2: startServer

import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
/**
 * Start an embedded HTTP server
 *
 * @param activeProfilers The active profilers
 * @param port The port on which to bind the server
 */
public static void startServer(final Map<String, ScheduledFuture<?>> runningProfilers, final Map<String, Profiler> activeProfilers, final int port, final AtomicReference<Boolean> isRunning, final List<String> errors) {
    final HttpServer server = VERTX.createHttpServer();
    server.requestHandler(RequestHandler.getMatcher(runningProfilers, activeProfilers, isRunning, errors));
    server.listen(port, new Handler<AsyncResult<HttpServer>>() {
        @Override
        public void handle(AsyncResult<HttpServer> event) {
            if (event.failed()) {
                server.close();
                startServer(runningProfilers, activeProfilers, port + 1, isRunning, errors);
            } else if (event.succeeded()) {
                LOGGER.info("Profiler server started on port " + port);
            }
        }
    });
}
 
开发者ID:etsy,项目名称:statsd-jvm-profiler,代码行数:22,代码来源:ProfilerServer.java

示例3: startSockJSServer

import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
private void startSockJSServer() {
    HttpServer httpServer = vertx.createHttpServer();

    SockJSServer sockJSServer = vertx.createSockJSServer(httpServer);

    JsonObject config = new JsonObject().putString("prefix", "/chat");
    sockJSServer.installApp(config, new Handler<SockJSSocket>() {
        public void handle(final SockJSSocket sock) {
            vertx.sharedData().getSet(SHARED_DATA_SOCKET_IDS).add(sock.writeHandlerID());
            sock.endHandler(new Handler<Void>() {
                @Override
                public void handle(Void aVoid) {
                    vertx.sharedData().getSet(SHARED_DATA_SOCKET_IDS).remove(sock.writeHandlerID());
                }
            });
        }
    });
    httpServer.listen(8083);
}
 
开发者ID:bytor99999,项目名称:SpringInAVertxWorld,代码行数:20,代码来源:ChatVerticle.java

示例4: createHttpServer

import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
private void createHttpServer(int listenPort, final String expectedResponseMediaType, final String expectedResponse) {
	HttpServer server = vertx.createHttpServer();
	server.requestHandler(new Handler<HttpServerRequest>() {

		@Override
		public void handle(final HttpServerRequest request) {
			request.bodyHandler(new Handler<Buffer>() {
				@Override
				public void handle(Buffer body) {
					String contentType = request.headers().get("Content-Type");
					assertEquals(expectedResponseMediaType, contentType);
					assertEquals(expectedResponse, body.toString());
					testComplete();
				}
			});
		}
	});
	server.listen(listenPort);
}
 
开发者ID:j2ro,项目名称:mod-http-event-bus-bridge,代码行数:20,代码来源:MessageSendWithReplyTest.java

示例5: bridge

import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
public void bridge(final CountingCompletionHandler<Void> countDownLatch) {
  HttpServer server = vertx.createHttpServer();
  SockJSServer sjsServer = vertx.createSockJSServer(server).setHook(hook);
  JsonObject empty = new JsonObject();
  JsonArray all = new JsonArray().add(empty);
  JsonArray inboundPermitted = config.getArray("inbound_permitted", all);
  JsonArray outboundPermitted = config.getArray("outbound_permitted", all);

  sjsServer.bridge(config.getObject("sjs_config", new JsonObject()
      .putString("prefix", "/channel")), inboundPermitted, outboundPermitted, config.getObject(
      "bridge_config", empty));

  countDownLatch.incRequired();
  server.listen(config.getInteger("port", 1986), config.getString("host", "0.0.0.0"),
      new AsyncResultHandler<HttpServer>() {
        @Override
        public void handle(AsyncResult<HttpServer> ar) {
          if (!ar.succeeded()) {
            countDownLatch.failed(ar.cause());
          } else {
            countDownLatch.complete();
          }
        }
      });
}
 
开发者ID:goodow,项目名称:realtime-channel,代码行数:26,代码来源:ChannelBridge.java

示例6: start

import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
public void start() {

        RouteMatcher routeMatcher = new RouteMatcher();

        // HTTP server
        HttpServer httpServer = vertx.createHttpServer();
        httpServer.requestHandler(routeMatcher);

        // SockJS server
        JsonArray permitted = new JsonArray();
        permitted.add(new JsonObject()); // Let everything through
        SockJSServer sockJSServer = vertx.createSockJSServer(httpServer);
        sockJSServer.bridge(new JsonObject().putString("prefix", "/eventbus"), permitted, permitted);

        httpServer.listen(7777);

        System.out.println("Vert.X Core UP");
    }
 
开发者ID:rvillars,项目名称:bookapp-cqrs,代码行数:19,代码来源:VertXBean.java

示例7: start

import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
@Override
public void start() {
    final HttpServer httpServer = vertx.createHttpServer();
    final SockJSServer sockJSServer = vertx.createSockJSServer(httpServer);
    final JsonObject config = new JsonObject().putString("prefix", "/echo");
    sockJSServer.installApp(config, new Handler<SockJSSocket>() {
        public void handle(final SockJSSocket sock) {

        }
    });
    httpServer.listen(8080);
}
 
开发者ID:bwinparty,项目名称:HelloVertX,代码行数:13,代码来源:WebSocketVerticle.java

示例8: start

import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
@Override
public void start() {
    System.out.println("START WSEntryVerticle  THREAD: " + Thread.currentThread() + "  this:" + this);
    HttpServer server = startServer();
    registerWebsocketHandler(server);
    server.listen(PORT_NUMER);
}
 
开发者ID:amoAHCP,项目名称:vert.x-spring-microservice-demo,代码行数:8,代码来源:WSEntryVerticle.java

示例9: start

import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
@Override
public void start() {
    final HttpServer httpServer = startServer();
    registerEventBusMessageHandler();
    registerWebsocketHandler(httpServer);
    httpServer.listen(PORT_NUMER);
    this.container.logger().info("started : " + this);
}
 
开发者ID:amoAHCP,项目名称:vertx-samples,代码行数:9,代码来源:RemoteDrawingServer.java

示例10: start

import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
@Override
public void start() {
	// Create a portal server
	Server server = new DefaultServer();
	
	// This action is equivalent to socket handler of server.js in the portal repo
	// https://github.com/flowersinthesand/portal/blob/1.1.1/test/server.js#L593-L611
	server.socketAction(new Action<Socket>() {
		@Override
		public void on(final Socket socket) {
			socket.on("echo", new Action<Object>() {
				@Override
				public void on(Object data) {
					socket.send("echo", data);
				}
			})
			.on("disconnect", new VoidAction() {
				@Override
				public void on() {
					new Timer(true).schedule(new TimerTask() {
						@Override
						public void run() {
							socket.close();
						}
					}, 100);
				}
			})
			.on("reply-by-server", new Action<Reply<Boolean>>() {
				@Override
				public void on(Reply<Boolean> reply) {
					if (reply.data()) {
						reply.done(reply.data());
					} else {
						reply.fail(reply.data());
					}
				}
			})
			.on("reply-by-client", new VoidAction() {
				@Override
				public void on() {
					socket.send("reply-by-client", 1, new Action<String>() {
						@Override
						public void on(String type) {
							socket.send(type);
						}
					});
				}
			});
		}
	});
	
	HttpServer httpServer = vertx.createHttpServer();
	
	// Attach request handler and WebSocket handler first before installation
	httpServer.requestHandler(new Handler<HttpServerRequest>() {
		@Override
		public void handle(HttpServerRequest req) {
			String filename = req.path().equals("/") ? "/index.html" : req.path();
			req.response().sendFile("webapp" + filename);
		}
	});
	
	// Deliver HttpExchange and WebSocket produced by Vert.x to the portal server
	new VertxBridge(httpServer, "/test").httpAction(server.httpAction()).websocketAction(server.websocketAction());
	
	// Start a web server after installation
	httpServer.listen(8080);
}
 
开发者ID:flowersinthesand,项目名称:portal-java-examples,代码行数:69,代码来源:Bootstrap.java

示例11: start

import org.vertx.java.core.http.HttpServer; //导入方法依赖的package包/类
@Override
public void start() {

    address = this.getClass().getName();

    logger = container.logger();
    JsonObject appConfig = container.config();
    HttpServer server = vertx.createHttpServer();
    server.requestHandler(this);

    start(appConfig, server);

    int serverPort = appConfig.getInteger("port", 8080).intValue();

    server.listen(serverPort);

    postStart(appConfig, server);

}
 
开发者ID:stalk-io,项目名称:stalk-server,代码行数:20,代码来源:Server.java


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