Vertosphere: A Java WebSocket and HTTP server powered by the Atmosphere Framework and the Vert.x Framework.
The easiest way to get started with Vert.x is to download a sample and start it. Or look at the Javadoc. Samples are available here
% unzip vertx-<name>-distribution.jar
% vertx VertxAtmosphere -cp:classes:vertx-<name>-distribution.jar
Samples are the same as then one available in Atmosphere, e.g everything that works with Atmosphere works AS-IT-IS with the Vert.x module.
Download Vert.x extension [) or use Maven
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-vertx</artifactId>
<version>2.0.0</version>
</dependency>
For example, the famous multi-room Chat application in Atmosphere Can be run on top of Vert.x by doing:
public class VertxChatServer extends Verticle {
private static final Logger logger = LoggerFactory.getLogger(VertxChatServer.class);
@Override
public void start() throws Exception {
VertxAtmosphere.Builder b = new VertxAtmosphere.Builder();
HttpServer httpServer = vertx.createHttpServer();
httpServer.requestHandler(new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest req) {
String path = req.path;
if (path.equals("/")) {
path = "/index.html";
}
logger.info("Servicing request {}", path);
req.response.sendFile("src/main/resources" + path);
}
});
b.resource(ChatRoom.class).httpServer(httpServer).url("/chat/:room").build();
httpServer.listen(8080);
}
}
Same for Jersey. You can run any Jersey resource like can be boostrapped by doing
public class VertxJerseyChat extends Verticle {
private static final Logger logger = LoggerFactory.getLogger(VertxJerseyChat.class);
@Override
public void start() throws Exception {
VertxAtmosphere.Builder b = new VertxAtmosphere.Builder();
HttpServer httpServer = vertx.createHttpServer();
httpServer.requestHandler(new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest req) {
String path = req.path;
if (path.equals("/")) {
path = "/index.html";
}
logger.info("Servicing request {}", path);
req.response.sendFile("src/main/resources" + path);
}
});
b.resource(ResourceChat.class)
.initParam(ApplicationConfig.WEBSOCKET_CONTENT_TYPE, "application/json")
.httpServer(httpServer).url("/chat")
.build();
httpServer.listen(8080);
}
}