org.jboss.resteasy.plugins.server.vertx.VertxRequestHandler Java Examples

The following examples show how to use org.jboss.resteasy.plugins.server.vertx.VertxRequestHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainModule.java    From cassandra-sidecar with Apache License 2.0 6 votes vote down vote up
@Provides
@Singleton
public HttpServer vertxServer(Vertx vertx, Configuration conf, Router router, VertxRequestHandler restHandler)
{
    HttpServerOptions options = new HttpServerOptions().setLogActivity(true);

    if (conf.isSslEnabled())
    {
        options.setKeyStoreOptions(new JksOptions()
                                   .setPath(conf.getKeyStorePath())
                                   .setPassword(conf.getKeystorePassword()))
               .setSsl(conf.isSslEnabled());

        if (conf.getTrustStorePath() != null && conf.getTruststorePassword() != null)
        {
            options.setTrustStoreOptions(new JksOptions()
                                         .setPath(conf.getTrustStorePath())
                                         .setPassword(conf.getTruststorePassword()));
        }
    }

    router.route().pathRegex(".*").handler(rc -> restHandler.handle(rc.request()));

    return vertx.createHttpServer(options)
                .requestHandler(router);
}
 
Example #2
Source File: MainModule.java    From cassandra-sidecar with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
private VertxRequestHandler configureServices(Vertx vertx, HealthService healthService)
{
    VertxResteasyDeployment deployment = new VertxResteasyDeployment();
    deployment.start();
    VertxRegistry r = deployment.getRegistry();

    r.addPerInstanceResource(SwaggerOpenApiResource.class);
    r.addSingletonResource(healthService);

    return new VertxRequestHandler(vertx, deployment);
}
 
Example #3
Source File: VertxRestService.java    From atomix with Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example #4
Source File: ApiVerticle.java    From apiman with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Future<Void> startFuture) {
    Future<Void> superFuture = Future.future();
    Future<HttpServer> listenFuture = Future.future();
    super.start(superFuture);

    CompositeFuture.all(superFuture, listenFuture)
        .setHandler(compositeResult -> {
            if (compositeResult.succeeded()) {
                startFuture.complete(null);
            } else {
                startFuture.fail(compositeResult.cause());
            }
        });

    VertxResteasyDeployment deployment = new VertxResteasyDeployment();
    deployment.start();

    addResources(deployment.getRegistry(),
            new SystemResourceImpl(apimanConfig, engine),
            new ApiResourceImpl(apimanConfig, engine),
            new ClientResourceImpl(apimanConfig, engine),
            new OrgResourceImpl(apimanConfig, engine));

    deployment.getProviderFactory().register(RestExceptionMapper.class);

    VertxRequestHandler resteasyRh = new VertxRequestHandler(vertx, deployment);

    Router router = Router.router(vertx)
                .exceptionHandler(error -> log.error(error.getMessage(), error));

    // Ensure body handler is attached early so that if AuthHandler takes an external action
    // we don't end up losing the body (e.g OAuth2).
    router.route()
        .handler(BodyHandler.create());

    AuthHandler authHandler = AuthFactory.getAuth(vertx, router, apimanConfig);

    router.route("/*")
        .handler(authHandler);

    router.route("/*") // We did the previous stuff, now we call into JaxRS.
        .handler(context -> resteasyRh.handle(new Router2ResteasyRequestAdapter(context)));

    HttpServerOptions httpOptions = new HttpServerOptions();

    if (apimanConfig.isSSL()) {
        httpOptions.setSsl(true)
        .setKeyStoreOptions(
                new JksOptions()
                    .setPath(apimanConfig.getKeyStore())
                    .setPassword(apimanConfig.getKeyStorePassword())
                )
        .setTrustStoreOptions(
                new JksOptions()
                    .setPath(apimanConfig.getTrustStore())
                    .setPassword(apimanConfig.getTrustStorePassword())
                );
        addAllowedSslTlsProtocols(httpOptions);
    } else {
        log.warn("API is running in plaintext mode. Enable SSL in config for production deployments.");
    }

    vertx.createHttpServer(httpOptions)
        .requestHandler(router::accept)
        .listen(apimanConfig.getPort(VERTICLE_TYPE),
                apimanConfig.getHostname(),
                listenFuture.completer());
}