Skip to content

Commit

Permalink
JNG-6064 Configuration of Guice added
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcsakany committed Dec 14, 2024
1 parent daf6e6a commit 0eb6497
Show file tree
Hide file tree
Showing 26 changed files with 1,029 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,21 @@
import com.google.inject.Singleton;
import com.google.inject.multibindings.Multibinder;
import hu.blackbelt.judo.runtime.core.jaxrs.cxf.server.guice.providers.*;
import hu.blackbelt.judo.runtime.core.utils.RuntimeVariableResolver;
import lombok.*;
import org.apache.cxf.interceptor.Interceptor;

import java.util.Objects;
import java.util.function.Consumer;

public class JudoCxfModule extends AbstractModule {

@Getter
private JudoCxfModuleConfiguration configuration;

public static class JudoCxfModuleBuilder {
JudoCxfModuleConfiguration configuration = null;
RuntimeVariableResolver runtimeVariableResolver = null;
Boolean exchangeIdInterceptors = JudoCxfModuleConfiguration.DEFAULT.getExchangeIdInterceptors();
String cxfJaxRsServerUrl = JudoCxfModuleConfiguration.DEFAULT.getCxfJaxRsServerUrl();
String cxfJaxRsServerPath = JudoCxfModuleConfiguration.DEFAULT.getCxfJaxRsServerPath();
Expand All @@ -61,6 +66,7 @@ public static class JudoCxfModuleBuilder {

@Builder
private JudoCxfModule(JudoCxfModuleConfiguration configuration,
RuntimeVariableResolver runtimeVariableResolver,
String cxfJaxRsServerUrl,
String cxfJaxRsServerPath,
Boolean exchangeIdInterceptors,
Expand All @@ -85,6 +91,8 @@ private JudoCxfModule(JudoCxfModuleConfiguration configuration,
this.configuration = configuration;
} else {
this.configuration = JudoCxfModuleConfiguration.builder()
.runtimeVariableResolver(Objects.requireNonNullElseGet(runtimeVariableResolver,
() -> RuntimeVariableResolver.builder().prefix("judo").build()))
.cxfJaxRsServerUrl(cxfJaxRsServerUrl)
.cxfJaxRsServerPath(cxfJaxRsServerPath)
.exchangeIdInterceptors(exchangeIdInterceptors)
Expand Down Expand Up @@ -139,24 +147,95 @@ protected void configure() {
}

protected void configureOptions() {
bind(String.class).annotatedWith(CxfConfigurations.CxfJaxRsServerUrl.class).toInstance(configuration.getCxfJaxRsServerUrl());
bind(String.class).annotatedWith(CxfConfigurations.CxfJaxRsServerPath.class).toInstance(configuration.getCxfJaxRsServerPath());
bind(Boolean.class).annotatedWith(CxfConfigurations.CxfSkipDefaultJsonProviderRegistration.class).toInstance(configuration.getCxfSkipDefaultJsonProviderRegistration());
bind(Boolean.class).annotatedWith(CxfConfigurations.CxfWadlServiceDescriptionAvailable.class).toInstance(configuration.getCxfWadlServiceDescriptionAvailable());
bind(Boolean.class).annotatedWith(CxfConfigurations.CxfMetricsEnabled.class).toInstance(configuration.getCxfMetricsEnabled());
bind(Boolean.class).annotatedWith(CxfConfigurations.CxfLoggingEnabled.class).toInstance(configuration.getCxfLoggingEnabled());
bind(Boolean.class).annotatedWith(CxfConfigurations.CxfLogException.class).toInstance(configuration.getCxfLogException());
bind(Boolean.class).annotatedWith(CxfConfigurations.CxfReturnRuntimeExceptions.class).toInstance(configuration.getCxfReturnRuntimeExceptions());
bind(Boolean.class).annotatedWith(CxfConfigurations.CxfIncludeBusinessCause.class).toInstance(configuration.getCxfIncludeBusinessCause());
bind(String.class).annotatedWith(CxfConfigurations.CxfDefaultRequestContentType.class).toInstance(configuration.getCxfDefaultRequestContentType());
bind(String.class).annotatedWith(CxfConfigurations.CxfCorsAllowOrigin.class).toInstance(configuration.getCorsAllowOrigin());
bind(Boolean.class).annotatedWith(CxfConfigurations.CxfCorsAllowCredentials.class).toInstance(configuration.getCorsAllowCredentials());
bind(String.class).annotatedWith(CxfConfigurations.CxfCorsAllowHeaders.class).toInstance(configuration.getCorsAllowHeaders());
bind(String.class).annotatedWith(CxfConfigurations.CxfCorsExposeHeaders.class).toInstance(configuration.getCorsExposeHeaders());
bind(Integer.class).annotatedWith(CxfConfigurations.CxfCorsMaxAge.class).toInstance(configuration.getCorsMaxAge());
bind(Integer.class).annotatedWith(CxfConfigurations.CxfCorsPrefligthErrorStatus.class).toInstance(configuration.getCorsPrefligthErrorStatus());
bind(Boolean.class).annotatedWith(CxfConfigurations.CxfCorsBlockIfUnauthorized.class).toInstance(configuration.getCorsBlockIfUnauthorized());
bind(Boolean.class).annotatedWith(CxfConfigurations.CxfCorsDefaultOptionsMethodsHandlePreflight.class).toInstance(configuration.getCorsDefaultOptionsMethodsHandlePreflight());
bind(String.class).annotatedWith(CxfConfigurations.CxfJaxRsServerUrl.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsString("CxfJaxRsServerUrl",
configuration.getCxfJaxRsServerUrl()));

bind(String.class).annotatedWith(CxfConfigurations.CxfJaxRsServerPath.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsString("CxfJaxRsServerPath",
configuration.getCxfJaxRsServerPath()));

bind(Boolean.class).annotatedWith(CxfConfigurations.CxfSkipDefaultJsonProviderRegistration.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsBoolean("CxfSkipDefaultJsonProviderRegistration",
configuration.getCxfSkipDefaultJsonProviderRegistration()));

bind(Boolean.class).annotatedWith(CxfConfigurations.CxfWadlServiceDescriptionAvailable.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsBoolean("CxfWadlServiceDescriptionAvailable",
configuration.getCxfWadlServiceDescriptionAvailable()));

bind(Boolean.class).annotatedWith(CxfConfigurations.CxfMetricsEnabled.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsBoolean("CxfMetricsEnabled",
configuration.getCxfMetricsEnabled()));

bind(Boolean.class).annotatedWith(CxfConfigurations.CxfLoggingEnabled.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsBoolean("CxfLoggingEnabled",
configuration.getCxfLoggingEnabled()));

bind(Boolean.class).annotatedWith(CxfConfigurations.CxfLogException.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsBoolean("CxfLogException",
configuration.getCxfLogException()));

bind(Boolean.class).annotatedWith(CxfConfigurations.CxfReturnRuntimeExceptions.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsBoolean("CxfReturnRuntimeExceptions",
configuration.getCxfReturnRuntimeExceptions()));

bind(Boolean.class).annotatedWith(CxfConfigurations.CxfIncludeBusinessCause.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsBoolean("CxfIncludeBusinessCause",
configuration.getCxfIncludeBusinessCause()));

bind(String.class).annotatedWith(CxfConfigurations.CxfDefaultRequestContentType.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsString("CxfDefaultRequestContentType",
configuration.getCxfDefaultRequestContentType()));

bind(String.class).annotatedWith(CxfConfigurations.CxfCorsAllowOrigin.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsString("CxfCorsAllowOrigin",
configuration.getCorsAllowOrigin()));

bind(Boolean.class).annotatedWith(CxfConfigurations.CxfCorsAllowCredentials.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsBoolean("CxfCorsAllowCredentials",
configuration.getCorsAllowCredentials()));

bind(String.class).annotatedWith(CxfConfigurations.CxfCorsAllowHeaders.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsString("CxfCorsAllowHeaders",
configuration.getCorsAllowHeaders()));

bind(String.class).annotatedWith(CxfConfigurations.CxfCorsExposeHeaders.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsString("CxfCorsExposeHeaders",
configuration.getCorsExposeHeaders()));

bind(Integer.class).annotatedWith(CxfConfigurations.CxfCorsMaxAge.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsInteger("CxfCorsMaxAge",
configuration.getCorsMaxAge()));

bind(Integer.class).annotatedWith(CxfConfigurations.CxfCorsPrefligthErrorStatus.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsInteger("CxfCorsPrefligthErrorStatus",
configuration.getCorsPrefligthErrorStatus()));

bind(Boolean.class).annotatedWith(CxfConfigurations.CxfCorsBlockIfUnauthorized.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsBoolean("CxfCorsBlockIfUnauthorized",
configuration.getCorsBlockIfUnauthorized()));

bind(Boolean.class).annotatedWith(CxfConfigurations.CxfCorsDefaultOptionsMethodsHandlePreflight.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsBoolean("CxfCorsDefaultOptionsMethodsHandlePreflight",
configuration.getCorsDefaultOptionsMethodsHandlePreflight()));
}

protected void configureServer() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hu.blackbelt.judo.runtime.core.jaxrs.cxf.server.guice;

import hu.blackbelt.judo.runtime.core.jaxrs.providers.SetDefaultContentTypePreMatchContainerRequestFilter;
import hu.blackbelt.judo.runtime.core.utils.RuntimeVariableResolver;
import lombok.*;

@Builder
Expand All @@ -10,7 +11,8 @@
@AllArgsConstructor
public class JudoCxfModuleConfiguration {
public static final JudoCxfModuleConfiguration DEFAULT = JudoCxfModuleConfiguration.builder().build();

@Builder.Default
RuntimeVariableResolver runtimeVariableResolver = null;
@Builder.Default
Boolean exchangeIdInterceptors = true;
@Builder.Default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
* #L%
*/
import java.io.File;
import java.util.Objects;

import javax.sql.DataSource;

import com.google.inject.AbstractModule;
import com.google.inject.util.Providers;
import hu.blackbelt.judo.runtime.core.dao.rdbms.RdbmsInit;
import hu.blackbelt.judo.runtime.core.guice.dao.rdbms.PlatformTransactionManagerProvider;
import hu.blackbelt.judo.runtime.core.utils.RuntimeVariableResolver;
import lombok.*;
import org.hsqldb.server.Server;

Expand All @@ -46,6 +48,7 @@ public class JudoHsqldbModule extends AbstractModule {

public static class JudoHsqldbModuleBuilder {
JudoHsqldbModuleConfiguration configuration = null;
RuntimeVariableResolver runtimeVariableResolver = null;
Boolean runServer = JudoHsqldbModuleConfiguration.DEFAULT.getRunServer();
String databaseName = JudoHsqldbModuleConfiguration.DEFAULT.getDatabaseName();
File databasePath = JudoHsqldbModuleConfiguration.DEFAULT.getDatabasePath();
Expand All @@ -60,6 +63,7 @@ public static class JudoHsqldbModuleBuilder {

@Builder
private JudoHsqldbModule(JudoHsqldbModuleConfiguration configuration,
RuntimeVariableResolver runtimeVariableResolver,
Boolean runServer,
String databaseName,
File databasePath,
Expand All @@ -75,6 +79,8 @@ private JudoHsqldbModule(JudoHsqldbModuleConfiguration configuration,
this.configuration = configuration;
} else {
this.configuration = JudoHsqldbModuleConfiguration.builder()
.runtimeVariableResolver(Objects.requireNonNullElseGet(runtimeVariableResolver,
() -> RuntimeVariableResolver.builder().prefix("judo").build()))
.port(port)
.runServer(runServer)
.databaseName(databaseName)
Expand All @@ -100,9 +106,20 @@ protected void configure() {
}

protected void configureOptions() {
bind(Integer.class).annotatedWith(HsqlDbConfigurationQualifier.HsqldbServerPort.class).toInstance(configuration.getPort());
bind(String.class).annotatedWith(HsqlDbConfigurationQualifier.HsqldbServerDatabaseName.class).toInstance(configuration.getDatabaseName());
bind(File.class).annotatedWith(HsqlDbConfigurationQualifier.HsqldbServerDatabasePath.class).toInstance(configuration.getDatabasePath());
bind(Integer.class).annotatedWith(HsqlDbConfigurationQualifier.HsqldbServerPort.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsInteger("hsqldbServerPort",
configuration.getPort()));

bind(String.class).annotatedWith(HsqlDbConfigurationQualifier.HsqldbServerDatabaseName.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsString("hsqldbServerDatabaseName",
configuration.getDatabaseName()));

bind(File.class).annotatedWith(HsqlDbConfigurationQualifier.HsqldbServerDatabasePath.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsFile("hsqldbServerDatabasePath",
configuration.getDatabasePath()));
}

protected void configureServer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import hu.blackbelt.judo.runtime.core.dao.rdbms.RdbmsInit;
import hu.blackbelt.judo.runtime.core.dao.rdbms.RdbmsParameterMapper;
import hu.blackbelt.judo.runtime.core.dao.rdbms.query.mappers.MapperFactory;
import hu.blackbelt.judo.runtime.core.utils.RuntimeVariableResolver;
import lombok.*;
import org.springframework.transaction.PlatformTransactionManager;

Expand All @@ -18,6 +19,8 @@
public class JudoHsqldbModuleConfiguration {
public static final JudoHsqldbModuleConfiguration DEFAULT = JudoHsqldbModuleConfiguration.builder().build();
@Builder.Default
RuntimeVariableResolver runtimeVariableResolver = null;
@Builder.Default
private Boolean runServer = false;
@Builder.Default
private String databaseName = "judo";
Expand Down
4 changes: 4 additions & 0 deletions judo-runtime-core-guice-jetty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>hu.blackbelt.judo.runtime</groupId>
<artifactId>judo-runtime-core</artifactId>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import hu.blackbelt.judo.runtime.core.utils.RuntimeVariableResolver;
import lombok.*;

import java.util.Objects;

public class JudoJettyModule extends AbstractModule {

@Getter
Expand All @@ -38,6 +41,7 @@ public class JudoJettyModule extends AbstractModule {
@Setter
public static class JudoJettyModuleConfiguration {
public static final JudoJettyModuleConfiguration DEFAULT = JudoJettyModuleConfiguration.builder().build();
@Builder.Default RuntimeVariableResolver runtimeVariableResolver = null;
@Builder.Default Integer jettyServerPort = 8181;
@Builder.Default String jettyContextPath = "/";
@Builder.Default Integer maxThreads = 100;
Expand All @@ -47,6 +51,7 @@ public static class JudoJettyModuleConfiguration {

public static class JudoJettyModuleBuilder {
JudoJettyModuleConfiguration configuration = null;
RuntimeVariableResolver runtimeVariableResolver = null;
Integer jettyServerPort = JudoJettyModuleConfiguration.DEFAULT.getJettyServerPort();
String jettyContextPath = JudoJettyModuleConfiguration.DEFAULT.getJettyContextPath();
Integer maxThreads = JudoJettyModuleConfiguration.DEFAULT.getMaxThreads();
Expand All @@ -60,6 +65,7 @@ public static class JudoJettyModuleBuilder {

@Builder
private JudoJettyModule(JudoJettyModuleConfiguration configuration,
RuntimeVariableResolver runtimeVariableResolver,
Integer jettyServerPort,
String jettyContextPath,
Integer maxThreads,
Expand All @@ -70,6 +76,8 @@ private JudoJettyModule(JudoJettyModuleConfiguration configuration,
this.configuration = configuration;
} else {
this.configuration = JudoJettyModuleConfiguration.builder()
.runtimeVariableResolver(Objects.requireNonNullElseGet(runtimeVariableResolver,
() -> RuntimeVariableResolver.builder().prefix("judo").build()))
.jettyServerPort(jettyServerPort)
.jettyContextPath(jettyContextPath)
.maxThreads(maxThreads)
Expand All @@ -85,11 +93,31 @@ protected void configure() {
}

protected void configureOptions() {
bind(Integer.class).annotatedWith(JettyConfigurations.JettyServerPort.class).toInstance(configuration.getJettyServerPort());
bind(String.class).annotatedWith(JettyConfigurations.JettyServerContextPath.class).toInstance(configuration.getJettyContextPath());
bind(Integer.class).annotatedWith(JettyConfigurations.JettyServerMaxThreads.class).toInstance(configuration.getMaxThreads());
bind(Integer.class).annotatedWith(JettyConfigurations.JettyServerMinThreads.class).toInstance(configuration.getMinThreads());
bind(Integer.class).annotatedWith(JettyConfigurations.JettyServerIdleTimeout.class).toInstance(configuration.getIdleTimeout());
bind(Integer.class).annotatedWith(JettyConfigurations.JettyServerPort.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsInteger("jettyServerPort",
configuration.getJettyServerPort()));

bind(String.class).annotatedWith(JettyConfigurations.JettyServerContextPath.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsString("jettyServerContextPath",
configuration.getJettyContextPath()));

bind(Integer.class).annotatedWith(JettyConfigurations.JettyServerMaxThreads.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsInteger("jettyServerMaxThreads",
configuration.getMaxThreads()));

bind(Integer.class).annotatedWith(JettyConfigurations.JettyServerMinThreads.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsInteger("jettyServerMinThreads",
configuration.getMinThreads()));

bind(Integer.class).annotatedWith(JettyConfigurations.JettyServerIdleTimeout.class)
.toInstance(configuration.getRuntimeVariableResolver()
.getVariableAsInteger("jettyServerIdleTimeout",
configuration.getIdleTimeout()));

}

protected void configureServer() {
Expand Down
Loading

0 comments on commit 0eb6497

Please sign in to comment.