Search in sources :

Example 1 with ServerConfig

use of io.neonbee.config.ServerConfig in project neonbee by SAP.

the class NeonBeeTestBase method readServerConfig.

private static ServerConfig readServerConfig(NeonBee neonBee, Path workingDirPath) {
    ServerConfig config = new ServerConfig(readDeploymentOptions(ServerVerticle.class, workingDirPath).getConfig());
    overridePort(neonBee, config);
    return config;
}
Also used : ServerConfig(io.neonbee.config.ServerConfig)

Example 2 with ServerConfig

use of io.neonbee.config.ServerConfig in project neonbee by SAP.

the class ODataV4EndpointTest method provideWorkingDirectoryBuilder.

@Override
protected WorkingDirectoryBuilder provideWorkingDirectoryBuilder(TestInfo testInfo, VertxTestContext testContext) {
    return super.provideWorkingDirectoryBuilder(testInfo, testContext).setCustomTask(root -> {
        // the server verticle should either use strict, cds or loose URI mapping
        String testMethodName = testInfo.getTestMethod().map(Method::getName).orElse(EMPTY);
        UriConversion uriConversion = STRICT;
        if (testMethodName.contains("LooseUriConversion")) {
            uriConversion = LOOSE;
        } else if (testMethodName.contains("CDSUriConversion")) {
            uriConversion = CDS;
        }
        DeploymentOptions opts = WorkingDirectoryBuilder.readDeploymentOptions(ServerVerticle.class, root);
        EndpointConfig epc = new EndpointConfig().setType(ODataV4Endpoint.class.getName()).setAdditionalConfig(new JsonObject().put(CONFIG_URI_CONVERSION, uriConversion.toString()));
        ServerConfig sc = new ServerConfig(opts.getConfig()).setEndpointConfigs(List.of(epc));
        opts.setConfig(sc.toJson());
        WorkingDirectoryBuilder.writeDeploymentOptions(ServerVerticle.class, opts, root);
    });
}
Also used : ServerConfig(io.neonbee.config.ServerConfig) DeploymentOptions(io.vertx.core.DeploymentOptions) UriConversion(io.neonbee.endpoint.odatav4.ODataV4Endpoint.UriConversion) JsonObject(io.vertx.core.json.JsonObject) EndpointConfig(io.neonbee.config.EndpointConfig)

Example 3 with ServerConfig

use of io.neonbee.config.ServerConfig in project neonbee by SAP.

the class DefaultErrorHandlerTest method testGetErrorHandlerDefault.

@Test
@Timeout(value = 2, timeUnit = TimeUnit.SECONDS)
void testGetErrorHandlerDefault(Vertx vertx, VertxTestContext testContext) throws Exception {
    NeonBee neonBee = mock(NeonBee.class);
    ServerConfig config = mock(ServerConfig.class);
    when(config.getErrorHandlerTemplate()).thenReturn("Hodor");
    when(neonBee.getServerConfig()).thenReturn(config);
    when(neonBee.getVertx()).thenReturn(vertx);
    new DefaultErrorHandler().initialize(neonBee).onComplete(testContext.failing(t -> testContext.verify(() -> {
        assertThat(t).isInstanceOf(FileSystemException.class);
        assertThat(t).hasMessageThat().contains("Hodor");
        testContext.completeNow();
    })));
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) NeonBee(io.neonbee.NeonBee) Vertx(io.vertx.core.Vertx) Mockito.when(org.mockito.Mockito.when) FileSystemException(io.vertx.core.file.FileSystemException) Truth.assertThat(com.google.common.truth.Truth.assertThat) VertxExtension(io.vertx.junit5.VertxExtension) Timeout(io.vertx.junit5.Timeout) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ServerConfig(io.neonbee.config.ServerConfig) Mockito.mock(org.mockito.Mockito.mock) ServerConfig(io.neonbee.config.ServerConfig) NeonBee(io.neonbee.NeonBee) Test(org.junit.jupiter.api.Test) Timeout(io.vertx.junit5.Timeout)

Example 4 with ServerConfig

use of io.neonbee.config.ServerConfig in project neonbee by SAP.

the class ServerVerticle method createRouter.

