Skip to content

Commit

Permalink
Release 2.3.12 (#267)
Browse files Browse the repository at this point in the history
* enabled customized delimiter of collection in @config with new collectionDelimiter field

* refactoring

* refactoring hit-> txId

* refactoring

* refactoring

* dependency update

* release 2.3.12
  • Loading branch information
SummerBootFramework authored Dec 4, 2023
1 parent 028d1a4 commit c1a17a8
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 88 deletions.
30 changes: 15 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.summerboot</groupId>
<artifactId>jexpress</artifactId>
<version>2.3.11</version>
<version>2.3.12</version>
<packaging>jar</packaging>
<name>Summer Boot jExpress</name>
<description>Summer Boot jExpress focuses on solving non-functional and operational maintainability requirements, some of which Spring Boot has (may) not yet provided</description>
Expand Down Expand Up @@ -172,30 +172,30 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<!-- Commons -->
<commons-lang3.version>3.13.0</commons-lang3.version>
<commons-lang3.version>3.14.0</commons-lang3.version>
<commons-cli.version>1.6.0</commons-cli.version>
<commons-io.version>2.15.0</commons-io.version>
<commons-io.version>2.15.1</commons-io.version>
<!-- <commons-text.version>1.11.0</commons-text.version>-->
<!-- <owasp.encoder.version>1.2.3</owasp.encoder.version>-->
<!-- Logging -->
<log4j-api.version>2.21.1</log4j-api.version>
<log4j-api.version>2.22.0</log4j-api.version>
<log4j-disruptor.version>3.4.4</log4j-disruptor.version>
<!-- Mail -->
<jakarta-mail.version>2.0.1</jakarta-mail.version>
<!-- Security -->
<bouncycastle.version>1.76</bouncycastle.version>
<bouncycastle.version>1.77</bouncycastle.version>
<!-- JWT -->
<jwt.version>0.11.5</jwt.version>

<!-- NIO Netty -->
<netty.version>4.1.100.Final</netty.version>
<netty.version>4.1.101.Final</netty.version>
<netty-tcnative.version>2.0.62.Final</netty-tcnative.version>
<!-- gRPC and protobuf -->
<grpc.version>1.59.0</grpc.version>
<grpc.version>1.59.1</grpc.version>
<guava.version>32.1.3-jre</guava.version>
<protobuf.version>3.24.4</protobuf.version>
<protobuf.version>3.25.1</protobuf.version>
<!-- Web JAX-RS -->
<swagger.core.version>2.2.18</swagger.core.version>
<swagger.core.version>2.2.19</swagger.core.version>
<!--<elastic-apm.version>1.36.0</elastic-apm.version>-->


Expand All @@ -207,22 +207,22 @@
<reflections.version>0.10.2</reflections.version>

<!-- JSON/XML/Bean Validation -->
<jackson.version>2.15.3</jackson.version>
<jackson.version>2.16.0</jackson.version>
<!-- Bean Validation -->
<hibernate-validator.version>8.0.1.Final</hibernate-validator.version>
<el.Implementation.version>4.0.2</el.Implementation.version>

<!-- IOC Injection -->
<guice.version>5.1.0</guice.version>
<guice.version>7.0.0</guice.version>

<!-- JPA -->
<hibernate.version>6.3.1.Final</hibernate.version>
<hikari-cp.version>5.0.1</hikari-cp.version>
<hibernate.version>6.4.0.Final</hibernate.version>
<hikari-cp.version>5.1.0</hikari-cp.version>

<!-- Cache -->
<jedis.version>5.0.2</jedis.version>
<jedis.version>5.1.0</jedis.version>

<quartz.version>2.3.2</quartz.version>
<quartz.version>2.5.0-rc1</quartz.version>

<!-- Template Engine -->
<freemarker.version>2.3.32</freemarker.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface BootConstant {
String APP_ID = String.format("%06d", new Random().nextInt(999999));

//version
String VERSION = "SummerBoot.jExpress 2.3.11";
String VERSION = "SummerBoot.jExpress 2.3.12";
String JEXPRESS_PACKAGE_NAME = "org.summerboot.jexpress";

String DEFAULT_ADMIN_MM = "changeit";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ protected int scanAnnotation_Scheduled(Injector injector, String... rootPackageN
for (Class c : classes) {
try {
triggers += QuartzUtil.addQuartzJob(scheduler, c);
} catch (SchedulerException ex) {
} catch (Throwable ex) {
throw new RuntimeException("Filed to addQuartzJob for " + c, ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -301,11 +300,8 @@ protected void scanArgsToInitializeLogging(String[] args) {
System.exit(1);
}
//set log folder outside user specified config folder
Random rnd = new Random();
int number = rnd.nextInt(999999);
String logId = String.format("%06d", number);
// this will convert any number sequence into 6 character.
System.setProperty(BootConstant.SYS_PROP_LOGID, logId);
System.setProperty(BootConstant.SYS_PROP_LOGID, BootConstant.APP_ID);
System.setProperty(BootConstant.SYS_PROP_LOGFILEPATH, userSpecifiedConfigDir.getParent() + File.separator + BootConstant.DIR_LOG);//used by log4j2.xml
pluginDir = new File(userSpecifiedConfigDir.getParentFile(), BootConstant.DIR_PLUGIN).getAbsoluteFile();
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ protected void loadField(Field field, String configFolder, ConfigUtil helper, Pr
valueInCfgFile = configFolder + File.separator + valueInCfgFile;
}
}
ReflectionUtil.loadField(this, field, valueInCfgFile, autoDecrypt, isEmailRecipients);
String collectionDelimiter = cfgAnnotation.collectionDelimiter();
ReflectionUtil.loadField(this, field, valueInCfgFile, autoDecrypt, isEmailRecipients, collectionDelimiter);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,7 @@ public enum Validate {
* @return
*/
String callbackMethodName4Dump() default "";

String collectionDelimiter() default ",";

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpResponseStatus;
import jakarta.persistence.PersistenceException;
import java.io.IOException;
import java.net.http.HttpConnectTimeoutException;
import java.net.http.HttpTimeoutException;
import java.util.Collection;
Expand Down Expand Up @@ -69,7 +70,7 @@ public void onNamingException(NamingException ex, HttpMethod httptMethod, String
if (cause == null) {
cause = ex;
}
if (cause instanceof java.net.UnknownHostException) {
if (cause instanceof IOException) {// java.net.UnknownHostException
HealthMonitor.setHealthStatus(false, ex.toString(), healthInspector);
nakFatal(context, HttpResponseStatus.SERVICE_UNAVAILABLE, BootErrorCode.ACCESS_ERROR_LDAP, "LDAP " + cause.getClass().getSimpleName(), ex, cmtpCfg.getEmailToAppSupport(), httptMethod + " " + httpRequestPath);
} else {
Expand All @@ -85,7 +86,7 @@ public void onPersistenceException(PersistenceException ex, HttpMethod httptMeth
if (cause == null) {
cause = ex;
}
if (cause instanceof java.net.ConnectException) {
if (cause instanceof IOException) {// java.net.ConnectException
HealthMonitor.setHealthStatus(false, ex.toString(), healthInspector);
nakFatal(context, HttpResponseStatus.SERVICE_UNAVAILABLE, BootErrorCode.ACCESS_ERROR_DATABASE, "DB " + cause.getClass().getSimpleName(), ex, cmtpCfg.getEmailToAppSupport(), httptMethod + " " + httpRequestPath);
} else {
Expand Down Expand Up @@ -152,7 +153,7 @@ protected void nakFatal(ServiceContext context, HttpResponseStatus httpResponseS
// 2. send sendAlertAsync
if (po != null) {
// build email content
String briefContent = "caller=" + context.callerId() + ", request#" + context.hit() + ": " + content;
String briefContent = "caller=" + context.callerId() + ", request#" + context.txId() + ": " + content;
po.sendAlertAsync(emailTo, errorMessage, briefContent, ex, true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static long sendResponse(ChannelHandlerContext ctx, boolean isKeepAlive,
if (processorSettings != null) {
String key = processorSettings.getHttpServiceResponseHeaderName_Reference();
if (key != null) {
serviceContext.responseHeader(key, serviceContext.hit());
serviceContext.responseHeader(key, serviceContext.txId());
}
key = processorSettings.getHttpServiceResponseHeaderName_ServerTimestamp();
if (key != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public void channelRead0(final ChannelHandlerContext ctx, final FullHttpRequest
}
NioCounter.COUNTER_HIT.incrementAndGet();
final long hitIndex = NioCounter.COUNTER_BIZ_HIT.incrementAndGet();
final String txId = BootConstant.APP_ID + "-" + hitIndex;
// if (HttpUtil.is100ContinueExpected(req)) {
// ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE, Unpooled.EMPTY_BUFFER));
// }
Expand All @@ -126,7 +127,7 @@ public void channelRead0(final ChannelHandlerContext ctx, final FullHttpRequest
final String httpRequestUri = req.uri();

final boolean isKeepAlive = HttpUtil.isKeepAlive(req);
final String requestMetaInfo = requestMetaInfo(ctx, hitIndex, httpMethod, httpRequestUri, isKeepAlive, dataSize);
final String requestMetaInfo = requestMetaInfo(ctx, txId, httpMethod, httpRequestUri, isKeepAlive, dataSize);
log.debug(() -> requestMetaInfo);

final HttpHeaders requestHeaders = req.headers();
Expand All @@ -140,7 +141,7 @@ public void channelRead0(final ChannelHandlerContext ctx, final FullHttpRequest
final QueryStringDecoder queryStringDecoder = new QueryStringDecoder(httpRequestUri, StandardCharsets.UTF_8);
Runnable asyncTask = () -> {
long queuingTime = System.currentTimeMillis() - start;
ServiceContext context = ServiceContext.build(ctx, hitIndex, start, requestHeaders, httpMethod, httpRequestUri, httpPostRequestBody).responseHeaders(nioCfg.getServerDefaultResponseHeaders()).clientAcceptContentType(requestHeaders.get(HttpHeaderNames.ACCEPT));
ServiceContext context = ServiceContext.build(ctx, txId, hitIndex, start, requestHeaders, httpMethod, httpRequestUri, httpPostRequestBody).responseHeaders(nioCfg.getServerDefaultResponseHeaders()).clientAcceptContentType(requestHeaders.get(HttpHeaderNames.ACCEPT));
String acceptCharset = requestHeaders.get(HttpHeaderNames.ACCEPT_CHARSET);
if (StringUtils.isNotBlank(acceptCharset)) {
context.charsetName(acceptCharset);//.contentType(ServiceContext.CONTENT_TYPE_JSON_ + acceptCharset); do not build content type with charset now, don't know charset valid or not
Expand Down Expand Up @@ -185,9 +186,9 @@ public void channelRead0(final ChannelHandlerContext ctx, final FullHttpRequest
//response#1=200 OK, error=0, r2q=7ms, r2r=60ms, caller=aaa#bbb, received#1=GET /a
StringBuilder sb = new StringBuilder();
//line1
sb.append("request_").append(hitIndex).append(".caller=").append(caller == null ? context.callerId() : caller);
sb.append("request_").append(txId).append(".caller=").append(caller == null ? context.callerId() : caller);
//line2,3
sb.append("\n\t").append(requestMetaInfo).append("\n\tresponse_").append(hitIndex).append("=").append(status)
sb.append("\n\t").append(requestMetaInfo).append("\n\tresponse_").append(txId).append("=").append(status)
.append(", error=").append(errorCount)
.append(", FullHttpRequest.t0=").append(TimeUtil.toOffsetDateTime(start, zoneId))
.append(", queuing=").append(queuingTime).append("ms, process=").append(processTime);
Expand Down Expand Up @@ -247,14 +248,14 @@ public void channelRead0(final ChannelHandlerContext ctx, final FullHttpRequest
nioCfg.getBizExecutor().execute(asyncTask);
} catch (RejectedExecutionException ex) {
long queuingTime = System.currentTimeMillis() - start;
ServiceContext context = ServiceContext.build(ctx, hitIndex, start, requestHeaders, httpMethod, httpRequestUri, httpPostRequestBody).responseHeaders(nioCfg.getServerDefaultResponseHeaders()).clientAcceptContentType(requestHeaders.get(HttpHeaderNames.ACCEPT));
ServiceContext context = ServiceContext.build(ctx, txId, hitIndex, start, requestHeaders, httpMethod, httpRequestUri, httpPostRequestBody).responseHeaders(nioCfg.getServerDefaultResponseHeaders()).clientAcceptContentType(requestHeaders.get(HttpHeaderNames.ACCEPT));
Err e = new Err(BootErrorCode.NIO_TOO_MANY_REQUESTS, null, null, ex, "Too many request, try again later");
context.error(e).status(HttpResponseStatus.TOO_MANY_REQUESTS).level(Level.FATAL);
long responseContentLength = NioHttpUtil.sendResponse(ctx, isKeepAlive, context, this, null);

StringBuilder sb = new StringBuilder();
sb.append("request_").append(hitIndex).append("=").append(ex.toString())
.append("ms\n\t").append(requestMetaInfo).append("\n\tresponse#").append(hitIndex)
sb.append("request_").append(txId).append("=").append(ex.toString())
.append("ms\n\t").append(requestMetaInfo).append("\n\tresponse#").append(txId)
.append("=").append(context.status())
.append(", errorCode=").append(e.getErrorCode())
.append(", queuing=").append(queuingTime)
Expand All @@ -264,13 +265,13 @@ public void channelRead0(final ChannelHandlerContext ctx, final FullHttpRequest
log.fatal(sb.toString());
} catch (Throwable ex) {
long queuingTime = System.currentTimeMillis() - start;
ServiceContext context = ServiceContext.build(ctx, hitIndex, start, requestHeaders, httpMethod, httpRequestUri, httpPostRequestBody).responseHeaders(nioCfg.getServerDefaultResponseHeaders()).clientAcceptContentType(requestHeaders.get(HttpHeaderNames.ACCEPT));
ServiceContext context = ServiceContext.build(ctx, txId, hitIndex, start, requestHeaders, httpMethod, httpRequestUri, httpPostRequestBody).responseHeaders(nioCfg.getServerDefaultResponseHeaders()).clientAcceptContentType(requestHeaders.get(HttpHeaderNames.ACCEPT));
Err e = new Err(BootErrorCode.NIO_UNEXPECTED_EXECUTOR_FAILURE, null, null, ex, "NIO unexpected executor failure");
context.error(e).status(HttpResponseStatus.INTERNAL_SERVER_ERROR).level(Level.FATAL);
long responseContentLength = NioHttpUtil.sendResponse(ctx, isKeepAlive, context, this, null);
StringBuilder sb = new StringBuilder();
sb.append("request_").append(hitIndex).append("=").append(ex.toString())
.append("ms\n\t").append(requestMetaInfo).append("\n\tresponse#").append(hitIndex)
sb.append("request_").append(txId).append("=").append(ex.toString())
.append("ms\n\t").append(requestMetaInfo).append("\n\tresponse#").append(txId)
.append("=").append(context.status())
.append(", errorCode=").append(e.getErrorCode())
.append(", queuing=").append(queuingTime)
Expand All @@ -291,7 +292,7 @@ private String info(ChannelHandlerContext ctx) {
.toString();
}

private String requestMetaInfo(ChannelHandlerContext ctx, long hitIndex, HttpMethod httpMethod, String httpRequestUri, boolean isKeepAlive, long dataSize) {
private String requestMetaInfo(ChannelHandlerContext ctx, String hitIndex, HttpMethod httpMethod, String httpRequestUri, boolean isKeepAlive, long dataSize) {
return new StringBuilder()
.append("request_").append(hitIndex)
.append("=").append(httpMethod).append(" ").append(httpRequestUri)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public class ServiceContext {
private final String requesURI;
private final HttpHeaders requestHeaders;
private final String requestBody;
private final String txId;
private final long hit;
private final long startTs;
private Caller caller;
Expand Down Expand Up @@ -107,11 +108,15 @@ public class ServiceContext {
private boolean logResponseBody = true;

public static ServiceContext build(long hit) {
return new ServiceContext(null, hit, System.currentTimeMillis(), null, null, null, null);
return build(BootConstant.APP_ID + "-" + hit, hit);
}

public static ServiceContext build(ChannelHandlerContext ctx, long hit, long startTs, HttpHeaders requestHeaders, HttpMethod requesMethod, String requesURI, String requestBody) {
return new ServiceContext(ctx, hit, startTs, requestHeaders, requesMethod, requesURI, requestBody);
public static ServiceContext build(String txId, long hit) {
return new ServiceContext(null, txId, hit, System.currentTimeMillis(), null, null, null, null);
}

public static ServiceContext build(ChannelHandlerContext ctx, String txId, long hit, long startTs, HttpHeaders requestHeaders, HttpMethod requesMethod, String requesURI, String requestBody) {
return new ServiceContext(ctx, txId, hit, startTs, requestHeaders, requesMethod, requesURI, requestBody);
}

@Override
Expand All @@ -120,14 +125,15 @@ public String toString() {
return "ServiceContext{" + "status=" + status + ", responseHeaders=" + responseHeaders + ", contentType=" + contentType + ", data=" + data + ", txt=" + txt + ", errors=" + serviceError + ", level=" + level + ", logReqHeader=" + logRequestHeader + ", logRespHeader=" + logResponseHeader + ", logReqContent=" + logRequestBody + ", logRespContent=" + logResponseBody + '}';
}

private ServiceContext(ChannelHandlerContext ctx, long hit, long startTs, HttpHeaders requestHeaders, HttpMethod requesMethod, String requesURI, String requestBody) {
private ServiceContext(ChannelHandlerContext ctx, String txId, long hit, long startTs, HttpHeaders requestHeaders, HttpMethod requesMethod, String requesURI, String requestBody) {
if (ctx != null && ctx.channel() != null) {
this.localIP = ctx.channel().localAddress();
this.remoteIP = ctx.channel().remoteAddress();
} else {
this.localIP = null;
this.remoteIP = null;
}
this.txId = txId;
this.hit = hit;
this.startTs = startTs;
this.requestHeaders = requestHeaders;
Expand Down Expand Up @@ -220,6 +226,10 @@ public ServiceContext reset() {
}

//@JsonInclude(JsonInclude.Include.NON_NULL)
public String txId() {
return txId;
}

public long hit() {
return hit;
}
Expand Down Expand Up @@ -661,7 +671,7 @@ public ServiceError error() {
*/
public ServiceContext error(Err error) {
if (serviceError == null) {
serviceError = new ServiceError(BootConstant.APP_ID + "-" + hit);
serviceError = new ServiceError(txId);
}
if (error == null) {
return this;
Expand Down Expand Up @@ -693,7 +703,7 @@ public ServiceContext errors(Collection<Err> es) {
return this;
}
if (serviceError == null) {
serviceError = new ServiceError(BootConstant.APP_ID + "-" + hit);
serviceError = new ServiceError(txId);
}
serviceError.addErrors(es);
for (Err e : es) {
Expand Down
Loading

0 comments on commit c1a17a8

Please sign in to comment.