Skip to content

Commit 870c9af

Browse files
Feature2.4.9 (#279)
* enable configurable TimeZone for JSON parser in Nio and Http config * updated log4j2.xml * updated log4j2.xml * wip * wip * afterProcess only get triggered when beforeProcess success * release2.4.9
1 parent 4c65e81 commit 870c9af

File tree

15 files changed

+123
-96
lines changed

15 files changed

+123
-96
lines changed

pom.xml

Lines changed: 17 additions & 7 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.8</version>
7+
<version>2.4.9</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,
@@ -151,6 +151,16 @@
151151
<autoReleaseAfterClose>true</autoReleaseAfterClose>
152152
</configuration>
153153
</plugin>
154+
155+
<!-- <plugin>-->
156+
<!-- <groupId>org.sonatype.central</groupId>-->
157+
<!-- <artifactId>central-publishing-maven-plugin</artifactId>-->
158+
<!-- <version>0.5.0</version>-->
159+
<!-- <extensions>true</extensions>-->
160+
<!-- <configuration>-->
161+
<!-- <publishingServerId>central</publishingServerId>-->
162+
<!-- </configuration>-->
163+
<!-- </plugin>-->
154164
</plugins>
155165
</build>
156166
<!-- Central Repository info -->
@@ -171,8 +181,8 @@
171181
<properties>
172182
<!-- common properties and dependencies -->
173183
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
174-
<maven.compiler.source>11</maven.compiler.source>
175-
<maven.compiler.target>11</maven.compiler.target>
184+
<maven.compiler.source>17</maven.compiler.source>
185+
<maven.compiler.target>17</maven.compiler.target>
176186
<maven.clean.version>3.3.2</maven.clean.version>
177187
<maven.compiler.version>3.12.1</maven.compiler.version>
178188
<maven.dependency.version>3.6.1</maven.dependency.version>
@@ -199,9 +209,9 @@
199209
<netty.version>4.1.111.Final</netty.version>
200210
<netty-tcnative.version>2.0.65.Final</netty-tcnative.version>
201211
<!-- gRPC and protobuf -->
202-
<grpc.version>1.64.0</grpc.version>
212+
<grpc.version>1.65.0</grpc.version>
203213
<guava.version>33.2.1-jre</guava.version>
204-
<protobuf.version>4.27.1</protobuf.version>
214+
<protobuf.version>4.27.2</protobuf.version>
205215
<!-- Web JAX-RS -->
206216
<swagger.core.version>2.2.22</swagger.core.version>
207217
<!--<elastic-apm.version>1.36.0</elastic-apm.version>-->
@@ -215,7 +225,7 @@
215225
<reflections.version>0.10.2</reflections.version>
216226

217227
<!-- JSON/XML/Bean Validation -->
218-
<jackson.version>2.17.1</jackson.version>
228+
<jackson.version>2.17.2</jackson.version>
219229
<!-- Bean Validation -->
220230
<hibernate-validator.version>8.0.1.Final</hibernate-validator.version>
221231
<jakarta.el.version>6.0.0</jakarta.el.version>
@@ -248,7 +258,7 @@
248258

249259
<!-- Testing -->
250260
<testng.version>7.10.2</testng.version>
251-
<jdbc.version>8.4.0</jdbc.version>
261+
<jdbc.version>9.0.0</jdbc.version>
252262
</properties>
253263

254264
<dependencies>

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import java.util.Map;
3030
import java.util.Properties;
3131
import java.util.Set;
32-
import java.util.TimeZone;
3332
import java.util.concurrent.ThreadPoolExecutor;
3433
import java.util.stream.Collectors;
3534

@@ -207,10 +206,6 @@ public Map<Integer, Integer> getBootErrorCodeMapping() {
207206
@Config(key = "backoffice.executor.allowCoreThreadTimeOut", defaultValue = "false")
208207
private boolean allowCoreThreadTimeOut = false;
209208

210-
@Config(key = "backoffice.jsonParser.TimeZone", desc = "The ID for a TimeZone, either an abbreviation such as \"PST\", a full name such as \"America/Los_Angeles\", or a custom ID such as \"GMT-8:00\", or \"default\" as system default timezone.", defaultValue = "UTC")
211-
private TimeZone timeZone = TimeZone.getTimeZone("UTC");//TimeZone.getDefault();
212-
213-
214209
@ConfigHeader(title = "4.1 Default Path/File Naming")
215210
@Config(key = "naming.folder.domainPrefix", defaultValue = "standalone")
216211
private String domainFolderPrefix = "standalone";
@@ -334,10 +329,6 @@ public String getPortInUseAlertMessage() {
334329
return portInUseAlertMessage;
335330
}
336331

337-
public TimeZone getTimeZone() {
338-
return timeZone;
339-
}
340-
341332
public String getDomainFolderPrefix() {
342333
return domainFolderPrefix;
343334
}

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 = "SummerBoot.jExpress 2.4.8";
28+
String VERSION = "SummerBoot.jExpress 2.4.9";
2929
String JEXPRESS_PACKAGE_NAME = "org.summerboot.jexpress";
3030

3131
String DEFAULT_ADMIN_MM = "changeit";

src/main/java/org/summerboot/jexpress/integration/cache/BootCache.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ public interface BootCache {
3030
* this is a Distributed non-blocking version of lock() method; it attempts
3131
* to acquire the lock immediately, return true if locking succeeds
3232
*
33-
* @param lockName the name of the tryLock
34-
* @param unlockPassword unlockPassword is to be used for unlock. To protect
35-
* a tryLock from being unlocked by anyone, a tryLock cannot be released
36-
* when unlockPassword not match
37-
* @param millisecondsToExpireIncaseUnableToUnlock expire time of tryLock in
38-
* case unable to unlock (e.g. exception/error before executing unlock)
33+
* @param lockName the name of the tryLock
34+
* @param unlockPassword unlockPassword is to be used for unlock. To protect
35+
* a tryLock from being unlocked by anyone, a tryLock cannot be released
36+
* when unlockPassword not match
37+
* @param ttlToExpireIncaseUnableToUnlock expire time of tryLock in
38+
* case unable to unlock (e.g. exception/error before executing unlock)
39+
* @param timeUnit
3940
* @return the result of get tryLock
4041
*/
41-
boolean tryLock(String lockName, String unlockPassword, long millisecondsToExpireIncaseUnableToUnlock);
42+
boolean tryLock(String lockName, String unlockPassword, long ttlToExpireIncaseUnableToUnlock, TimeUnit timeUnit);
4243

4344
/**
4445
* unlocks the Distributed Lock instance
@@ -54,16 +55,6 @@ default String generateUnlockPassword() {
5455
return UUID.randomUUID().toString() + "_" + BootConstant.PID + "_" + Thread.currentThread().getName();
5556
}
5657

57-
/**
58-
* @param key
59-
* @param unlockPassword
60-
* @param ttlMinute
61-
* @return true is debounced (failed to acquire lock), false is not debounced (acquired lock successfully
62-
*/
63-
default boolean debounced(String key, String unlockPassword, long ttlMinute) {
64-
return !tryLock(key, unlockPassword, ttlMinute * 60000);
65-
}
66-
6758
/**
6859
* @param key
6960
* @param unlockPassword
@@ -72,7 +63,7 @@ default boolean debounced(String key, String unlockPassword, long ttlMinute) {
7263
* @return true is debounced (failed to acquire lock), false is not debounced (acquired lock successfully
7364
*/
7465
default boolean debounced(String key, String unlockPassword, long ttl, TimeUnit timeUnit) {
75-
return !tryLock(key, unlockPassword, timeUnit.toMillis(ttl));
66+
return !tryLock(key, unlockPassword, ttl, timeUnit);
7667
}
7768

7869
/**

src/main/java/org/summerboot/jexpress/integration/cache/BootCache_RedisImple.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,19 @@ protected void onNoticeAutoFailover(String info, String newNode) {
216216
* this is a Distributed non-blocking version of lock() method; it attempts
217217
* to acquire the lock immediately, return true if locking succeeds
218218
*
219-
* @param lockName the name of the tryLock
220-
* @param unlockPassword unlockPassword is to be used for unlock. To protect
221-
* a tryLock from being unlocked by anyone, a tryLock cannot be released
222-
* when unlockPassword not match
223-
* @param millisecondsToExpireIncaseUnableToUnlock expire time of tryLock in
224-
* case unable to unlock (e.g. exception/error before executing unlock)
219+
* @param lockName the name of the tryLock
220+
* @param unlockPassword unlockPassword is to be used for unlock. To protect
221+
* a tryLock from being unlocked by anyone, a tryLock cannot be released
222+
* when unlockPassword not match
223+
* @param ttlToExpireIncaseUnableToUnlock expire time of tryLock in
224+
* case unable to unlock (e.g. exception/error before executing unlock)
225225
* @return the result of get tryLock
226226
*/
227227
@Override
228-
public boolean tryLock(String lockName, String unlockPassword, long millisecondsToExpireIncaseUnableToUnlock) {
228+
public boolean tryLock(String lockName, String unlockPassword, long ttlToExpireIncaseUnableToUnlock, TimeUnit timeUnit) {
229229
final Holder<Boolean> holder = new Holder<>(false);
230230
execute(true, jedis -> {
231-
SetParams p = new SetParams().nx().px(millisecondsToExpireIncaseUnableToUnlock);
231+
SetParams p = new SetParams().nx().px(timeUnit.toMillis(ttlToExpireIncaseUnableToUnlock));
232232
String result = jedis.set(lockName, unlockPassword, p);
233233

234234
boolean isLocked = REDIS_SUCCESS.equalsIgnoreCase(result);

src/main/java/org/summerboot/jexpress/integration/httpclient/HttpClientConfig.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.Map;
4545
import java.util.Properties;
4646
import java.util.Set;
47+
import java.util.TimeZone;
4748
import java.util.concurrent.Executors;
4849
import java.util.concurrent.ScheduledExecutorService;
4950
import java.util.concurrent.ThreadPoolExecutor;
@@ -149,6 +150,8 @@ protected void generateTemplate_truststore(StringBuilder sb) {
149150
protected volatile boolean fromJsonCaseInsensitive = false;
150151
@Config(key = "httpclient.fromJson.failOnUnknownProperties")
151152
protected volatile boolean fromJsonFailOnUnknownProperties = true;
153+
@Config(key = "httpclient.fromJson.TimeZone", desc = "The ID for a TimeZone, either an abbreviation such as \"UTC\", a full name such as \"America/Toronto\", or a custom ID such as \"GMT-8:00\", or \"system\" as system default timezone.", defaultValue = "system")
154+
protected TimeZone jsonParserTimeZone = TimeZone.getDefault();
152155

153156
//3.2 HTTP Client Performance
154157
@ConfigHeader(title = "2. HTTP Client Performance")
@@ -237,7 +240,7 @@ protected void loadCustomizedConfigs(File cfgFile, boolean isReal, ConfigUtil he
237240
}
238241
});
239242

240-
RPCResult.init(fromJsonFailOnUnknownProperties, fromJsonCaseInsensitive);
243+
RPCResult.init(jsonParserTimeZone, fromJsonFailOnUnknownProperties, fromJsonCaseInsensitive);
241244

242245
// 3.1 HTTP Client keystore
243246
KeyManager[] keyManagers = kmf == null ? null : kmf.getKeyManagers();
@@ -403,6 +406,10 @@ public boolean isFromJsonFailOnUnknownProperties() {
403406
return fromJsonFailOnUnknownProperties;
404407
}
405408

409+
public TimeZone getJsonParserTimeZone() {
410+
return jsonParserTimeZone;
411+
}
412+
406413
public long getHttpConnectTimeoutMs() {
407414
return httpConnectTimeoutMs;
408415
}

src/main/java/org/summerboot/jexpress/integration/httpclient/RPCResult.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
2525
import io.netty.handler.codec.http.HttpResponseStatus;
2626
import org.apache.commons.lang3.StringUtils;
27-
import org.summerboot.jexpress.boot.BackOffice;
2827
import org.summerboot.jexpress.boot.BootErrorCode;
2928
import org.summerboot.jexpress.nio.server.domain.Err;
3029
import org.summerboot.jexpress.nio.server.domain.ServiceContext;
@@ -33,6 +32,7 @@
3332
import java.net.http.HttpRequest;
3433
import java.net.http.HttpResponse;
3534
import java.util.List;
35+
import java.util.TimeZone;
3636

3737
/**
3838
* @param <T> Success(JSON) result type
@@ -41,29 +41,27 @@
4141
*/
4242
public class RPCResult<T, E extends ServiceErrorConvertible> {
4343

44-
protected static boolean isFromJsonFailOnUnknownProperties = true;
4544

4645
public static ObjectMapper DefaultJacksonMapper = new ObjectMapper();
4746

48-
public static void update(ObjectMapper objectMapper) {
47+
public static void update(ObjectMapper objectMapper, TimeZone timeZone, boolean isFromJsonFailOnUnknownProperties) {
4948
objectMapper.registerModules(new JavaTimeModule());
50-
objectMapper.setTimeZone(BackOffice.agent.getTimeZone());
49+
objectMapper.setTimeZone(timeZone);
5150
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
5251
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
5352
objectMapper.configure(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES, false);
5453
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, isFromJsonFailOnUnknownProperties);
5554
}
5655

57-
public static void init(boolean fromJsonFailOnUnknownProperties, boolean fromJsonCaseInsensitive) {
58-
isFromJsonFailOnUnknownProperties = fromJsonFailOnUnknownProperties;
56+
public static void init(TimeZone timeZone, boolean fromJsonFailOnUnknownProperties, boolean fromJsonCaseInsensitive) {
5957
if (fromJsonCaseInsensitive) {
6058
DefaultJacksonMapper = JsonMapper.builder().configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true).build();
6159
}
62-
update(DefaultJacksonMapper);
60+
update(DefaultJacksonMapper, timeZone, fromJsonFailOnUnknownProperties);
6361
}
6462

6563
static {
66-
init(true, false);
64+
init(TimeZone.getDefault(), true, false);
6765
}
6866

6967
protected final HttpRequest originRequest;

src/main/java/org/summerboot/jexpress/integration/quartz/BootJobListener.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ protected void scheduleFixedDelayJob(final JobExecutionContext context, final Jo
105105
.build();
106106
scheduler.rescheduleJob(currentTriggerKey, nextTrigger);
107107
log.info(desc + " scheduled@" + nextTime);
108-
109108
} catch (SchedulerException ex) {
110109
log.error("failed to reschedule the job with triger: {}", currentTriggerKey, ex);
111110
}

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ 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;
7172
try {
7273
// step1. find controller and the action in it
7374
processor = getRequestProcessor(httptMethod, httpRequestPath);
@@ -105,10 +106,12 @@ protected ProcessorSettings service(final ChannelHandlerContext ctx, final HttpH
105106
if (authenticator != null && !authenticator.customizedAuthorizationCheck(processor, httpRequestHeaders, httpRequestPath, context)) {
106107
return processorSettings;
107108
}
108-
if (!httpLifecycleListener.beforeProcess(processor, httpRequestHeaders, httpRequestPath, context)) {
109+
preProcessSuccess = httpLifecycleListener.beforeProcess(processor, httpRequestHeaders, httpRequestPath, context);
110+
if (preProcessSuccess) {
111+
processor.process(ctx, httpRequestHeaders, httpRequestPath, queryParams, httpPostRequestBody, context);
112+
} else {
109113
return processorSettings;
110114
}
111-
processor.process(ctx, httpRequestHeaders, httpRequestPath, queryParams, httpPostRequestBody, context);
112115
//} catch (ExpiredJwtException | SignatureException | MalformedJwtException ex) {
113116
// nak(context, HttpResponseStatus.UNAUTHORIZED, BootErrorCode.AUTH_INVALID_TOKEN, "Invalid JWT");
114117
} catch (NamingException ex) {
@@ -140,7 +143,9 @@ protected ProcessorSettings service(final ChannelHandlerContext ctx, final HttpH
140143
} catch (Throwable ex) {
141144
httpExceptionListener.onUnexpectedException(ex, processor, ctx, httpRequestHeaders, httptMethod, httpRequestPath, queryParams, httpPostRequestBody, context);
142145
} finally {
143-
httpLifecycleListener.afterProcess(processor, ctx, httpRequestHeaders, httptMethod, httpRequestPath, queryParams, httpPostRequestBody, context);
146+
if (preProcessSuccess) {
147+
httpLifecycleListener.afterProcess(processor, ctx, httpRequestHeaders, httptMethod, httpRequestPath, queryParams, httpPostRequestBody, context);
148+
}
144149
context.poi(BootPOI.PROCESS_END);
145150
}
146151
return processorSettings;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ protected void initChannelPipeline(ChannelPipeline channelPipeline, NioConfig ni
8787
//channelPipeline.addLast(new HttpContentCompressor());
8888

8989
// 3*. File upload: after codec, chunked and before aggregator
90-
if (namedFileUpload != null) {
90+
if (namedFileUpload != null && !namedFileUpload.isEmpty()) {
9191
for (String named : namedFileUpload) {
9292
ch = injector.getInstance(Key.get(ChannelHandler.class, Names.named(named)));
9393
channelPipeline.addLast("FileUpload_" + named, ch);// to support file upload, must before HttpObjectAggregator

0 commit comments

Comments
 (0)