Skip to content

Commit c3ee71c

Browse files
refactoring (#284)
1 parent af6cab1 commit c3ee71c

File tree

9 files changed

+41
-29
lines changed

9 files changed

+41
-29
lines changed

pom.xml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>org.summerboot</groupId>
66
<artifactId>jexpress</artifactId>
7-
<version>2.4.11</version>
7+
<version>2.4.12</version>
88
<packaging>jar</packaging>
99
<name>Summer Boot jExpress</name>
1010
<description>Summer Boot jExpress focuses on solving non-functional and operational maintainability requirements,
@@ -62,14 +62,15 @@
6262
<plugins>
6363
<plugin>
6464
<!--for unit test-->
65+
<groupId>org.apache.maven.plugins</groupId>
6566
<artifactId>maven-surefire-plugin</artifactId>
66-
<version>3.2.5</version>
67+
<version>3.5.0</version>
6768
</plugin>
6869
<plugin>
6970
<groupId>org.apache.maven.plugins</groupId>
7071
<artifactId>maven-scm-plugin</artifactId>
7172
<!-- <version>1.12.2</version> -->
72-
<version>2.0.0-M1</version>
73+
<version>2.1.0</version>
7374
</plugin>
7475
<!--Source-->
7576
<plugin>
@@ -90,7 +91,7 @@
9091
<plugin>
9192
<groupId>org.apache.maven.plugins</groupId>
9293
<artifactId>maven-javadoc-plugin</artifactId>
93-
<version>3.6.3</version>
94+
<version>3.10.0</version>
9495
<configuration>
9596
<source>17</source>
9697
<!-- <aggregate>true</aggregate>-->
@@ -111,9 +112,10 @@
111112

112113
<!--Deploy-->
113114
<plugin>
115+
<groupId>org.apache.maven.plugins</groupId>
114116
<artifactId>maven-deploy-plugin</artifactId>
115117
<!-- <version>2.8.2</version> -->
116-
<version>3.1.1</version>
118+
<version>3.1.3</version>
117119
<executions>
118120
<execution>
119121
<id>default-deploy</id>
@@ -128,7 +130,7 @@
128130
<plugin>
129131
<groupId>org.apache.maven.plugins</groupId>
130132
<artifactId>maven-gpg-plugin</artifactId>
131-
<version>3.2.2</version>
133+
<version>3.2.5</version>
132134
<executions>
133135
<execution>
134136
<phase>verify</phase>
@@ -143,7 +145,7 @@
143145
<plugin>
144146
<groupId>org.sonatype.plugins</groupId>
145147
<artifactId>nexus-staging-maven-plugin</artifactId>
146-
<version>1.6.13</version>
148+
<version>1.7.0</version>
147149
<extensions>true</extensions>
148150
<configuration>
149151
<serverId>ossrh</serverId>
@@ -206,7 +208,7 @@
206208
<jwt.version>0.12.6</jwt.version>
207209

208210
<!-- NIO Netty -->
209-
<netty.version>4.1.112.Final</netty.version>
211+
<netty.version>4.1.113.Final</netty.version>
210212
<netty-tcnative.version>2.0.66.Final</netty-tcnative.version>
211213
<!-- gRPC and protobuf -->
212214
<grpc.version>1.66.0</grpc.version>
@@ -241,7 +243,7 @@
241243
<!-- Cache -->
242244
<jedis.version>5.1.5</jedis.version>
243245

244-
<quartz.version>2.5.0-rc1</quartz.version>
246+
<quartz.version>2.3.2</quartz.version>
245247
<mqtt.version>1.2.5</mqtt.version>
246248

247249
<!-- Template Engine -->

src/main/java/org/summerboot/jexpress/boot/BootConstant.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface BootConstant {
2525
String APP_ID = String.format("%06d", new Random().nextInt(999999));
2626

2727
//version
28-
String VERSION = "jExpress 2.4.11";
28+
String VERSION = "jExpress 2.4.12";
2929
String JEXPRESS_PACKAGE_NAME = "org.summerboot.jexpress";
3030

3131
String DEFAULT_ADMIN_MM = "changeit";

src/main/java/org/summerboot/jexpress/boot/event/HttpLifecycleHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public boolean beforeProcess(RequestProcessor processor, HttpHeaders httpRequest
4747
}
4848

4949
@Override
50-
public void afterProcess(RequestProcessor processor, ChannelHandlerContext ctx, HttpHeaders httpRequestHeaders, HttpMethod httptMethod, String httpRequestPath, Map<String, List<String>> queryParams, String httpPostRequestBody, ServiceContext context) {
50+
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) {
5151
// if (httpRequestHeaders.contains(HttpHeaderNames.Sensitive_Header)) {
5252
// httpRequestHeaders.set(HttpHeaderNames.Sensitive_Header, "***");// protect Sensitive_Header from being logged
5353
// }

src/main/java/org/summerboot/jexpress/boot/event/HttpLifecycleListener.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public interface HttpLifecycleListener {
4949
/**
5050
* step1 - after process is done, before sending response to client
5151
*
52+
* @param preProcessResult
53+
* @param processResult
54+
* @param processException
5255
* @param processor
5356
* @param ctx
5457
* @param httpRequestHeaders
@@ -58,7 +61,7 @@ public interface HttpLifecycleListener {
5861
* @param httpPostRequestBody
5962
* @param context
6063
*/
61-
void afterProcess(RequestProcessor processor, ChannelHandlerContext ctx, HttpHeaders httpRequestHeaders, HttpMethod httptMethod, String httpRequestPath,
64+
void afterProcess(boolean preProcessResult, Object processResult, Throwable processException, RequestProcessor processor, ChannelHandlerContext ctx, HttpHeaders httpRequestHeaders, HttpMethod httptMethod, String httpRequestPath,
6265
Map<String, List<String>> queryParams, String httpPostRequestBody, ServiceContext context);
6366

6467

src/main/java/org/summerboot/jexpress/nio/grpc/GRPCServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ protected GRPCServiceCounter initThreadPool(ThreadPoolExecutor tpe, NIOStatusLis
136136
long task = tpe.getTaskCount();
137137
long completed = tpe.getCompletedTaskCount();
138138
//long checksum = hps + tps + active + queue + activeChannel + totalChannel + totalHit + bizHit + task + completed + active + pool + core + max + largest;
139-
long checksum = hps + tps + active + queue + totalHit + bizHit + /*task + completed +*/ active + pool + core + max + largest;
139+
long checksum = hps + tps + active + queue /*+ activeChannel*/ + bizHit + task + completed + active + pool + core + max + largest;
140140
if (lastChecksum.get() != checksum) {
141141
lastChecksum.set(checksum);
142142
//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);

src/main/java/org/summerboot/jexpress/nio/server/BootHttpRequestHandler.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ protected ProcessorSettings service(final ChannelHandlerContext ctx, final HttpH
6868
final String httpRequestPath, final Map<String, List<String>> queryParams, final String httpPostRequestBody, final ServiceContext context) {
6969
ProcessorSettings processorSettings = null;
7070
RequestProcessor processor = null;
71-
boolean preProcessSuccess = false;
71+
boolean preProcessResult = false;
72+
Object processResult = null;
73+
Throwable processException = null;
7274
try {
7375
// step1. find controller and the action in it
7476
processor = getRequestProcessor(httptMethod, httpRequestPath);
@@ -106,29 +108,33 @@ protected ProcessorSettings service(final ChannelHandlerContext ctx, final HttpH
106108
if (authenticator != null && !authenticator.customizedAuthorizationCheck(processor, httpRequestHeaders, httpRequestPath, context)) {
107109
return processorSettings;
108110
}
109-
preProcessSuccess = httpLifecycleListener.beforeProcess(processor, httpRequestHeaders, httpRequestPath, context);
110-
if (preProcessSuccess) {
111-
processor.process(ctx, httpRequestHeaders, httpRequestPath, queryParams, httpPostRequestBody, context);
112-
} else {
111+
preProcessResult = httpLifecycleListener.beforeProcess(processor, httpRequestHeaders, httpRequestPath, context);
112+
if (!preProcessResult) {
113113
return processorSettings;
114114
}
115-
//} catch (ExpiredJwtException | SignatureException | MalformedJwtException ex) {
116-
// nak(context, HttpResponseStatus.UNAUTHORIZED, BootErrorCode.AUTH_INVALID_TOKEN, "Invalid JWT");
115+
processResult = processor.process(ctx, httpRequestHeaders, httpRequestPath, queryParams, httpPostRequestBody, context);
117116
} catch (NamingException ex) {
117+
processException = ex;
118118
httpExceptionListener.onNamingException(ex, httptMethod, httpRequestPath, context);
119119
} catch (PersistenceException ex) {
120+
processException = ex;
120121
httpExceptionListener.onPersistenceException(ex, httptMethod, httpRequestPath, context);
121122
} catch (HttpConnectTimeoutException ex) {
123+
processException = ex;
122124
// a connection, over which an HttpRequest is intended to be sent, is not successfully established within a specified time period.
123125
httpExceptionListener.onHttpConnectTimeoutException(ex, httptMethod, httpRequestPath, context);
124126
} catch (HttpTimeoutException ex) {
127+
processException = ex;
125128
// a context is not received within a specified time period.
126129
httpExceptionListener.onHttpTimeoutException(ex, httptMethod, httpRequestPath, context);
127130
} catch (RejectedExecutionException ex) {
131+
processException = ex;
128132
httpExceptionListener.onRejectedExecutionException(ex, httptMethod, httpRequestPath, context);
129133
} catch (ConnectException ex) {
134+
processException = ex;
130135
httpExceptionListener.onConnectException(ex, httptMethod, httpRequestPath, context);
131136
} catch (IOException | UnresolvedAddressException ex) {//SocketException,
137+
processException = ex;
132138
Throwable cause = ExceptionUtils.getRootCause(ex);
133139
if (cause == null) {
134140
cause = ex;
@@ -139,13 +145,13 @@ protected ProcessorSettings service(final ChannelHandlerContext ctx, final HttpH
139145
httpExceptionListener.onIOException(ex, httptMethod, httpRequestPath, context);
140146
}
141147
} catch (InterruptedException ex) {
148+
processException = ex;
142149
httpExceptionListener.onInterruptedException(ex, httptMethod, httpRequestPath, context);
143150
} catch (Throwable ex) {
151+
processException = ex;
144152
httpExceptionListener.onUnexpectedException(ex, processor, ctx, httpRequestHeaders, httptMethod, httpRequestPath, queryParams, httpPostRequestBody, context);
145153
} finally {
146-
if (preProcessSuccess) {
147-
httpLifecycleListener.afterProcess(processor, ctx, httpRequestHeaders, httptMethod, httpRequestPath, queryParams, httpPostRequestBody, context);
148-
}
154+
httpLifecycleListener.afterProcess(preProcessResult, processResult, processException, processor, ctx, httpRequestHeaders, httptMethod, httpRequestPath, queryParams, httpPostRequestBody, context);
149155
context.poi(BootPOI.PROCESS_END);
150156
}
151157
return processorSettings;

src/main/java/org/summerboot/jexpress/nio/server/NioServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public void bind(NioConfig nioCfg, StringBuilder memo) throws InterruptedExcepti
249249
long completed = tpe.getCompletedTaskCount();
250250
long pingHit = NioCounter.COUNTER_PING_HIT.get();
251251
long totalHit = bizHit + pingHit;
252-
long checksum = hps + tps + active + queue + activeChannel + totalChannel + totalHit + bizHit + task + completed + active + pool + core + max + largest;
252+
long checksum = hps + tps + active + queue + activeChannel + bizHit + task + completed + active + pool + core + max + largest;
253253
if (lastChecksum.get() != checksum) {
254254
lastChecksum.set(checksum);
255255
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);

src/main/java/org/summerboot/jexpress/nio/server/RequestProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ public interface RequestProcessor {
4141

4242
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;
4343

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

4646
}

src/main/java/org/summerboot/jexpress/nio/server/ws/rs/JaxRsRequestProcessor.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ public boolean authorizationCheck(final ChannelHandlerContext channelHandlerCtx,
393393
}
394394

395395
@Override
396-
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 {
396+
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 {
397397
//2. invoke
398398
Object ret;
399399
Object[] paramValues = new Object[parameterSize];
@@ -403,20 +403,20 @@ public void process(final ChannelHandlerContext channelHandlerCtx, final HttpHea
403403
paramValues[i] = parameterList.get(i).value(request, context);
404404
}
405405
if (context.error() != null) {
406-
return;
406+
return null;
407407
}
408408
}
409409
try {
410410
context.poi(BootPOI.BIZ_BEGIN);
411411
if (rejectWhenHealthCheckFailed && !HealthMonitor.isHealthCheckSuccess()) {
412412
context.status(HttpResponseStatus.BAD_GATEWAY)
413413
.error(new Err(BootErrorCode.SERVICE_HEALTH_CHECK_FAILED, null, null, null, "Service health check failed: " + HealthMonitor.getStatusReasonHealthCheck()));
414-
return;
414+
return null;
415415
}
416416
if (rejectWhenPaused && HealthMonitor.isServicePaused()) {
417417
context.status(HttpResponseStatus.SERVICE_UNAVAILABLE)
418418
.error(new Err(BootErrorCode.SERVICE_PAUSED, null, null, null, "Service is paused: " + HealthMonitor.getStatusReasonPaused()));
419-
return;
419+
return null;
420420
}
421421

422422
ret = javaMethod.invoke(javaInstance, paramValues);
@@ -489,6 +489,7 @@ public void process(final ChannelHandlerContext channelHandlerCtx, final HttpHea
489489
}
490490
}
491491
}
492+
return ret;
492493
}
493494

494495
public boolean hasMatrixPara() {

0 commit comments

Comments
 (0)