private Future<Router> createRouter(ServerConfig config) {
    // the main router of the server verticle
    Router router = Router.router(vertx);
    // instead of creating new routes, vert.x recommends to add multiple handlers to one route instead. to prevent
    // sequence issues, block scope the variable to prevent using it after the endpoints have been mounted
    Route rootRoute = router.route();
    return createErrorHandler(config.getErrorHandlerClassName(), vertx).compose(errorHandler -> {
        rootRoute.failureHandler(errorHandler);
        rootRoute.handler(new LoggerHandler());
        rootRoute.handler(BodyHandler.create(false));
        rootRoute.handler(new CorrelationIdHandler(config.getCorrelationStrategy()));
        rootRoute.handler(TimeoutHandler.create(SECONDS.toMillis(config.getTimeout()), config.getTimeoutStatusCode()));
        rootRoute.handler(new CacheControlHandler());
        rootRoute.handler(new InstanceInfoHandler());
        createSessionStore(vertx, config.getSessionHandling()).map(SessionHandler::create).ifPresent(sessionHandler -> rootRoute.handler(sessionHandler.setSessionCookieName(config.getSessionCookieName())));
        return succeededFuture(router);
    }).onFailure(e -> LOGGER.error("Router could not be created", e));
}
Also used : Future.succeededFuture(io.vertx.core.Future.succeededFuture) CacheControlHandler(io.neonbee.internal.handler.CacheControlHandler) AsyncHelper(io.neonbee.internal.helper.AsyncHelper) LocalSessionStore(io.vertx.ext.web.sstore.LocalSessionStore) HttpServer(io.vertx.core.http.HttpServer) LoggerFactory(org.slf4j.LoggerFactory) NeonBee(io.neonbee.NeonBee) Router(io.vertx.ext.web.Router) BodyHandler(io.vertx.ext.web.handler.BodyHandler) LoggerHandler(io.neonbee.internal.handler.LoggerHandler) SessionHandling(io.neonbee.config.ServerConfig.SessionHandling) TimeoutHandler(io.vertx.ext.web.handler.TimeoutHandler) Endpoint(io.neonbee.endpoint.Endpoint) SessionHandler(io.vertx.ext.web.handler.SessionHandler) EndpointConfig(io.neonbee.config.EndpointConfig) ServerConfig(io.neonbee.config.ServerConfig) Route(io.vertx.ext.web.Route) InstanceInfoHandler(io.neonbee.internal.handler.InstanceInfoHandler) Logger(org.slf4j.Logger) ClusteredSessionStore(io.vertx.ext.web.sstore.ClusteredSessionStore) Predicate(java.util.function.Predicate) MethodHandles(java.lang.invoke.MethodHandles) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Future.failedFuture(io.vertx.core.Future.failedFuture) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) List(java.util.List) MountableEndpoint(io.neonbee.endpoint.MountableEndpoint) SessionStore(io.vertx.ext.web.sstore.SessionStore) DefaultErrorHandler(io.neonbee.internal.handler.DefaultErrorHandler) AbstractVerticle(io.vertx.core.AbstractVerticle) ChainAuthHandler(io.neonbee.internal.handler.ChainAuthHandler) Optional(java.util.Optional) ErrorHandler(io.neonbee.handler.ErrorHandler) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CorrelationIdHandler(io.neonbee.internal.handler.CorrelationIdHandler) SECONDS(java.util.concurrent.TimeUnit.SECONDS) NotFoundHandler(io.neonbee.internal.handler.NotFoundHandler) SessionHandler(io.vertx.ext.web.handler.SessionHandler) CorrelationIdHandler(io.neonbee.internal.handler.CorrelationIdHandler) CacheControlHandler(io.neonbee.internal.handler.CacheControlHandler) Router(io.vertx.ext.web.Router) InstanceInfoHandler(io.neonbee.internal.handler.InstanceInfoHandler) LoggerHandler(io.neonbee.internal.handler.LoggerHandler) Route(io.vertx.ext.web.Route)

Example 5 with ServerConfig

use of io.neonbee.config.ServerConfig in project neonbee by SAP.

the class ServerVerticle method start.

