Skip to content

refactoring #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.summerboot</groupId>
<artifactId>jexpress</artifactId>
<version>2.4.11</version>
<version>2.4.12</version>
<packaging>jar</packaging>
<name>Summer Boot jExpress</name>
<description>Summer Boot jExpress focuses on solving non-functional and operational maintainability requirements,
Expand Down Expand Up @@ -62,14 +62,15 @@
<plugins>
<plugin>
<!--for unit test-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<version>3.5.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<!-- <version>1.12.2</version> -->
<version>2.0.0-M1</version>
<version>2.1.0</version>
</plugin>
<!--Source-->
<plugin>
Expand All @@ -90,7 +91,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.3</version>
<version>3.10.0</version>
<configuration>
<source>17</source>
<!-- <aggregate>true</aggregate>-->
Expand All @@ -111,9 +112,10 @@

<!--Deploy-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<!-- <version>2.8.2</version> -->
<version>3.1.1</version>
<version>3.1.3</version>
<executions>
<execution>
<id>default-deploy</id>
Expand All @@ -128,7 +130,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>3.2.2</version>
<version>3.2.5</version>
<executions>
<execution>
<phase>verify</phase>
Expand All @@ -143,7 +145,7 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.13</version>
<version>1.7.0</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
Expand Down Expand Up @@ -206,7 +208,7 @@
<jwt.version>0.12.6</jwt.version>

<!-- NIO Netty -->
<netty.version>4.1.112.Final</netty.version>
<netty.version>4.1.113.Final</netty.version>
<netty-tcnative.version>2.0.66.Final</netty-tcnative.version>
<!-- gRPC and protobuf -->
<grpc.version>1.66.0</grpc.version>
Expand Down Expand Up @@ -241,7 +243,7 @@
<!-- Cache -->
<jedis.version>5.1.5</jedis.version>

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

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

//version
String VERSION = "jExpress 2.4.11";
String VERSION = "jExpress 2.4.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 @@ -47,7 +47,7 @@ public boolean beforeProcess(RequestProcessor processor, HttpHeaders httpRequest
}

