Skip to content

Commit

Permalink
perf($ReactiveStarter): abstract project property
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
Johnny Miller (锺俊) committed Dec 29, 2020
1 parent b6996c8 commit aafac56
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.jmsoftware.maf.apigateway;

import com.jmsoftware.maf.apigateway.universal.configuration.ProjectProperty;
import com.jmsoftware.maf.apigateway.universal.configuration.ServerConfiguration;
import com.jmsoftware.maf.reactivespringbootstarter.configuration.MafProjectProperty;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.boot.SpringApplication;
Expand All @@ -28,11 +28,11 @@
@EnableReactiveFeignClients
public class ApiGatewayApplication {
private static final String LINE_SEPARATOR = System.lineSeparator();
private static ProjectProperty projectProperty;
private static MafProjectProperty mafProjectProperty;
private static ServerConfiguration serverConfiguration;

public ApiGatewayApplication(ProjectProperty projectProperty, ServerConfiguration serverConfiguration) {
ApiGatewayApplication.projectProperty = projectProperty;
public ApiGatewayApplication(MafProjectProperty mafProjectProperty, ServerConfiguration serverConfiguration) {
ApiGatewayApplication.mafProjectProperty = mafProjectProperty;
ApiGatewayApplication.serverConfiguration = serverConfiguration;
}

Expand All @@ -42,12 +42,12 @@ public static void main(String[] args) {
val endInstant = Instant.now();
val duration = Duration.between(startInstant, endInstant);
log.info("🥳 Congratulations! 🎉");
log.info("🖥 {}@{} started!", projectProperty.getProjectArtifactId(), projectProperty.getVersion());
log.info("⚙️ Environment: {}", projectProperty.getEnvironment());
log.info("🖥 {}@{} started!", mafProjectProperty.getProjectArtifactId(), mafProjectProperty.getVersion());
log.info("⚙️ Environment: {}", mafProjectProperty.getEnvironment());
log.info("⏳ Deployment duration: {} seconds ({} ms)", duration.getSeconds(), duration.toMillis());
log.info("⏰ App started at {} (timezone - {})", endInstant, TimeZone.getDefault().getDisplayName());
log.info("{} App running at{} - Local: http://localhost:{}{}/{} - Network: {}/{}",
LINE_SEPARATOR, LINE_SEPARATOR, serverConfiguration.getServerPort(), projectProperty.getContextPath(),
LINE_SEPARATOR, serverConfiguration.getBaseUrl(), projectProperty.getContextPath());
LINE_SEPARATOR, LINE_SEPARATOR, serverConfiguration.getServerPort(), mafProjectProperty.getContextPath(),
LINE_SEPARATOR, serverConfiguration.getBaseUrl(), mafProjectProperty.getContextPath());
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.jmsoftware.maf.apigateway.security.configuration;

import com.jmsoftware.maf.apigateway.universal.configuration.ProjectProperty;
import com.jmsoftware.maf.reactivespringbootstarter.configuration.MafProjectProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
Expand All @@ -27,11 +27,12 @@ public class JwtConfiguration {
*/
private String jwtRedisKeyPrefix;

public JwtConfiguration(ProjectProperty projectProperty) {
this.signingKey = String.format("%s %s", projectProperty.getProjectParentArtifactId(), projectProperty.getVersion());
public JwtConfiguration(MafProjectProperty mafProjectProperty) {
this.signingKey = String.format("%s %s", mafProjectProperty.getProjectParentArtifactId(),
mafProjectProperty.getVersion());
log.info("Initiated JWT signing key: {}. The specified key byte array is {} bits", this.signingKey,
this.signingKey.getBytes(StandardCharsets.UTF_8).length * 8);
jwtRedisKeyPrefix = String.format("%s:jwt:", projectProperty.getProjectParentArtifactId());
jwtRedisKeyPrefix = String.format("%s:jwt:", mafProjectProperty.getProjectParentArtifactId());
log.warn("Initiated 'jwtRedisKeyPrefix': {}", jwtRedisKeyPrefix);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jmsoftware.maf.apigateway.universal.configuration;

import com.jmsoftware.maf.reactivespringbootstarter.configuration.MafProjectProperty;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -30,7 +31,7 @@
@RequiredArgsConstructor
public class ServerConfiguration implements ApplicationListener<WebServerInitializedEvent> {
private static final String DEVELOPMENT_ENVIRONMENT = "development";
private final ProjectProperty projectProperty;
private final MafProjectProperty mafProjectProperty;
private int serverPort;

@Override
Expand All @@ -51,7 +52,7 @@ public void onApplicationEvent(WebServerInitializedEvent event) {
* @date 2019-05-03 16:05
*/
public String getBaseUrl() {
return "http://" + this.getPublicIp() + ":" + serverPort + projectProperty.getContextPath();
return "http://" + this.getPublicIp() + ":" + serverPort + mafProjectProperty.getContextPath();
}

/**
Expand All @@ -60,7 +61,7 @@ public String getBaseUrl() {
* @return public IP
*/
public String getPublicIp() {
if (projectProperty.getEnvironment().contains(DEVELOPMENT_ENVIRONMENT)) {
if (mafProjectProperty.getEnvironment().contains(DEVELOPMENT_ENVIRONMENT)) {
return this.getInternetIp();
}
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jmsoftware.maf.apigateway.universal.configuration;

import com.jmsoftware.maf.reactivespringbootstarter.configuration.MafProjectProperty;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
Expand Down Expand Up @@ -40,7 +41,7 @@
public class SwaggerResourceProvider implements SwaggerResourcesProvider {
private static final String SWAGGER_API_URI = "/v2/api-docs";
private static final String LINE_SEPARATOR = System.lineSeparator();
private final ProjectProperty projectProperty;
private final MafProjectProperty mafProjectProperty;
private final RouteLocator routeLocator;

/**
Expand Down Expand Up @@ -72,26 +73,26 @@ public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage(projectProperty.getBasePackage()))
.apis(RequestHandlerSelectors.basePackage(mafProjectProperty.getBasePackage()))
.paths(PathSelectors.any())
.build();
}

private ApiInfo apiInfo() {
val projectArtifactId = projectProperty.getProjectArtifactId();
val version = projectProperty.getVersion();
val developerEmail = projectProperty.getDeveloperEmail();
val developerUrl = projectProperty.getDeveloperUrl();
val projectArtifactId = mafProjectProperty.getProjectArtifactId();
val version = mafProjectProperty.getVersion();
val developerEmail = mafProjectProperty.getDeveloperEmail();
val developerUrl = mafProjectProperty.getDeveloperUrl();
return new ApiInfoBuilder()
.title(String.format("API for %s@%s", projectArtifactId, version))
.description(String.format("%s %sArtifact ID: %s%sEnvironment: %s",
projectProperty.getDescription(),
mafProjectProperty.getDescription(),
LINE_SEPARATOR,
projectArtifactId,
LINE_SEPARATOR,
projectProperty.getEnvironment()))
mafProjectProperty.getEnvironment()))
.contact(new Contact(String.format("%s, email: %s%sHome page: %s",
projectProperty.getDeveloperName(),
mafProjectProperty.getDeveloperName(),
developerEmail,
LINE_SEPARATOR,
developerUrl),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.jmsoftware.maf.apigateway.universal.service.impl;

import com.jmsoftware.maf.apigateway.universal.configuration.ProjectProperty;
import com.jmsoftware.maf.apigateway.universal.service.CommonService;
import com.jmsoftware.maf.common.domain.ValidationTestPayload;
import com.jmsoftware.maf.reactivespringbootstarter.configuration.MafProjectProperty;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -27,12 +27,12 @@
@Service
@RequiredArgsConstructor
public class CommonServiceImpl implements CommonService {
private final ProjectProperty projectProperty;
private final MafProjectProperty mafProjectProperty;

@Override
public Map<String, Object> getApplicationInfo() {
var map = new HashMap<String, Object>(16);
var fieldsInfo = getFieldsInfo(projectProperty);
var fieldsInfo = getFieldsInfo(mafProjectProperty);
fieldsInfo.forEach(fieldInfo -> {
var type = fieldInfo.get("type");
if ("class java.lang.String".equals(type)) {
Expand Down
6 changes: 2 additions & 4 deletions api-gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ logging:
com.jmsoftware: DEBUG
# org.springframework.cloud.gateway: debug

project:
property:
maf:
project-property:
base-package: @project.groupId@
context-path:
group-id: @project.groupId@
Expand All @@ -92,8 +92,6 @@ project:
developer-name: @developerName@
developer-email: @developerEmail@
developer-url: @developerUrl@

maf:
configuration:
ignored-url:
post:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package com.jmsoftware.maf.reactivespringbootstarter.configuration;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

/**
* <h1>MafProjectProperty</h1>
* <p>
* M&F project property, containing the basic constants of the project.
*
* @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 12/29/2020 1:21 PM
*/
@Data
@Validated
@Component
@SuppressWarnings("jol")
@ConfigurationProperties(prefix = "maf.project-property")
public class MafProjectProperty {
/**
* The Base package.
*/
private String basePackage;
/**
* The Context path.
*/
private String contextPath;
/**
* The Group id.
*/
private String groupId;
/**
* The Project parent artifact id.
*/
private String projectParentArtifactId;
/**
* The Project artifact id.
*/
private String projectArtifactId;
/**
* The Version.
*/
private String version;
/**
* The Description.
*/
private String description;
/**
* The Jdk version.
*/
private String jdkVersion;
/**
* The Environment.
*/
private String environment;
/**
* The Url.
*/
private String url;
/**
* The Inception year.
*/
private String inceptionYear;
/**
* The Organization name.
*/
private String organizationName;
/**
* The Organization url.
*/
private String organizationUrl;
/**
* The Issue management system.
*/
private String issueManagementSystem;
/**
* The Issue management url.
*/
private String issueManagementUrl;
/**
* The Developer name.
*/
private String developerName;
/**
* The Developer email.
*/
private String developerEmail;
/**
* The Developer url.
*/
private String developerUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@ public void postConstruct() {
@Bean
@ConditionalOnMissingBean
public MafConfiguration mafConfiguration() {
log.warn("Initial bean: {}", MafConfiguration.class.getName());
log.warn("Initial bean: {}", MafConfiguration.class.getSimpleName());
return new MafConfiguration();
}

@Bean
@ConditionalOnMissingBean
public AccessLogFilter requestFilter(MafConfiguration mafConfiguration) {
log.warn("Initial bean: {}", AccessLogFilter.class.getName());
log.warn("Initial bean: {}", AccessLogFilter.class.getSimpleName());
return new AccessLogFilter(mafConfiguration);
}

@Bean
public MafProjectProperty mafProjectProperty() {
log.warn("Initial bean: {}", MafProjectProperty.class.getSimpleName());
return new MafProjectProperty();
}
}

0 comments on commit aafac56

Please sign in to comment.