@Override
public void start(Promise<Void> startPromise) {
    NeonBee.get(vertx).getLocalMap().put(SERVER_CONFIG_KEY, config());
    ServerConfig config = new ServerConfig(config());
    createRouter(config).compose(router -> {
        Optional<ChainAuthHandler> defaultAuthHandler = Optional.ofNullable(config.getAuthChainConfig()).map(c -> ChainAuthHandler.create(vertx, c));
        return mountEndpoints(router, config.getEndpointConfigs(), defaultAuthHandler).onSuccess(v -> {
            // the NotFoundHandler fails the routing context finally.
            // To ensure that no handler will be added after it, it is added here.
            router.route().handler(new NotFoundHandler());
        }).compose(v -> createHttpServer(router, config));
    }).<Void>mapEmpty().onComplete(startPromise);
}
Also used : Future.succeededFuture(io.vertx.core.Future.succeededFuture) CacheControlHandler(io.neonbee.internal.handler.CacheControlHandler) AsyncHelper(io.neonbee.internal.helper.AsyncHelper) LocalSessionStore(io.vertx.ext.web.sstore.LocalSessionStore) HttpServer(io.vertx.core.http.HttpServer) LoggerFactory(org.slf4j.LoggerFactory) NeonBee(io.neonbee.NeonBee) Router(io.vertx.ext.web.Router) BodyHandler(io.vertx.ext.web.handler.BodyHandler) LoggerHandler(io.neonbee.internal.handler.LoggerHandler) SessionHandling(io.neonbee.config.ServerConfig.SessionHandling) TimeoutHandler(io.vertx.ext.web.handler.TimeoutHandler) Endpoint(io.neonbee.endpoint.Endpoint) SessionHandler(io.vertx.ext.web.handler.SessionHandler) EndpointConfig(io.neonbee.config.EndpointConfig) ServerConfig(io.neonbee.config.ServerConfig) Route(io.vertx.ext.web.Route) InstanceInfoHandler(io.neonbee.internal.handler.InstanceInfoHandler) Logger(org.slf4j.Logger) ClusteredSessionStore(io.vertx.ext.web.sstore.ClusteredSessionStore) Predicate(java.util.function.Predicate) MethodHandles(java.lang.invoke.MethodHandles) Promise(io.vertx.core.Promise) Vertx(io.vertx.core.Vertx) Future.failedFuture(io.vertx.core.Future.failedFuture) Collectors(java.util.stream.Collectors) Future(io.vertx.core.Future) List(java.util.List) MountableEndpoint(io.neonbee.endpoint.MountableEndpoint) SessionStore(io.vertx.ext.web.sstore.SessionStore) DefaultErrorHandler(io.neonbee.internal.handler.DefaultErrorHandler) AbstractVerticle(io.vertx.core.AbstractVerticle) ChainAuthHandler(io.neonbee.internal.handler.ChainAuthHandler) Optional(java.util.Optional) ErrorHandler(io.neonbee.handler.ErrorHandler) VisibleForTesting(com.google.common.annotations.VisibleForTesting) CorrelationIdHandler(io.neonbee.internal.handler.CorrelationIdHandler) SECONDS(java.util.concurrent.TimeUnit.SECONDS) NotFoundHandler(io.neonbee.internal.handler.NotFoundHandler) ServerConfig(io.neonbee.config.ServerConfig) NotFoundHandler(io.neonbee.internal.handler.NotFoundHandler) ChainAuthHandler(io.neonbee.internal.handler.ChainAuthHandler)

Aggregations

ServerConfig (io.neonbee.config.ServerConfig)7 EndpointConfig (io.neonbee.config.EndpointConfig)5 NeonBee (io.neonbee.NeonBee)3 DeploymentOptions (io.vertx.core.DeploymentOptions)3 Vertx (io.vertx.core.Vertx)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 SessionHandling (io.neonbee.config.ServerConfig.SessionHandling)2 Endpoint (io.neonbee.endpoint.Endpoint)2 MountableEndpoint (io.neonbee.endpoint.MountableEndpoint)2 ErrorHandler (io.neonbee.handler.ErrorHandler)2 CacheControlHandler (io.neonbee.internal.handler.CacheControlHandler)2 ChainAuthHandler (io.neonbee.internal.handler.ChainAuthHandler)2 CorrelationIdHandler (io.neonbee.internal.handler.CorrelationIdHandler)2 DefaultErrorHandler (io.neonbee.internal.handler.DefaultErrorHandler)2 InstanceInfoHandler (io.neonbee.internal.handler.InstanceInfoHandler)2 LoggerHandler (io.neonbee.internal.handler.LoggerHandler)2 NotFoundHandler (io.neonbee.internal.handler.NotFoundHandler)2 AsyncHelper (io.neonbee.internal.helper.AsyncHelper)2 AbstractVerticle (io.vertx.core.AbstractVerticle)2 Future (io.vertx.core.Future)2