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;
}
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);
});
}
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();
})));
}
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));
}
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);
}
Aggregations