diff --git a/app/src/main/java/ch/sbb/polarion/extension/generic/rest/GenericRestApplication.java b/app/src/main/java/ch/sbb/polarion/extension/generic/rest/GenericRestApplication.java index daf97ef..8d80c44 100644 --- a/app/src/main/java/ch/sbb/polarion/extension/generic/rest/GenericRestApplication.java +++ b/app/src/main/java/ch/sbb/polarion/extension/generic/rest/GenericRestApplication.java @@ -43,38 +43,63 @@ public Set> getClasses() { @NotNull protected Set> getExceptionMappers() { + return new HashSet<>(); + } + + @NotNull + protected Set> getFilters() { + return new HashSet<>(); + } + + @NotNull + protected Set> getControllerClasses() { + return new HashSet<>(); + } + + @Override + @NotNull + public Set getSingletons() { + Set singletons = new HashSet<>(); + singletons.addAll(getExceptionMapperSingletons()); + singletons.addAll(getFilterSingletons()); + singletons.addAll(getControllerSingletons()); + return singletons; + } + + @NotNull + protected Set getExceptionMapperSingletons() { return new HashSet<>(Arrays.asList( - BadRequestExceptionMapper.class, - ForbiddenExceptionMapper.class, - IllegalArgumentExceptionMapper.class, - InternalServerErrorExceptionMapper.class, - NotFoundExceptionMapper.class, - ObjectNotFoundExceptionMapper.class, - UncaughtExceptionMapper.class + new BadRequestExceptionMapper(), + new ForbiddenExceptionMapper(), + new IllegalArgumentExceptionMapper(), + new InternalServerErrorExceptionMapper(), + new NotFoundExceptionMapper(), + new ObjectNotFoundExceptionMapper(), + new UncaughtExceptionMapper() )); } @NotNull - protected Set> getFilters() { + protected Set getFilterSingletons() { return new HashSet<>(Arrays.asList( - AuthenticationFilter.class, - CorsFilter.class, - LogoutFilter.class + new AuthenticationFilter(), + new CorsFilter(), + new LogoutFilter() )); } @NotNull - protected Set> getControllerClasses() { - HashSet> controllerClasses = new HashSet<>(Arrays.asList( - ExtensionInfoApiController.class, - ExtensionInfoInternalController.class, - SwaggerController.class, - SwaggerDefinitionController.class + protected Set getControllerSingletons() { + HashSet controllerSingletons = new HashSet<>(Arrays.asList( + new ExtensionInfoApiController(), + new ExtensionInfoInternalController(), + new SwaggerController(), + new SwaggerDefinitionController() )); if (!NamedSettingsRegistry.INSTANCE.getAll().isEmpty()) { - controllerClasses.add(NamedSettingsRegistry.INSTANCE.isScopeAgnostic() ? NamedSettingsApiScopeAgnosticController.class : NamedSettingsApiController.class); - controllerClasses.add(NamedSettingsInternalController.class); + controllerSingletons.add(NamedSettingsRegistry.INSTANCE.isScopeAgnostic() ? new NamedSettingsApiScopeAgnosticController() : new NamedSettingsApiController()); + controllerSingletons.add(new NamedSettingsInternalController()); } - return controllerClasses; + return controllerSingletons; } }