Search in sources :

Example 1 with VertxRequestHandler

use of org.jboss.resteasy.plugins.server.vertx.VertxRequestHandler in project vertx-examples by vert-x3.

the class Server method start.

@Override
public void start() throws Exception {
    // Build the Jax-RS controller deployment
    VertxResteasyDeployment deployment = new VertxResteasyDeployment();
    deployment.start();
    deployment.getRegistry().addPerInstanceResource(Controller.class);
    // Start the front end server using the Jax-RS controller
    vertx.createHttpServer().requestHandler(new VertxRequestHandler(vertx, deployment)).listen(8080, ar -> {
        System.out.println("Server started on port " + ar.result().actualPort());
    });
}
Also used : VertxRequestHandler(org.jboss.resteasy.plugins.server.vertx.VertxRequestHandler) VertxResteasyDeployment(org.jboss.resteasy.plugins.server.vertx.VertxResteasyDeployment)

Example 2 with VertxRequestHandler

use of org.jboss.resteasy.plugins.server.vertx.VertxRequestHandler in project vertx-examples by vert-x3.

the class Server method start.

@Override
public void start() throws Exception {
    // Build the Jax-RS hello world deployment
    VertxResteasyDeployment deployment = new VertxResteasyDeployment();
    deployment.start();
    deployment.getRegistry().addPerInstanceResource(HelloWorldService.class);
    // Start the front end server using the Jax-RS controller
    vertx.createHttpServer().requestHandler(new VertxRequestHandler(vertx, deployment)).listen(8080, ar -> {
        System.out.println("Server started on port " + ar.result().actualPort());
    });
}
Also used : VertxRequestHandler(org.jboss.resteasy.plugins.server.vertx.VertxRequestHandler) VertxResteasyDeployment(org.jboss.resteasy.plugins.server.vertx.VertxResteasyDeployment)

Example 3 with VertxRequestHandler

use of org.jboss.resteasy.plugins.server.vertx.VertxRequestHandler in project atomix by atomix.

the class VertxRestService method start.

@Override
public CompletableFuture<RestService> start() {
    server = vertx.createHttpServer();
    deployment = new VertxResteasyDeployment();
    deployment.start();
    deployment.getDispatcher().getDefaultContextObjects().put(ClusterMembershipService.class, atomix.getMembershipService());
    deployment.getDispatcher().getDefaultContextObjects().put(ClusterCommunicationService.class, atomix.getCommunicationService());
    deployment.getDispatcher().getDefaultContextObjects().put(ClusterEventService.class, atomix.getEventService());
    deployment.getDispatcher().getDefaultContextObjects().put(PrimitiveFactory.class, atomix.getPrimitivesService());
    deployment.getDispatcher().getDefaultContextObjects().put(PrimitivesService.class, atomix.getPrimitivesService());
    deployment.getDispatcher().getDefaultContextObjects().put(EventManager.class, new EventManager());
    deployment.getDispatcher().getDefaultContextObjects().put(AtomixRegistry.class, atomix.getRegistry());
    final ClassLoader classLoader = atomix.getClass().getClassLoader();
    final String[] whitelistPackages = StringUtils.split(System.getProperty("io.atomix.whitelistPackages"), ",");
    final ClassGraph classGraph = whitelistPackages != null ? new ClassGraph().enableAnnotationInfo().whitelistPackages(whitelistPackages).addClassLoader(classLoader) : new ClassGraph().enableAnnotationInfo().addClassLoader(classLoader);
    try (final ScanResult scanResult = classGraph.scan()) {
        scanResult.getClassesWithAnnotation(AtomixResource.class.getName()).forEach(classInfo -> {
            deployment.getRegistry().addPerInstanceResource(classInfo.loadClass(), "/v1");
        });
    }
    deployment.getDispatcher().getProviderFactory().register(new JacksonProvider(createObjectMapper()));
    server.requestHandler(new VertxRequestHandler(vertx, deployment));
    CompletableFuture<RestService> future = new CompletableFuture<>();
    server.listen(address.port(), address.address(true).getHostAddress(), result -> {
        if (result.succeeded()) {
            open.set(true);
            LOGGER.info("Started");
            future.complete(this);
        } else {
            future.completeExceptionally(result.cause());
        }
    });
    return future;
}
Also used : ScanResult(io.github.classgraph.ScanResult) CompletableFuture(java.util.concurrent.CompletableFuture) VertxRequestHandler(org.jboss.resteasy.plugins.server.vertx.VertxRequestHandler) VertxResteasyDeployment(org.jboss.resteasy.plugins.server.vertx.VertxResteasyDeployment) ClassGraph(io.github.classgraph.ClassGraph) ManagedRestService(io.atomix.rest.ManagedRestService) RestService(io.atomix.rest.RestService)

Aggregations

VertxRequestHandler (org.jboss.resteasy.plugins.server.vertx.VertxRequestHandler)3 VertxResteasyDeployment (org.jboss.resteasy.plugins.server.vertx.VertxResteasyDeployment)3 ManagedRestService (io.atomix.rest.ManagedRestService)1 RestService (io.atomix.rest.RestService)1 ClassGraph (io.github.classgraph.ClassGraph)1 ScanResult (io.github.classgraph.ScanResult)1 CompletableFuture (java.util.concurrent.CompletableFuture)1