@Override
public void afterProcess(RequestProcessor processor, ChannelHandlerContext ctx, HttpHeaders httpRequestHeaders, HttpMethod httptMethod, String httpRequestPath, Map<String, List<String>> queryParams, String httpPostRequestBody, ServiceContext context) {
public void afterProcess(boolean preProcessResult, Object processResult, Throwable processException, RequestProcessor processor, ChannelHandlerContext ctx, HttpHeaders httpRequestHeaders, HttpMethod httptMethod, String httpRequestPath, Map<String, List<String>> queryParams, String httpPostRequestBody, ServiceContext context) {
// if (httpRequestHeaders.contains(HttpHeaderNames.Sensitive_Header)) {
// httpRequestHeaders.set(HttpHeaderNames.Sensitive_Header, "***");// protect Sensitive_Header from being logged
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public interface HttpLifecycleListener {
/**
* step1 - after process is done, before sending response to client
*
* @param preProcessResult
* @param processResult
* @param processException
* @param processor
* @param ctx
* @param httpRequestHeaders
Expand All @@ -58,7 +61,7 @@ public interface HttpLifecycleListener {
* @param httpPostRequestBody
* @param context
*/
void afterProcess(RequestProcessor processor, ChannelHandlerContext ctx, HttpHeaders httpRequestHeaders, HttpMethod httptMethod, String httpRequestPath,
void afterProcess(boolean preProcessResult, Object processResult, Throwable processException, RequestProcessor processor, ChannelHandlerContext ctx, HttpHeaders httpRequestHeaders, HttpMethod httptMethod, String httpRequestPath,
Map<String, List<String>> queryParams, String httpPostRequestBody, ServiceContext context);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected GRPCServiceCounter initThreadPool(ThreadPoolExecutor tpe, NIOStatusLis
long task = tpe.getTaskCount();
long completed = tpe.getCompletedTaskCount();
//long checksum = hps + tps + active + queue + activeChannel + totalChannel + totalHit + bizHit + task + completed + active + pool + core + max + largest;
long checksum = hps + tps + active + queue + totalHit + bizHit + /*task + completed +*/ active + pool + core + max + largest;
long checksum = hps + tps + active + queue /*+ activeChannel*/ + bizHit + task + completed + active + pool + core + max + largest;
if (lastChecksum.get() != checksum) {
lastChecksum.set(checksum);
//log.debug(() -> "hps=" + hps + ", tps=" + tps + ", activeChannel=" + activeChannel + ", totalChannel=" + totalChannel + ", totalHit=" + totalHit + " (ping" + pingHit + " + biz" + bizHit + "), task=" + task + ", completed=" + completed + ", queue=" + queue + ", active=" + active + ", pool=" + pool + ", core=" + core + ", max=" + max + ", largest=" + largest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ protected ProcessorSettings service(final ChannelHandlerContext ctx, final HttpH
final String httpRequestPath, final Map<String, List<String>> queryParams, final String httpPostRequestBody, final ServiceContext context) {
ProcessorSettings processorSettings = null;
RequestProcessor processor = null;
boolean preProcessSuccess = false;
boolean preProcessResult = false;
Object processResult = null;
Throwable processException = null;
try {
// step1. find controller and the action in it
processor = getRequestProcessor(httptMethod, httpRequestPath);
Expand Down Expand Up @@ -106,29 +108,33 @@ protected ProcessorSettings service(final ChannelHandlerContext ctx, final HttpH
if (authenticator != null && !authenticator.customizedAuthorizationCheck(processor, httpRequestHeaders, httpRequestPath, context)) {
return processorSettings;
}
preProcessSuccess = httpLifecycleListener.beforeProcess(processor, httpRequestHeaders, httpRequestPath, context);
if (preProcessSuccess) {
processor.process(ctx, httpRequestHeaders, httpRequestPath, queryParams, httpPostRequestBody, context);
} else {
preProcessResult = httpLifecycleListener.beforeProcess(processor, httpRequestHeaders, httpRequestPath, context);
if (!preProcessResult) {
return processorSettings;
}
//} catch (ExpiredJwtException | SignatureException | MalformedJwtException ex) {
// nak(context, HttpResponseStatus.UNAUTHORIZED, BootErrorCode.AUTH_INVALID_TOKEN, "Invalid JWT");
processResult = processor.process(ctx, httpRequestHeaders, httpRequestPath, queryParams, httpPostRequestBody, context);
} catch (NamingException ex) {
processException = ex;
httpExceptionListener.onNamingException(ex, httptMethod, httpRequestPath, context);
} catch (PersistenceException ex) {
processException = ex;
httpExceptionListener.onPersistenceException(ex, httptMethod, httpRequestPath, context);
} catch (HttpConnectTimeoutException ex) {
processException = ex;
// a connection, over which an HttpRequest is intended to be sent, is not successfully established within a specified time period.
httpExceptionListener.onHttpConnectTimeoutException(ex, httptMethod, httpRequestPath, context);
} catch (HttpTimeoutException ex) {
processException = ex;
// a context is not received within a specified time period.
httpExceptionListener.onHttpTimeoutException(ex, httptMethod, httpRequestPath, context);
} catch (RejectedExecutionException ex) {
processException = ex;
httpExceptionListener.onRejectedExecutionException(ex, httptMethod, httpRequestPath, context);
} catch (ConnectException ex) {
processException = ex;
httpExceptionListener.onConnectException(ex, httptMethod, httpRequestPath, context);
} catch (IOException | UnresolvedAddressException ex) {//SocketException,
processException = ex;
Throwable cause = ExceptionUtils.getRootCause(ex);
if (cause == null) {
cause = ex;
Expand All @@ -139,13 +145,13 @@ protected ProcessorSettings service(final ChannelHandlerContext ctx, final HttpH
httpExceptionListener.onIOException(ex, httptMethod, httpRequestPath, context);
}
} catch (InterruptedException ex) {
processException = ex;
httpExceptionListener.onInterruptedException(ex, httptMethod, httpRequestPath, context);
} catch (Throwable ex) {
processException = ex;
httpExceptionListener.onUnexpectedException(ex, processor, ctx, httpRequestHeaders, httptMethod, httpRequestPath, queryParams, httpPostRequestBody, context);
} finally {
if (preProcessSuccess) {
httpLifecycleListener.afterProcess(processor, ctx, httpRequestHeaders, httptMethod, httpRequestPath, queryParams, httpPostRequestBody, context);
}
httpLifecycleListener.afterProcess(preProcessResult, processResult, processException, processor, ctx, httpRequestHeaders, httptMethod, httpRequestPath, queryParams, httpPostRequestBody, context);
context.poi(BootPOI.PROCESS_END);
}
return processorSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void bind(NioConfig nioCfg, StringBuilder memo) throws InterruptedExcepti
long completed = tpe.getCompletedTaskCount();
long pingHit = NioCounter.COUNTER_PING_HIT.get();
long totalHit = bizHit + pingHit;
long checksum = hps + tps + active + queue + activeChannel + totalChannel + totalHit + bizHit + task + completed + active + pool + core + max + largest;
long checksum = hps + tps + active + queue + activeChannel + bizHit + task + completed + active + pool + core + max + largest;
if (lastChecksum.get() != checksum) {
lastChecksum.set(checksum);
log.debug(() -> "hps=" + hps + ", tps=" + tps + ", activeChannel=" + activeChannel + ", totalChannel=" + totalChannel + ", totalHit=" + totalHit + " (ping" + pingHit + " + biz" + bizHit + "), task=" + task + ", completed=" + completed + ", queue=" + queue + ", active=" + active + ", pool=" + pool + ", core=" + core + ", max=" + max + ", largest=" + largest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public interface RequestProcessor {

boolean authorizationCheck(final ChannelHandlerContext channelHandlerCtx, final HttpHeaders httpHeaders, final String httpRequestPath, final Map<String, List<String>> queryParams, final String httpPostRequestBody, final ServiceContext context, int badRequestErrorCode) throws Throwable;

void process(ChannelHandlerContext ctx, HttpHeaders httpRequestHeaders, String httpRequestPath, Map<String, List<String>> queryParams, String httpPostRequestBody, ServiceContext context) throws Throwable;
Object process(ChannelHandlerContext ctx, HttpHeaders httpRequestHeaders, String httpRequestPath, Map<String, List<String>> queryParams, String httpPostRequestBody, ServiceContext context) throws Throwable;

}
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public boolean authorizationCheck(final ChannelHandlerContext channelHandlerCtx,
}

@Override
public void process(final ChannelHandlerContext channelHandlerCtx, final HttpHeaders httpHeaders, final String httpRequestPath, final Map<String, List<String>> queryParams, final String httpPostRequestBody, final ServiceContext context) throws Throwable {
public Object process(final ChannelHandlerContext channelHandlerCtx, final HttpHeaders httpHeaders, final String httpRequestPath, final Map<String, List<String>> queryParams, final String httpPostRequestBody, final ServiceContext context) throws Throwable {
//2. invoke
Object ret;
Object[] paramValues = new Object[parameterSize];
Expand All @@ -403,20 +403,20 @@ public void process(final ChannelHandlerContext channelHandlerCtx, final HttpHea
paramValues[i] = parameterList.get(i).value(request, context);
}
if (context.error() != null) {
return;
return null;
}
}
try {
context.poi(BootPOI.BIZ_BEGIN);
if (rejectWhenHealthCheckFailed && !HealthMonitor.isHealthCheckSuccess()) {
context.status(HttpResponseStatus.BAD_GATEWAY)
.error(new Err(BootErrorCode.SERVICE_HEALTH_CHECK_FAILED, null, null, null, "Service health check failed: " + HealthMonitor.getStatusReasonHealthCheck()));
return;
return null;
}
if (rejectWhenPaused && HealthMonitor.isServicePaused()) {
context.status(HttpResponseStatus.SERVICE_UNAVAILABLE)
.error(new Err(BootErrorCode.SERVICE_PAUSED, null, null, null, "Service is paused: " + HealthMonitor.getStatusReasonPaused()));
return;
return null;
}

ret = javaMethod.invoke(javaInstance, paramValues);
Expand Down Expand Up @@ -489,6 +489,7 @@ public void process(final ChannelHandlerContext channelHandlerCtx, final HttpHea
}
}
}
return ret;
}

public boolean hasMatrixPara() {
Expand Down
Loading