From a20474a37ad9e3cdb448e0cf32f7cc75f6988cf9 Mon Sep 17 00:00:00 2001 From: Summer Boot Framework Date: Sat, 11 Nov 2023 09:36:24 -0500 Subject: [PATCH 01/11] enabled customized delimiter of collection in @Config with new collectionDelimiter field --- pom.xml | 10 +++++----- .../summerboot/jexpress/boot/BootConstant.java | 2 +- .../summerboot/jexpress/boot/SummerBigBang.java | 2 +- .../jexpress/boot/config/BootConfig.java | 3 ++- .../jexpress/boot/config/annotation/Config.java | 2 ++ .../nio/server/ws/rs/JaxRsRequestParameter.java | 3 ++- .../summerboot/jexpress/util/FormatterUtil.java | 3 +++ .../summerboot/jexpress/util/ReflectionUtil.java | 15 ++++++++------- 8 files changed, 24 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 0325e8c9..e174459f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.summerboot jexpress - 2.3.11 + 2.3.12-SNAPSHOT jar Summer Boot jExpress Summer Boot jExpress focuses on solving non-functional and operational maintainability requirements, some of which Spring Boot has (may) not yet provided @@ -188,12 +188,12 @@ 0.11.5 - 4.1.100.Final + 4.1.101.Final 2.0.62.Final 1.59.0 32.1.3-jre - 3.24.4 + 3.25.0 2.2.18 @@ -213,11 +213,11 @@ 4.0.2 - 5.1.0 + 7.0.0 6.3.1.Final - 5.0.1 + 5.1.0 5.0.2 diff --git a/src/main/java/org/summerboot/jexpress/boot/BootConstant.java b/src/main/java/org/summerboot/jexpress/boot/BootConstant.java index 42f395ce..c20cc925 100644 --- a/src/main/java/org/summerboot/jexpress/boot/BootConstant.java +++ b/src/main/java/org/summerboot/jexpress/boot/BootConstant.java @@ -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"; diff --git a/src/main/java/org/summerboot/jexpress/boot/SummerBigBang.java b/src/main/java/org/summerboot/jexpress/boot/SummerBigBang.java index c318af57..1f1e40f0 100644 --- a/src/main/java/org/summerboot/jexpress/boot/SummerBigBang.java +++ b/src/main/java/org/summerboot/jexpress/boot/SummerBigBang.java @@ -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); } } diff --git a/src/main/java/org/summerboot/jexpress/boot/config/BootConfig.java b/src/main/java/org/summerboot/jexpress/boot/config/BootConfig.java index 96a3c6f2..7f5b8310 100644 --- a/src/main/java/org/summerboot/jexpress/boot/config/BootConfig.java +++ b/src/main/java/org/summerboot/jexpress/boot/config/BootConfig.java @@ -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); } } diff --git a/src/main/java/org/summerboot/jexpress/boot/config/annotation/Config.java b/src/main/java/org/summerboot/jexpress/boot/config/annotation/Config.java index 7ed52962..b4c2edd1 100644 --- a/src/main/java/org/summerboot/jexpress/boot/config/annotation/Config.java +++ b/src/main/java/org/summerboot/jexpress/boot/config/annotation/Config.java @@ -59,5 +59,7 @@ public enum Validate { * @return */ String callbackMethodName4Dump() default ""; + + String collectionDelimiter() default ","; } diff --git a/src/main/java/org/summerboot/jexpress/nio/server/ws/rs/JaxRsRequestParameter.java b/src/main/java/org/summerboot/jexpress/nio/server/ws/rs/JaxRsRequestParameter.java index 0d194fce..75f33ba9 100644 --- a/src/main/java/org/summerboot/jexpress/nio/server/ws/rs/JaxRsRequestParameter.java +++ b/src/main/java/org/summerboot/jexpress/nio/server/ws/rs/JaxRsRequestParameter.java @@ -68,6 +68,7 @@ public enum ParamType { private boolean autoBeanValidation = false; private boolean cookieParamObj = false; private final EnumConvert.To enumConvert; + private final String collectionDelimiter = null;// TODO public JaxRsRequestParameter(String info, HttpMethod httpMethod, List consumes, Parameter param) { String error = "\n\tparameter is not allowed in " + info + "(" + param + ")\n\t - "; @@ -374,7 +375,7 @@ private Object parse(String value, String defaultValue, ServiceContext context) } } try { - return ReflectionUtil.toJavaType(targetClass, parameterizedType, value, false, false, enumConvert); + return ReflectionUtil.toJavaType(targetClass, parameterizedType, value, false, false, enumConvert, collectionDelimiter); } catch (Throwable ex) { Err e = new Err(BootErrorCode.BAD_RQUEST_DATA, null, null, ex, "Failed to parse data type: invalid " + type + "{" + key + "}=" + value); context.status(HttpResponseStatus.BAD_REQUEST).error(e); diff --git a/src/main/java/org/summerboot/jexpress/util/FormatterUtil.java b/src/main/java/org/summerboot/jexpress/util/FormatterUtil.java index 6a993033..563ca134 100644 --- a/src/main/java/org/summerboot/jexpress/util/FormatterUtil.java +++ b/src/main/java/org/summerboot/jexpress/util/FormatterUtil.java @@ -61,6 +61,9 @@ public class FormatterUtil { public static final Pattern REGEX_EMAIL_PATTERN = Pattern.compile(REGEX_EMAIL); public static String[] parseDsv(String csv, String delimiter) { + if (StringUtils.isBlank(delimiter)) { + return parseCsv(csv); + } return StringUtils.isBlank(csv) ? EMPTY_STR_ARRAY : csv.trim().split("\\s*" + delimiter + "\\s*"); } diff --git a/src/main/java/org/summerboot/jexpress/util/ReflectionUtil.java b/src/main/java/org/summerboot/jexpress/util/ReflectionUtil.java index fd9960a2..edd856df 100644 --- a/src/main/java/org/summerboot/jexpress/util/ReflectionUtil.java +++ b/src/main/java/org/summerboot/jexpress/util/ReflectionUtil.java @@ -203,19 +203,20 @@ public static List getAllSuperClasses(Class targetClass) { * @param value * @param autoDecrypt * @param isEmailRecipients + * @param collectionDelimiter * @throws java.lang.IllegalAccessException */ - public static void loadField(Object instance, Field field, String value, final boolean autoDecrypt, final boolean isEmailRecipients) throws IllegalAccessException { + public static void loadField(Object instance, Field field, String value, final boolean autoDecrypt, final boolean isEmailRecipients, String collectionDelimiter) throws IllegalAccessException { Class targetClass = field.getType(); Type genericType = field.getGenericType(); field.setAccessible(true); - field.set(instance, toJavaType(targetClass, genericType, value, autoDecrypt, isEmailRecipients, null)); + field.set(instance, toJavaType(targetClass, genericType, value, autoDecrypt, isEmailRecipients, null, collectionDelimiter)); } private static final Type[] DEFAULT_ARG_TYPES = {String.class, String.class}; public static Object toJavaType(Class targetClass, Type genericType, String value, final boolean autoDecrypt, - final boolean isEmailRecipients, EnumConvert.To enumConvert) throws IllegalAccessException { + final boolean isEmailRecipients, EnumConvert.To enumConvert, String collectionDelimiter) throws IllegalAccessException { if (StringUtils.isBlank(value)) { Object nullValue = ReflectionUtil.toStandardJavaType(null, targetClass, autoDecrypt, false, enumConvert); return nullValue; @@ -246,7 +247,7 @@ public static Object toJavaType(Class targetClass, Type genericType, String valu } if (targetClass.isArray()) { - String[] valuesStr = FormatterUtil.parseCsv(value); + String[] valuesStr = FormatterUtil.parseDsv(value, collectionDelimiter); if (valuesStr == null || valuesStr.length < 1) { return null; } @@ -257,7 +258,7 @@ public static Object toJavaType(Class targetClass, Type genericType, String valu } return array; } else if (targetClass.equals(Set.class)) { - String[] valuesStr = FormatterUtil.parseCsv(value); + String[] valuesStr = FormatterUtil.parseDsv(value, collectionDelimiter); if (valuesStr == null || valuesStr.length < 1) { return null; } @@ -268,7 +269,7 @@ public static Object toJavaType(Class targetClass, Type genericType, String valu } return Set.of((Object[]) array); } else if (targetClass.equals(SortedSet.class)) { - String[] valuesStr = FormatterUtil.parseCsv(value); + String[] valuesStr = FormatterUtil.parseDsv(value, collectionDelimiter); if (valuesStr == null || valuesStr.length < 1) { return null; } @@ -279,7 +280,7 @@ public static Object toJavaType(Class targetClass, Type genericType, String valu } return ImmutableSortedSet.copyOf(List.of((Object[]) array)); } else if (targetClass.equals(List.class)) { - String[] valuesStr = FormatterUtil.parseCsv(value); + String[] valuesStr = FormatterUtil.parseDsv(value, collectionDelimiter); if (valuesStr == null || valuesStr.length < 1) { return null; } From 265ccdb9f3083bd1327ff32fc575f1a6bd6fc00c Mon Sep 17 00:00:00 2001 From: Summer Boot Framework Date: Mon, 13 Nov 2023 10:03:49 -0500 Subject: [PATCH 02/11] refactoring --- .../jexpress/util/FormatterUtil.java | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/summerboot/jexpress/util/FormatterUtil.java b/src/main/java/org/summerboot/jexpress/util/FormatterUtil.java index 563ca134..733a4f50 100644 --- a/src/main/java/org/summerboot/jexpress/util/FormatterUtil.java +++ b/src/main/java/org/summerboot/jexpress/util/FormatterUtil.java @@ -45,53 +45,53 @@ * @author Changski Tie Zheng Zhang 张铁铮, 魏泽北, 杜旺财, 杜富贵 */ public class FormatterUtil { - + protected static Logger log = null;// = LogManager.getLogger(FormatterUtil.class); public static final long INT_MASK = 0xFFFFFFFFL;//(long) Integer.MAX_VALUE - (long) Integer.MIN_VALUE; public static final int SHORT_MASK = 0xFFFF; public static final short BYTE_MASK = 0xFF; public static final short NIBBLE_MASK = 0x0F; - + public static final String[] EMPTY_STR_ARRAY = {}; public static final String REGEX_CSV = "\\s*,\\s*"; public static final String REGEX_URL = "\\s*/\\s*"; public static final String REGEX_BINDING_MAP = "\\s*:\\s*"; public static final String REGEX_EMAIL = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$"; public static final Pattern REGEX_EMAIL_PATTERN = Pattern.compile(REGEX_EMAIL); - + public static String[] parseDsv(String csv, String delimiter) { - if (StringUtils.isBlank(delimiter)) { + if (StringUtils.isBlank(delimiter) || ",".equals(delimiter)) { return parseCsv(csv); } return StringUtils.isBlank(csv) ? EMPTY_STR_ARRAY : csv.trim().split("\\s*" + delimiter + "\\s*"); } - + public static String[] parseCsv(String csv) { return StringUtils.isBlank(csv) ? EMPTY_STR_ARRAY : csv.trim().split(REGEX_CSV); } - + public static String[] parseURL(String url) { return StringUtils.isBlank(url) ? EMPTY_STR_ARRAY : url.trim().split(REGEX_URL); } - + public static String[] parseURL(String url, boolean trim) { return StringUtils.isBlank(url) ? EMPTY_STR_ARRAY : trim ? url.trim().split(REGEX_URL) : url.split(REGEX_URL); } - + public static String toCSV(Collection a) { return a.stream().map(String::valueOf).collect(Collectors.joining(", ")); } - + public static String[] getEnumNames(Class> e) { //return Arrays.stream(MyEnum.values()).map(MyEnum::name).toArray(String[]::new); return Arrays.stream(e.getEnumConstants()).map(Enum::name).toArray(String[]::new); } - + public static Pattern INSIDE_PARENTHESES_VALUE = Pattern.compile("\\(([^)]+)\\)"); - + public static String getInsideParenthesesValue(String value) { String ret = value; // Matcher m = INSIDE_PARENTHESES_VALUE.matcher(value); @@ -105,13 +105,13 @@ public static String getInsideParenthesesValue(String value) { } return ret; } - + public static final String REGEX_FIRST_AND_LAST_B = "\\(.*\\)"; - + public static final Pattern REGEX_DEC_PATTERN = Pattern.compile(DECRYPTED_WARPER_PREFIX + REGEX_FIRST_AND_LAST_B); - + public static final Pattern REGEX_ENC_PATTERN = Pattern.compile(ENCRYPTED_WARPER_PREFIX + REGEX_FIRST_AND_LAST_B); - + public static String updateProtectedLine(String line, boolean encrypt) throws GeneralSecurityException { Matcher matcher = encrypt ? REGEX_DEC_PATTERN.matcher(line) @@ -129,7 +129,7 @@ public static String updateProtectedLine(String line, boolean encrypt) throws Ge } return null; } - + @Deprecated public static String updateProtectedLine_(String line, boolean encrypt) throws GeneralSecurityException { String ret = null; @@ -148,7 +148,7 @@ public static String updateProtectedLine_(String line, boolean encrypt) throws G } return ret; } - + public static String b2n(String s) { return StringUtils.isBlank(s) ? null : s.trim(); } @@ -166,7 +166,7 @@ public static Map parseBindingAddresss(String bindAddresses) { } return ret; } - + public static Map parseMap(String mapCVS) { //int[] ports = Arrays.stream(portsStr).mapToInt(Integer::parseInt).toArray(); Map ret = new HashMap<>(); @@ -177,24 +177,24 @@ public static Map parseMap(String mapCVS) { } return ret; } - + public static String convertTo(String value, String targetCharsetName) throws UnsupportedEncodingException { //String rawString = "Fantasticèéçà Entwickeln Sie mit Vergnügen"; return new String(value.getBytes(targetCharsetName), targetCharsetName); } - + public static String base64MimeEncode(byte[] contentBytes) { return Base64.getMimeEncoder().encodeToString(contentBytes); } - + public static byte[] base64MimeDecode(String encodedMime) { return Base64.getMimeDecoder().decode(encodedMime); } - + public static String base64Encode(byte[] contentBytes) { return Base64.getEncoder().encodeToString(contentBytes); } - + public static byte[] base64Decode(String encodedMime) { return Base64.getDecoder().decode(encodedMime); } @@ -213,11 +213,11 @@ public static byte[] toByteArray(BufferedImage bi, String format) throws IOExcep return bytes; } } - + public static String toString(ByteBuffer buffer) { return toString(buffer, true, true, 8, " "); } - + public static String toString(ByteBuffer buffer, boolean showStatus, boolean showHeaderfooter, int showNumberOfBytesPerLine, String delimiter) { StringBuilder sb = new StringBuilder(); if (showStatus) { @@ -271,11 +271,11 @@ public static byte[] parseHex(String hexString) { } return data; } - + public static Set findDuplicates(List listContainingDuplicates) { final Set setToReturn = new HashSet<>(); final Set set1 = new HashSet<>(); - + for (T yourInt : listContainingDuplicates) { if (!set1.add(yourInt)) { setToReturn.add(yourInt); @@ -283,7 +283,7 @@ public static Set findDuplicates(List listContainingDup } return setToReturn; } - + public static String protectContentNumber(String plain, String keyword, String delimiter, String replaceWith) { if (StringUtils.isBlank(plain)) { return plain; @@ -292,7 +292,7 @@ public static String protectContentNumber(String plain, String keyword, String d String replacement = keyword + delimiter + replaceWith; return plain.replaceAll(regex, replacement); } - + public static String protectContent(String plain, String keyword, String delimiter, String wrapper, String replaceWith) { if (StringUtils.isBlank(plain)) { return plain; @@ -308,42 +308,42 @@ public static String protectContent(String plain, String keyword, String delimit log.trace(() -> "replace " + plain + "\n\t regex=" + regex + "\n\t with=" + replacement); return plain.replaceAll(regex, replacement); } - + public static String protectJsonString(String json, String key, String replaceWith) { final String regex = "(\"" + key + "\"\\s*:\\s*\")[^\"]*(\")";//("key"\s*:\s*")[^"]*(") return json.replaceAll(regex, "$1" + replaceWith + "$2"); } - + public static String protectJsonString_InString(String json, String key, String replaceWith) { final String regex = "(\"" + key + "\\\\\"\\s*:\\s*\\\\\")[^\"]*(\")"; return json.replaceAll(regex, "$1" + replaceWith + "$2"); } - + public static String protectJsonNumber(String json, String key, String replaceWith) { String regex = "(\"" + key + "\"\\s*:\\s*)(\\d+)"; return json.replaceAll(regex, "$1" + replaceWith); } - + public static String protectJsonNumber_InString(String json, String key, String replaceWith) { String regex = "(\"" + key + "\\\\\"\\s*:\\s*)(\\d+)"; return json.replaceAll(regex, "$1" + replaceWith); } - + public static String protectJsonArray(String json, String key, String replaceWith) { final String regex = "(\"" + key + "\"\\s*:\\s*\\[)[^\\[]*(\\])"; return json.replaceAll(regex, "$1" + replaceWith + "$2"); } - + public static String[] splitByLength(String plain, int chunckSize) { return plain.split("(?<=\\G.{" + chunckSize + "})"); } - + public static T[] arrayCopy(T[] array1, T[] array2) { T[] result = Arrays.copyOf(array1, array1.length + array2.length); System.arraycopy(array2, 0, result, array1.length, array2.length); return result; } - + public static T[] arrayAdd(T[] array1, T newElement) { int size = array1.length; T[] result = Arrays.copyOf(array1, size + 1); From 5456d068e4483dcafab36f6cdfecd4480108471f Mon Sep 17 00:00:00 2001 From: Summer Boot Framework Date: Fri, 17 Nov 2023 17:03:00 -0500 Subject: [PATCH 03/11] refactoring hit-> txId --- pom.xml | 8 +++---- .../jexpress/boot/SummerSingularity.java | 6 +---- .../nio/server/BootHttpExceptionHandler.java | 2 +- .../jexpress/nio/server/NioHttpUtil.java | 2 +- .../server/NioServerHttpRequestHandler.java | 4 ++-- .../nio/server/domain/ServiceContext.java | 24 +++++++++++-------- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/pom.xml b/pom.xml index e174459f..6e738140 100644 --- a/pom.xml +++ b/pom.xml @@ -183,7 +183,7 @@ 2.0.1 - 1.76 + 1.77 0.11.5 @@ -193,7 +193,7 @@ 1.59.0 32.1.3-jre - 3.25.0 + 3.25.1 2.2.18 @@ -207,7 +207,7 @@ 0.10.2 - 2.15.3 + 2.16.0 8.0.1.Final 4.0.2 @@ -222,7 +222,7 @@ 5.0.2 - 2.3.2 + 2.5.0-rc1 2.3.32 diff --git a/src/main/java/org/summerboot/jexpress/boot/SummerSingularity.java b/src/main/java/org/summerboot/jexpress/boot/SummerSingularity.java index 449b5dd9..12166556 100644 --- a/src/main/java/org/summerboot/jexpress/boot/SummerSingularity.java +++ b/src/main/java/org/summerboot/jexpress/boot/SummerSingularity.java @@ -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; @@ -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(); // } diff --git a/src/main/java/org/summerboot/jexpress/nio/server/BootHttpExceptionHandler.java b/src/main/java/org/summerboot/jexpress/nio/server/BootHttpExceptionHandler.java index ccd9860c..29197338 100644 --- a/src/main/java/org/summerboot/jexpress/nio/server/BootHttpExceptionHandler.java +++ b/src/main/java/org/summerboot/jexpress/nio/server/BootHttpExceptionHandler.java @@ -152,7 +152,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); } } diff --git a/src/main/java/org/summerboot/jexpress/nio/server/NioHttpUtil.java b/src/main/java/org/summerboot/jexpress/nio/server/NioHttpUtil.java index 80b6db98..5c7ea902 100644 --- a/src/main/java/org/summerboot/jexpress/nio/server/NioHttpUtil.java +++ b/src/main/java/org/summerboot/jexpress/nio/server/NioHttpUtil.java @@ -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) { diff --git a/src/main/java/org/summerboot/jexpress/nio/server/NioServerHttpRequestHandler.java b/src/main/java/org/summerboot/jexpress/nio/server/NioServerHttpRequestHandler.java index e253b8c5..5561467a 100644 --- a/src/main/java/org/summerboot/jexpress/nio/server/NioServerHttpRequestHandler.java +++ b/src/main/java/org/summerboot/jexpress/nio/server/NioServerHttpRequestHandler.java @@ -111,7 +111,7 @@ public void channelRead0(final ChannelHandlerContext ctx, final FullHttpRequest return; } NioCounter.COUNTER_HIT.incrementAndGet(); - final long hitIndex = NioCounter.COUNTER_BIZ_HIT.incrementAndGet(); + final String hitIndex = BootConstant.APP_ID + "-" + NioCounter.COUNTER_BIZ_HIT.incrementAndGet(); // if (HttpUtil.is100ContinueExpected(req)) { // ctx.write(new DefaultFullHttpResponse(HTTP_1_1, CONTINUE, Unpooled.EMPTY_BUFFER)); // } @@ -291,7 +291,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) diff --git a/src/main/java/org/summerboot/jexpress/nio/server/domain/ServiceContext.java b/src/main/java/org/summerboot/jexpress/nio/server/domain/ServiceContext.java index add63ff8..f6e25dbf 100644 --- a/src/main/java/org/summerboot/jexpress/nio/server/domain/ServiceContext.java +++ b/src/main/java/org/summerboot/jexpress/nio/server/domain/ServiceContext.java @@ -68,7 +68,7 @@ public class ServiceContext { private final String requesURI; private final HttpHeaders requestHeaders; private final String requestBody; - private final long hit; + private final String txId; private final long startTs; private Caller caller; private String callerId; @@ -107,11 +107,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); } - 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) { + return new ServiceContext(null, txId, System.currentTimeMillis(), null, null, null, null); + } + + public static ServiceContext build(ChannelHandlerContext ctx, String txId, long startTs, HttpHeaders requestHeaders, HttpMethod requesMethod, String requesURI, String requestBody) { + return new ServiceContext(ctx, txId, startTs, requestHeaders, requesMethod, requesURI, requestBody); } @Override @@ -120,7 +124,7 @@ 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 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(); @@ -128,7 +132,7 @@ private ServiceContext(ChannelHandlerContext ctx, long hit, long startTs, HttpHe this.localIP = null; this.remoteIP = null; } - this.hit = hit; + this.txId = txId; this.startTs = startTs; this.requestHeaders = requestHeaders; this.requesMethod = requesMethod; @@ -220,8 +224,8 @@ public ServiceContext reset() { } //@JsonInclude(JsonInclude.Include.NON_NULL) - public long hit() { - return hit; + public String txId() { + return txId; } public HttpMethod method() { @@ -661,7 +665,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; @@ -693,7 +697,7 @@ public ServiceContext errors(Collection es) { return this; } if (serviceError == null) { - serviceError = new ServiceError(BootConstant.APP_ID + "-" + hit); + serviceError = new ServiceError(txId); } serviceError.addErrors(es); for (Err e : es) { From e3363094f57020d18d23f40fd724427ae571d704 Mon Sep 17 00:00:00 2001 From: Summer Boot Framework Date: Mon, 20 Nov 2023 15:40:05 -0500 Subject: [PATCH 04/11] refactoring --- pom.xml | 2 +- .../server/NioServerHttpRequestHandler.java | 23 ++++++++++--------- .../nio/server/domain/ServiceContext.java | 20 ++++++++++------ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index 6e738140..0509d5e7 100644 --- a/pom.xml +++ b/pom.xml @@ -195,7 +195,7 @@ 32.1.3-jre 3.25.1 - 2.2.18 + 2.2.19 diff --git a/src/main/java/org/summerboot/jexpress/nio/server/NioServerHttpRequestHandler.java b/src/main/java/org/summerboot/jexpress/nio/server/NioServerHttpRequestHandler.java index 5561467a..8f802660 100644 --- a/src/main/java/org/summerboot/jexpress/nio/server/NioServerHttpRequestHandler.java +++ b/src/main/java/org/summerboot/jexpress/nio/server/NioServerHttpRequestHandler.java @@ -111,7 +111,8 @@ public void channelRead0(final ChannelHandlerContext ctx, final FullHttpRequest return; } NioCounter.COUNTER_HIT.incrementAndGet(); - final String hitIndex = BootConstant.APP_ID + "-" + NioCounter.COUNTER_BIZ_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)); // } @@ -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(); @@ -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 @@ -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); @@ -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) @@ -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) diff --git a/src/main/java/org/summerboot/jexpress/nio/server/domain/ServiceContext.java b/src/main/java/org/summerboot/jexpress/nio/server/domain/ServiceContext.java index f6e25dbf..8e7b8e13 100644 --- a/src/main/java/org/summerboot/jexpress/nio/server/domain/ServiceContext.java +++ b/src/main/java/org/summerboot/jexpress/nio/server/domain/ServiceContext.java @@ -69,6 +69,7 @@ public class ServiceContext { private final HttpHeaders requestHeaders; private final String requestBody; private final String txId; + private final long hit; private final long startTs; private Caller caller; private String callerId; @@ -107,15 +108,15 @@ public class ServiceContext { private boolean logResponseBody = true; public static ServiceContext build(long hit) { - return build(BootConstant.APP_ID + "-" + hit); + return build(BootConstant.APP_ID + "-" + hit, hit); } - public static ServiceContext build(String txId) { - return new ServiceContext(null, txId, System.currentTimeMillis(), null, null, null, null); + 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 startTs, HttpHeaders requestHeaders, HttpMethod requesMethod, String requesURI, String requestBody) { - return new ServiceContext(ctx, txId, startTs, requestHeaders, requesMethod, requesURI, requestBody); + 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 @@ -124,7 +125,7 @@ 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, String txId, 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(); @@ -132,7 +133,8 @@ private ServiceContext(ChannelHandlerContext ctx, String txId, long startTs, Htt this.localIP = null; this.remoteIP = null; } - this.txId = txId; + this.txId = txId; + this.hit = hit; this.startTs = startTs; this.requestHeaders = requestHeaders; this.requesMethod = requesMethod; @@ -227,6 +229,10 @@ public ServiceContext reset() { public String txId() { return txId; } + + public long hit() { + return hit; + } public HttpMethod method() { return requesMethod; From bf90bca925030ec10720be4f69bbd5d6341fce2e Mon Sep 17 00:00:00 2001 From: Summer Boot Framework Date: Thu, 23 Nov 2023 10:07:22 -0500 Subject: [PATCH 05/11] refactoring --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 0509d5e7..d231ce4b 100644 --- a/pom.xml +++ b/pom.xml @@ -178,7 +178,7 @@ - 2.21.1 + 2.22.0 3.4.4 2.0.1 @@ -220,7 +220,7 @@ 5.1.0 - 5.0.2 + 5.1.0 2.5.0-rc1 From 689435345711963a29f30a7462eb73e4e8478fba Mon Sep 17 00:00:00 2001 From: Summer Boot Framework Date: Mon, 27 Nov 2023 12:07:55 -0500 Subject: [PATCH 06/11] dependency update --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d231ce4b..76a6a6e7 100644 --- a/pom.xml +++ b/pom.xml @@ -172,7 +172,7 @@ 11 11 - 3.13.0 + 3.14.0 1.6.0 2.15.0 @@ -216,7 +216,7 @@ 7.0.0 - 6.3.1.Final + 6.4.0.Final 5.1.0 From e32143f7191c72149e3b70b730d433773418a2d0 Mon Sep 17 00:00:00 2001 From: Summer Boot Framework Date: Mon, 4 Dec 2023 10:39:53 -0500 Subject: [PATCH 07/11] release 2.3.12 --- pom.xml | 6 +++--- .../jexpress/nio/server/BootHttpExceptionHandler.java | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 76a6a6e7..b2f496a2 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.summerboot jexpress - 2.3.12-SNAPSHOT + 2.3.12 jar Summer Boot jExpress Summer Boot jExpress focuses on solving non-functional and operational maintainability requirements, some of which Spring Boot has (may) not yet provided @@ -174,7 +174,7 @@ 3.14.0 1.6.0 - 2.15.0 + 2.15.1 @@ -191,7 +191,7 @@ 4.1.101.Final 2.0.62.Final - 1.59.0 + 1.59.1 32.1.3-jre 3.25.1 diff --git a/src/main/java/org/summerboot/jexpress/nio/server/BootHttpExceptionHandler.java b/src/main/java/org/summerboot/jexpress/nio/server/BootHttpExceptionHandler.java index 29197338..e2840f69 100644 --- a/src/main/java/org/summerboot/jexpress/nio/server/BootHttpExceptionHandler.java +++ b/src/main/java/org/summerboot/jexpress/nio/server/BootHttpExceptionHandler.java @@ -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; @@ -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 { @@ -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 { From 2c6a1d4defab58a35d2a40ccbd8091c6ac88c7cb Mon Sep 17 00:00:00 2001 From: Summer Boot Framework Date: Mon, 11 Dec 2023 21:10:51 -0500 Subject: [PATCH 08/11] refactoring --- .gitignore | 4 +- pom.xml | 93 ++++++++++--------- .../summerboot/jexpress/boot/BackOffice.java | 25 +++-- .../jexpress/boot/BootConstant.java | 2 +- .../jexpress/boot/BootGuiceModule.java | 27 +++--- .../jexpress/boot/SummerApplication.java | 90 +++++++++--------- .../jexpress/boot/SummerBigBang.java | 69 ++++++++------ .../jexpress/boot/SummerSingularity.java | 91 ++++++++++++------ .../boot/instrumentation/Timeout.java | 6 +- .../nio/server/domain/ServiceContext.java | 43 ++++----- 10 files changed, 253 insertions(+), 197 deletions(-) diff --git a/.gitignore b/.gitignore index 96b7833d..3156e9c8 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,6 @@ build/ nbbuild/ dist/ nbdist/ -src/test/ \ No newline at end of file +src/test/ +.idea/ +jexpress.iml diff --git a/pom.xml b/pom.xml index b2f496a2..9ea4a10e 100644 --- a/pom.xml +++ b/pom.xml @@ -1,12 +1,15 @@ - + 4.0.0 org.summerboot jexpress - 2.3.12 + 2.3.13-SNAPSHOT jar Summer Boot jExpress - Summer Boot jExpress focuses on solving non-functional and operational maintainability requirements, some of which Spring Boot has (may) not yet provided + Summer Boot jExpress focuses on solving non-functional and operational maintainability requirements, + some of which Spring Boot has (may) not yet provided + https://github.com/SummerBootFramework Summer Boot Org @@ -33,12 +36,16 @@ Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0.txt repo - The jExpress licenses this framework to you under the Apache License, version 2.0 (the "License"); you may not use this framework except in compliance with the License and you have no policy prohibiting employee contributions back to this framework (unless the contributor to this framework is your current or retired employee). + The jExpress licenses this framework to you under the Apache License, version 2.0 (the "License"); + you may not use this framework except in compliance with the License and you have no policy prohibiting + employee contributions back to this framework (unless the contributor to this framework is your current + or retired employee). + https://github.com/SummerBootFramework/jExpress.git - scm:git:git@github.com:SummerBootFramework/jExpress.git + scm:git:git@github.com:SummerBootFramework/jExpress.git scm:git:git@github.com:SummerBootFramework/jExpress.git maven-surefire-plugin @@ -109,7 +116,7 @@ - + maven-deploy-plugin @@ -162,12 +169,12 @@ ossrh Central Repository OSSRH https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ - + - - + + UTF-8 11 11 @@ -191,14 +198,14 @@ 4.1.101.Final 2.0.62.Final - 1.59.1 + 1.60.0 32.1.3-jre 3.25.1 - + 2.2.19 - - + + 2.9.1 @@ -221,7 +228,7 @@ 5.1.0 - + 2.5.0-rc1 @@ -230,15 +237,15 @@ 3.5.2 - + 1.0.10 1.17 8.0.2 5.0.2 - + - 7.8.0 + 7.8.0 8.2.0 @@ -276,7 +283,7 @@ encoder ${owasp.encoder.version} --> - + @@ -304,7 +311,7 @@ com.lmax disruptor ${log4j-disruptor.version} - + org.apache.logging.log4j @@ -369,7 +376,6 @@ --> - @@ -400,8 +406,8 @@ io.netty netty-tcnative-classes ${netty-tcnative.version} - - + + @@ -409,7 +415,7 @@ protobuf-java ${protobuf.version} - + io.grpc @@ -439,14 +445,14 @@ - + io.swagger.core.v3 swagger-annotations ${swagger.core.version} - + @@ -537,7 +543,7 @@ - + com.google.inject guice @@ -581,8 +587,8 @@ ${jedis.version} provided - - + + @@ -610,7 +616,7 @@ freemarker ${freemarker.version} - + @@ -627,8 +633,7 @@ ${zxing.version} provided - - + @@ -652,8 +657,8 @@ org.apache.pdfbox pdfbox ${pdfbox.version} - --> - + --> + @@ -667,19 +672,19 @@ com.openhtmltopdf openhtmltopdf-pdfbox ${openhtml.version} - + - + com.openhtmltopdf openhtmltopdf-java2d ${openhtml.version} - + com.openhtmltopdf openhtmltopdf-rtl-support ${openhtml.version} - + com.openhtmltopdf @@ -691,7 +696,7 @@ slf4j-api - + com.openhtmltopdf @@ -712,7 +717,7 @@ openhtmltopdf-mathml-support ${openhtml.version} - + "; + private final static String INFO = BootConstant.BR + "\t- Ioc.default.binding: "; private final Object caller; private final Class callerClass; private final String callerRootPackageName; @@ -79,9 +81,6 @@ protected boolean isCliUseImplTag(String implTag) { return userSpecifiedImplTags != null && userSpecifiedImplTags.contains(implTag); } - private final static String BIND_TO = " --> "; - private final static String INFO = BootConstant.BR + "\t- Ioc.default.binding: "; - @Override public void configure() { // 1. Instrumentation - JMX @@ -152,8 +151,8 @@ public void configure() { * * @param binder * @param rootPackageNames - * @param annotation the class level annotation to mark this class as a HTTP - * request controller + * @param annotation the class level annotation to mark this class as a HTTP + * request controller */ protected void scanAnnotation_BindInstance(Binder binder, Class annotation, String... rootPackageNames) { MapBinder mapbinder = MapBinder.newMapBinder(binder, String.class, Object.class, annotation); diff --git a/src/main/java/org/summerboot/jexpress/boot/SummerApplication.java b/src/main/java/org/summerboot/jexpress/boot/SummerApplication.java index 7d6ee6ab..c7db997d 100644 --- a/src/main/java/org/summerboot/jexpress/boot/SummerApplication.java +++ b/src/main/java/org/summerboot/jexpress/boot/SummerApplication.java @@ -15,16 +15,12 @@ */ package org.summerboot.jexpress.boot; -import com.google.inject.Module; import com.google.inject.Inject; +import com.google.inject.Module; import io.grpc.BindableService; import io.grpc.ServerBuilder; import io.grpc.ServerInterceptor; import io.grpc.ServerServiceDefinition; -import java.net.InetSocketAddress; -import java.time.OffsetDateTime; -import java.util.ArrayList; -import java.util.List; import org.apache.commons.lang3.exception.ExceptionUtils; import org.quartz.SchedulerException; import org.summerboot.jexpress.boot.config.ConfigChangeListener; @@ -40,12 +36,17 @@ import org.summerboot.jexpress.integration.smtp.SMTPClientConfig; import org.summerboot.jexpress.nio.grpc.GRPCServer; import org.summerboot.jexpress.nio.grpc.GRPCServerConfig; -import org.summerboot.jexpress.nio.server.NioServer; -import org.summerboot.jexpress.util.BeanUtil; import org.summerboot.jexpress.nio.grpc.StatusReporter; import org.summerboot.jexpress.nio.server.NioChannelInitializer; import org.summerboot.jexpress.nio.server.NioConfig; +import org.summerboot.jexpress.nio.server.NioServer; import org.summerboot.jexpress.util.ApplicationUtil; +import org.summerboot.jexpress.util.BeanUtil; + +import java.net.InetSocketAddress; +import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.List; /** * In Code We Trust @@ -54,6 +55,22 @@ */ abstract public class SummerApplication extends SummerBigBang { + @Inject + protected ConfigChangeListener configChangeListener; + @Inject + protected InstrumentationMgr instrumentationMgr; + @Inject + protected HealthInspector healthInspector; + protected NioServer httpServer; + protected List gRPCServerList = new ArrayList(); + @Inject + protected PostOffice postOffice; + private boolean memoLogged = false; + + private SummerApplication(Class callerClass, Module userOverrideModule, String... args) { + super(callerClass, userOverrideModule, args); + } + /** * Might not work on Non HotSpot VM implementations. * @@ -66,7 +83,6 @@ public static T run() { } /** - * * @param callerClass * @param args */ @@ -87,9 +103,7 @@ public static T run(Module userOverrideModule) { int size = mainCommand.length; String[] args = size > 0 ? new String[size - 1] : ApplicationUtil.EMPTY_ARGS; String mainClassName = mainCommand[0]; - for (int i = 1; i < size; i++) { - args[i - 1] = mainCommand[i]; - } + System.arraycopy(mainCommand, 1, args, 0, size - 1); Class callerClass = null; StackTraceElement[] stackTrace = new RuntimeException().getStackTrace(); for (StackTraceElement stackTraceElement : stackTrace) { @@ -114,7 +128,6 @@ public static T run(Module userOverrideModule) { } /** - * * @param * @param args * @return @@ -125,7 +138,6 @@ public static T run(String[] args) { } /** - * * @param * @param args * @param userOverrideModule @@ -150,7 +162,6 @@ public static T run(Module userOverrideModule, Str } /** - * * @param * @param callerClass * @param userOverrideModule @@ -163,7 +174,6 @@ public static T run(Class callerClass, Module user } /** - * * @param * @param callerClass * @param userOverrideModule @@ -178,7 +188,6 @@ public static T run(Class callerClass, Module user } /** - * * @param * @param callerClass * @param userOverrideModule @@ -191,7 +200,6 @@ public static T unittest(Class callerClass, Module } /** - * * @param * @param callerClass * @param userOverrideModule @@ -205,28 +213,6 @@ public static T unittest(Class callerClass, Module return (T) app; } - private SummerApplication(Class callerClass, Module userOverrideModule, String... args) { - super(callerClass, userOverrideModule, args); - } - - @Inject - protected ConfigChangeListener configChangeListener; - - @Inject - protected InstrumentationMgr instrumentationMgr; - - @Inject - protected HealthInspector healthInspector; - - protected NioServer httpServer; - - protected List gRPCServerList = new ArrayList(); - - @Inject - protected PostOffice postOffice; - - private boolean memoLogged = false; - public List getgRPCServers() { return gRPCServerList; } @@ -237,6 +223,7 @@ protected Class getAddtionalI18n() { } protected void traceConfig() { + log.trace(""); if (!memoLogged) { memo.append(BootConstant.BR).append("\t- sys.prop.").append(BootConstant.SYS_PROP_LOGID).append(" = ").append(System.getProperty(BootConstant.SYS_PROP_LOGID)); memo.append(BootConstant.BR).append("\t- sys.prop.").append(BootConstant.SYS_PROP_LOGFILEPATH).append(" = ").append(System.getProperty(BootConstant.SYS_PROP_LOGFILEPATH)); @@ -256,39 +243,43 @@ protected void traceConfig() { /** * run application with ping enabled, URI as webApiContextRoot + * loadBalancerHealthCheckPath - * */ public void start() { + log.trace(""); traceConfig(); if (configChangeListener != null) { ConfigUtil.setConfigChangeListener(configChangeListener); } //1. init email + log.trace("1. init email"); final SMTPClientConfig smtpCfg = SMTPClientConfig.cfg; if (postOffice != null) { HealthMonitor.setPostOffice(postOffice); postOffice.setAppVersion(super.appVersion); //gracefully shutdown Runtime.getRuntime().addShutdownHook(new Thread(() -> { - if (postOffice != null) { - postOffice.sendAlertSync(smtpCfg.getEmailToAppSupport(), "Shutdown at " + OffsetDateTime.now() + " - " + super.appVersion, "EOM", null, false); - } - }, "ShutdownHook.BootApp") + if (postOffice != null) { + postOffice.sendAlertSync(smtpCfg.getEmailToAppSupport(), "Shutdown at " + OffsetDateTime.now() + " - " + super.appVersion, "EOM", null, false); + } + }, "ShutdownHook.BootApp") ); } try { // 2. initialize JMX instrumentation + log.trace("2. initialize JMX instrumentation"); if (instrumentationMgr != null/* && isJMXRequired()*/) { instrumentationMgr.start(BootConstant.VERSION); } - // 3a. runner.run + // 3a. runner.run + log.trace("3a. runner.run"); SummerRunner.RunnerContext context = new SummerRunner.RunnerContext(cli, userSpecifiedConfigDir, guiceInjector, healthInspector, postOffice); for (SummerRunner summerRunner : summerRunners) { summerRunner.run(context); } // 3b. start scheduler + log.trace("3b. start scheduler"); if (schedulerTriggers > 0) { scheduler.start(); StringBuilder sb = new StringBuilder(); @@ -300,6 +291,7 @@ public void start() { long timeoutMs = BackOffice.agent.getProcessTimeoutMilliseconds(); String timeoutDesc = BackOffice.agent.getProcessTimeoutAlertMessage(); // 4. health inspection + log.trace("4. health inspection"); StringBuilder sb = new StringBuilder(); sb.append(BootConstant.BR).append(HealthMonitor.PROMPT); if (healthInspector != null) { @@ -325,9 +317,9 @@ public void start() { } // 5a. start server: gRPC - log.trace("hasGRPCImpl.bs=" + gRPCBindableServiceImplClasses); - log.trace("hasGRPCImpl.ssd=" + gRPCServerServiceDefinitionImplClasses); if (hasGRPCImpl) { + log.trace("5a. start server: gRPC hasGRPCImpl.bs={}", gRPCBindableServiceImplClasses); + log.trace("5a. start server: gRPC hasGRPCImpl.ssd={}", gRPCServerServiceDefinitionImplClasses); ServerInterceptor serverInterceptor = super.guiceInjector.getInstance(ServerInterceptor.class); //2. init gRPC server GRPCServerConfig gRPCCfg = GRPCServerConfig.cfg; @@ -336,6 +328,7 @@ public void start() { for (InetSocketAddress bindingAddress : bindingAddresses) { String host = bindingAddress.getAddress().getHostAddress(); int port = bindingAddress.getPort(); + log.trace("5a. binding gRPC on {}:{}", host, port); try (var a = Timeout.watch("starting gRPCServer at " + host + ":" + port, timeoutMs).withDesc(timeoutDesc)) { GRPCServer gRPCServer = new GRPCServer(host, port, gRPCCfg.getKmf(), gRPCCfg.getTmf(), serverInterceptor, gRPCCfg.getTpe(), nioListener); ServerBuilder serverBuilder = gRPCServer.getServerBuilder(); @@ -359,7 +352,7 @@ public void start() { } // 5b. start server: HTTP - log.trace("hasControllers=" + hasControllers); + log.trace("5b. start server: HTTP hasControllers={}", hasControllers); if (hasControllers && NioConfig.cfg.isAutoStart()) { try (var a = Timeout.watch("starting Web Server", timeoutMs).withDesc(timeoutDesc)) { NioChannelInitializer channelInitializer = super.guiceInjector.getInstance(NioChannelInitializer.class); @@ -391,6 +384,7 @@ public void start() { } public void shutdown() { + log.trace(""); if (gRPCServerList != null && !gRPCServerList.isEmpty()) { for (GRPCServer gRPCServer : gRPCServerList) { gRPCServer.shutdown(); diff --git a/src/main/java/org/summerboot/jexpress/boot/SummerBigBang.java b/src/main/java/org/summerboot/jexpress/boot/SummerBigBang.java index 1f1e40f0..c3f16d9c 100644 --- a/src/main/java/org/summerboot/jexpress/boot/SummerBigBang.java +++ b/src/main/java/org/summerboot/jexpress/boot/SummerBigBang.java @@ -21,33 +21,13 @@ import com.google.inject.Module; import com.google.inject.Stage; import com.google.inject.util.Modules; -import org.summerboot.jexpress.security.JwtUtil; -import org.summerboot.jexpress.security.SecurityUtil; import io.jsonwebtoken.SignatureAlgorithm; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Constructor; -import java.lang.reflect.InaccessibleObjectException; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Locale; -import java.util.Map; -import java.util.Properties; -import java.util.Set; -import java.util.HashSet; -import java.util.List; -import java.util.TreeSet; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.Option; import org.apache.commons.cli.ParseException; import org.quartz.Job; import org.quartz.Scheduler; -import org.quartz.SchedulerException; import org.summerboot.jexpress.boot.annotation.Controller; import org.summerboot.jexpress.boot.annotation.Order; import org.summerboot.jexpress.boot.config.BootConfig; @@ -59,9 +39,29 @@ import org.summerboot.jexpress.nio.server.NioConfig; import org.summerboot.jexpress.nio.server.ws.rs.JaxRsRequestProcessorManager; import org.summerboot.jexpress.security.EncryptorUtil; +import org.summerboot.jexpress.security.JwtUtil; +import org.summerboot.jexpress.security.SecurityUtil; import org.summerboot.jexpress.util.FormatterUtil; import org.summerboot.jexpress.util.ReflectionUtil; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.lang.reflect.InaccessibleObjectException; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.TreeSet; + /** * In Code We Trust * @@ -73,6 +73,8 @@ abstract public class SummerBigBang extends SummerSingularity { protected Injector guiceInjector; protected List summerInitializers = new ArrayList(); protected List summerRunners = new ArrayList(); + protected Scheduler scheduler;//scheduler = new StdSchedulerFactory().getScheduler(); + protected int schedulerTriggers = 0; protected SummerBigBang(Class callerClass, Module userOverrideModule, String... args) { super(callerClass, args); @@ -86,6 +88,7 @@ public Injector getGuiceInjector() { } private void singularity() { + log.trace(""); guiceInjector = null; summerInitializers.clear(); summerRunners.clear(); @@ -93,17 +96,19 @@ private void singularity() { } private T aParallelUniverse(String... args) { + log.trace(""); bigBang_LetThereBeCLI(args); bigBang_AndThereWasCLI(); /* - * 2. load configs: + * 2. load configs: * all configs depend on SummerBigBang.CLI_CONFIG_DOMAIN result * AuthConfig depends on Ioc scan result: JaxRsRequestProcessor scan @DeclareRoles to verify Role-Mapping in configuration file */ loadBootConfigFiles(ConfigUtil.ConfigLoadMode.app_run); for (SummerInitializer summerInitializer : summerInitializers) { + log.trace("initApp: {}", summerInitializer); summerInitializer.initApp(userSpecifiedConfigDir); } @@ -117,6 +122,7 @@ private T aParallelUniverse(String... args) { } protected void bigBang_LetThereBeCLI(String[] args) { + log.trace(""); memo.append(BootConstant.BR).append("\t- CLI.init: args=").append(Arrays.asList(args)); Option arg = Option.builder(BootConstant.CLI_USAGE) .desc("Usage/Help") @@ -226,6 +232,7 @@ protected void bigBang_LetThereBeCLI(String[] args) { } protected List scanImplementation_SummerInitializer() { + log.trace(""); List summerCLIs = new ArrayList(); Set> summerCLI_ImplClasses = ReflectionUtil.getAllImplementationsByInterface(SummerInitializer.class, callerRootPackageNames); //prepare ordering @@ -235,7 +242,7 @@ protected List scanImplementation_SummerInitializer() { for (Class c : summerCLI_ImplClasses) { //get order int order = 0; - Order o = (Order) c.getAnnotation(Order.class); + Order o = c.getAnnotation(Order.class); if (o != null) { order = o.value(); } @@ -245,7 +252,8 @@ protected List scanImplementation_SummerInitializer() { Constructor cc = c.getConstructor(); cc.setAccessible(true); instance = cc.newInstance(); - } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { + } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | + IllegalArgumentException | InvocationTargetException ex) { throw new InaccessibleObjectException("Failed to call default constructor of " + c.getName()); } @@ -265,6 +273,7 @@ protected List scanImplementation_SummerInitializer() { } protected boolean runCLI_Utils() { + log.trace(""); boolean continueCLI = true; //usage if (cli.hasOption(BootConstant.CLI_USAGE)) { @@ -300,6 +309,7 @@ protected boolean runCLI_Utils() { } protected void bigBang_AndThereWasCLI() { + log.trace(""); if (!runCLI_Utils()) { System.exit(0); } @@ -309,7 +319,7 @@ protected void bigBang_AndThereWasCLI() { if (cli.hasOption(BootConstant.CLI_ADMIN_PWD_FILE)) { String adminPwdFile = cli.getOptionValue(BootConstant.CLI_ADMIN_PWD_FILE); Properties props = new Properties(); - try (InputStream is = new FileInputStream(adminPwdFile);) { + try (InputStream is = new FileInputStream(adminPwdFile)) { props.load(is); } catch (Throwable ex) { throw new RuntimeException("failed to load " + adminPwdFile, ex); @@ -431,6 +441,7 @@ protected void bigBang_AndThereWasCLI() { * @return */ protected int loadBootConfigFiles(ConfigUtil.ConfigLoadMode mode) { + log.trace(""); Map configs = new LinkedHashMap<>(); int updated = 0; @@ -491,6 +502,7 @@ protected boolean isUserSpecifiedImplTags(String mockItemName) { * @param userSpecifiedImplTags */ protected void genesis(Class primaryClass, Set userSpecifiedImplTags) { + log.trace(""); BootGuiceModule defaultModule = new BootGuiceModule(this, primaryClass, userSpecifiedImplTags, memo); ScanedGuiceModule scanedModule = new ScanedGuiceModule(scanedServiceBindingMap, userSpecifiedImplTags, channelHandlerNames, memo); Module bootModule = Modules.override(defaultModule).with(scanedModule); @@ -528,17 +540,18 @@ protected void genesis(Class primaryClass, Set userSpecifiedImplTags) { * Guice.createInjector(module) --> BootGuiceModule.configure() --> BootGuiceModule.scanAnnotation_BindInstance(...) * to load all classes annotated with @Controller * - * * @param controllers */ @Inject protected void onGuiceInjectorCreated_ControllersInjected(@Controller Map controllers) { + log.trace(""); //1. scan and register controllers String pingURL = JaxRsRequestProcessorManager.registerControllers(controllers, memo); BackOffice.agent.setPingURL(pingURL); } protected void scanImplementation_SummerRunner(Injector injector) { + log.trace(""); Set> summerRunner_ImplClasses = ReflectionUtil.getAllImplementationsByInterface(SummerRunner.class, callerRootPackageNames); //prepare ordering Set orderSet = new TreeSet(); @@ -547,7 +560,7 @@ protected void scanImplementation_SummerRunner(Injector injector) { for (Class c : summerRunner_ImplClasses) { //get order int order = 0; - Order o = (Order) c.getAnnotation(Order.class); + Order o = c.getAnnotation(Order.class); if (o != null) { order = o.value(); } @@ -568,10 +581,8 @@ protected void scanImplementation_SummerRunner(Injector injector) { } } - protected Scheduler scheduler;//scheduler = new StdSchedulerFactory().getScheduler(); - protected int schedulerTriggers = 0; - protected int scanAnnotation_Scheduled(Injector injector, String... rootPackageNames) { + log.trace(""); int triggers = 0; Set> classes = ReflectionUtil.getAllImplementationsByInterface(Job.class, rootPackageNames); diff --git a/src/main/java/org/summerboot/jexpress/boot/SummerSingularity.java b/src/main/java/org/summerboot/jexpress/boot/SummerSingularity.java index 12166556..68ecf734 100644 --- a/src/main/java/org/summerboot/jexpress/boot/SummerSingularity.java +++ b/src/main/java/org/summerboot/jexpress/boot/SummerSingularity.java @@ -20,6 +20,31 @@ import io.netty.channel.ChannelHandler; import jakarta.annotation.security.DeclareRoles; import jakarta.annotation.security.RolesAllowed; +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.HelpFormatter; +import org.apache.commons.cli.Options; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.summerboot.jexpress.boot.annotation.Controller; +import org.summerboot.jexpress.boot.annotation.GrpcService; +import org.summerboot.jexpress.boot.annotation.Service; +import org.summerboot.jexpress.boot.annotation.Service.ChannelHandlerType; +import org.summerboot.jexpress.boot.annotation.Unique; +import org.summerboot.jexpress.boot.annotation.Version; +import org.summerboot.jexpress.boot.config.ConfigUtil; +import org.summerboot.jexpress.boot.config.JExpressConfig; +import org.summerboot.jexpress.boot.config.annotation.ImportResource; +import org.summerboot.jexpress.i18n.I18n; +import org.summerboot.jexpress.integration.smtp.SMTPClientConfig; +import org.summerboot.jexpress.nio.grpc.GRPCServerConfig; +import org.summerboot.jexpress.nio.server.NioConfig; +import org.summerboot.jexpress.security.auth.AuthConfig; +import org.summerboot.jexpress.util.ApplicationUtil; +import org.summerboot.jexpress.util.BeanUtil; +import org.summerboot.jexpress.util.FormatterUtil; +import org.summerboot.jexpress.util.ReflectionUtil; + import java.io.File; import java.io.FileFilter; import java.io.IOException; @@ -39,30 +64,6 @@ import java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Options; -import org.apache.commons.lang3.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.summerboot.jexpress.boot.annotation.Controller; -import org.summerboot.jexpress.boot.annotation.Unique; -import org.summerboot.jexpress.boot.annotation.Version; -import org.summerboot.jexpress.boot.config.JExpressConfig; -import org.summerboot.jexpress.boot.config.annotation.ImportResource; -import org.summerboot.jexpress.security.auth.AuthConfig; -import org.summerboot.jexpress.util.ApplicationUtil; -import org.summerboot.jexpress.util.BeanUtil; -import org.summerboot.jexpress.util.ReflectionUtil; -import org.summerboot.jexpress.boot.annotation.Service; -import org.summerboot.jexpress.boot.annotation.GrpcService; -import org.summerboot.jexpress.boot.annotation.Service.ChannelHandlerType; -import org.summerboot.jexpress.boot.config.ConfigUtil; -import org.summerboot.jexpress.i18n.I18n; -import org.summerboot.jexpress.integration.smtp.SMTPClientConfig; -import org.summerboot.jexpress.nio.grpc.GRPCServerConfig; -import org.summerboot.jexpress.nio.server.NioConfig; -import org.summerboot.jexpress.util.FormatterUtil; /** * In Code We Trust @@ -145,7 +146,7 @@ private static String jExpressInit() { protected final Map> channelHandlerNames = new HashMap(); protected SummerSingularity(Class callerClass, String... args) { - System.out.println("SummerApplication loading from " + HOST); + System.out.println("jExpress loading from " + HOST); System.setProperty(BootConstant.SYS_PROP_SERVER_NAME, HOST);// used by log4j2.xml primaryClass = callerClass == null ? this.getClass() @@ -155,6 +156,9 @@ protected SummerSingularity(Class callerClass, String... args) { } private void singularity() { + if (BackOffice.agent.isTraceWithSystemOut()) { + System.out.println("jExpress init.0"); + } memo.setLength(0); userSpecifiedConfigDir = null; pluginDir = null; @@ -188,6 +192,9 @@ private void singularity() { } private T bigBang(String[] args) { + if (BackOffice.agent.isTraceWithSystemOut()) { + System.out.println("jExpress init.1"); + } memo.append(BootConstant.BR).append("\t- deployee callerClass=").append(primaryClass.getName()); Set packageSet = new HashSet(); Set configuredPackageSet = BackOffice.agent.getRootPackageNames(); @@ -198,12 +205,18 @@ private T bigBang(String[] args) { packageSet.add(rootPackageName); BackOffice.agent.setRootPackageNames(packageSet); callerRootPackageNames = packageSet.toArray(String[]::new); - memo.append(BootConstant.BR).append("\t- callerRootPackageName=").append(packageSet); + + if (BackOffice.agent.isTraceWithSystemOut()) { + System.out.println("jExpress init.2"); + } StringBuilder sb = new StringBuilder(); jmxRequired = ApplicationUtil.scanJVM_StartCommand(sb); jvmStartCommand = sb.toString(); + if (BackOffice.agent.isTraceWithSystemOut()) { + System.out.println("jExpress init.3"); + } scanAnnotation_Version(primaryClass); System.setProperty(BootConstant.SYS_PROP_LOGFILENAME, logFileName);// used by log4j2.xml as log file name System.setProperty(BootConstant.SYS_PROP_APP_PACKAGE_NAME, rootPackageName);// used by log4j2.xml @@ -235,6 +248,9 @@ private T bigBang(String[] args) { } protected void scanAnnotation_Version(Class callerClass) { + if (BackOffice.agent.isTraceWithSystemOut()) { + System.out.println("jExpress scanning version"); + } Version version = (Version) callerClass.getAnnotation(Version.class); if (version != null) { String logManager = version.LogManager(); @@ -262,6 +278,9 @@ protected void scanAnnotation_Version(Class callerClass) { } protected void scanArgsToInitializeLogging(String[] args) { + if (BackOffice.agent.isTraceWithSystemOut()) { + System.out.println("jExpress initLogger.1"); + } /* * [Config File] Location - determine the configuration path: userSpecifiedConfigDir */ @@ -283,6 +302,9 @@ protected void scanArgsToInitializeLogging(String[] args) { } } + if (BackOffice.agent.isTraceWithSystemOut()) { + System.out.println("jExpress initLogger.2"); + } if (userSpecifiedConfigDir == null) { userSpecifiedConfigDir = DEFAULT_CFG_DIR; } @@ -290,6 +312,9 @@ protected void scanArgsToInitializeLogging(String[] args) { userSpecifiedConfigDir.mkdirs(); } + if (BackOffice.agent.isTraceWithSystemOut()) { + System.out.println("jExpress initLogger.3"); + } // if (userSpecifiedConfigDir.getAbsolutePath().equals(CURRENT_DIR.getAbsolutePath())) { // //set log folder inside user specified config folder // System.setProperty(SYS_PROP_LOGFILEPATH, userSpecifiedConfigDir.getAbsolutePath());//used by log4j2.xml @@ -309,6 +334,9 @@ protected void scanArgsToInitializeLogging(String[] args) { /* * [Config File] Log4J - init */ + if (BackOffice.agent.isTraceWithSystemOut()) { + System.out.println("jExpress initLogger.4"); + } String location = userSpecifiedConfigDir.getAbsolutePath(); ClassLoader classLoader = this.getClass().getClassLoader(); Path logFilePath = ApplicationUtil.createIfNotExist(location, classLoader, "log4j2.xml.temp", "log4j2.xml"); @@ -321,6 +349,7 @@ protected void scanArgsToInitializeLogging(String[] args) { } protected void scanPluginJars(File pluginDir, boolean failOnUndefinedClasses) throws IOException { + log.trace("{}, {}", pluginDir, failOnUndefinedClasses); pluginDir.mkdirs(); if (!pluginDir.canRead() || !pluginDir.isDirectory()) { memo.append(BootConstant.BR).append("\t- loadPluginJars: invalid dir ").append(pluginDir); @@ -344,13 +373,13 @@ protected void scanPluginJars(File pluginDir, boolean failOnUndefinedClasses) th } /** - * * @param rootPackageNames * @param sb * @param displayByTags * @return error message */ protected String scanAnnotation_Unique(String[] rootPackageNames, StringBuilder sb, String... displayByTags) { + log.trace(""); StringBuilder errors = new StringBuilder(); boolean error = false; Set> classes = ReflectionUtil.getAllImplementationsByAnnotation(Unique.class, false, rootPackageNames); @@ -393,6 +422,7 @@ protected String scanAnnotation_Unique(String[] rootPackageNames, StringBuilder } protected void scanAnnotation_JExpressConfigImportResource(String... rootPackageNames) { + log.trace(""); Set pakcages = Set.copyOf(List.of(rootPackageNames)); //Set> classesAll = new HashSet();//to remove duplicated //for (String rootPackageName : pakcages) { @@ -440,6 +470,7 @@ protected void scanAnnotation_JExpressConfigImportResource(String... rootPackage } protected void scanImplementation_gRPC(String... pakcages) { + log.trace(""); //gRPCBindableServiceImplClasses.addAll(ReflectionUtil.getAllImplementationsByInterface(BindableService.class, callerRootPackageNames)); //for (String rootPackageName : pakcages) { Set> gRPCServerClasses = ReflectionUtil.getAllImplementationsByAnnotation(GrpcService.class, false, pakcages); @@ -455,6 +486,7 @@ protected void scanImplementation_gRPC(String... pakcages) { } protected void scanAnnotation_Controller(String... rootPackageNames) { + log.trace(""); //Set> classesAll = new HashSet();//to remove duplicated //for (String rootPackageName : rootPackageNames) { Set> classes = ReflectionUtil.getAllImplementationsByAnnotation(Controller.class, false, rootPackageNames); @@ -479,6 +511,7 @@ protected void scanAnnotation_Controller(String... rootPackageNames) { } protected List scanAnnotation_Service(String... rootPackageNames) { + log.trace(""); //Set> classesAll = new HashSet();//to remove duplicated //for (String rootPackageName : rootPackageNames) { Set> classes = ReflectionUtil.getAllImplementationsByAnnotation(Service.class, false, rootPackageNames); @@ -489,6 +522,7 @@ protected List scanAnnotation_Service(String... rootPackageNames) { } protected List scanAnnotation_Service(Set> classesAll) { + log.trace(""); List tags = new ArrayList(); StringBuilder sb = new StringBuilder(); for (Class serviceImplClass : classesAll) { @@ -551,6 +585,7 @@ protected List scanAnnotation_Service(Set> classesAll) { } protected void scanAnnotation_Service_Add2BindingMap(Class bindingClass, String uniqueKey, ServiceMetadata service, StringBuilder sb) { + log.trace(""); memo.append(BootConstant.BR).append("\t- scan.taggedservice.add to guiceModule.bind(").append(bindingClass.getName()).append(").to(").append(service).append("), uniqueKey=").append(uniqueKey); Map> taggeServicedMap = scanedServiceBindingMap.get(bindingClass); if (taggeServicedMap == null) { @@ -572,6 +607,7 @@ protected void scanAnnotation_Service_Add2BindingMap(Class bindingClass, String } protected void scanAnnotation_Service_ValidateBindingMap(StringBuilder sb) { + log.trace(""); for (Class keyBindingClass : scanedServiceBindingMap.keySet()) { Map> taggeServicedMap = scanedServiceBindingMap.get(keyBindingClass); for (String keyImplTag : taggeServicedMap.keySet()) { @@ -585,6 +621,7 @@ protected void scanAnnotation_Service_ValidateBindingMap(StringBuilder sb) { } protected void scanAnnotation_DeclareRoles(String... rootPackageNames) { + log.trace(""); Set declareRoles = new TreeSet(); //Set> classesAll = new HashSet();//to remove duplicated //for (String rootPackageName : rootPackageNames) { diff --git a/src/main/java/org/summerboot/jexpress/boot/instrumentation/Timeout.java b/src/main/java/org/summerboot/jexpress/boot/instrumentation/Timeout.java index 579586bc..cd39649e 100644 --- a/src/main/java/org/summerboot/jexpress/boot/instrumentation/Timeout.java +++ b/src/main/java/org/summerboot/jexpress/boot/instrumentation/Timeout.java @@ -15,15 +15,15 @@ */ package org.summerboot.jexpress.boot.instrumentation; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.locks.ReentrantLock; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.summerboot.jexpress.boot.BackOffice; import org.summerboot.jexpress.boot.BootConstant; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReentrantLock; + /** - * * @author Changski Tie Zheng Zhang 张铁铮, 魏泽北, 杜旺财, 杜富贵 */ public class Timeout implements AutoCloseable { diff --git a/src/main/java/org/summerboot/jexpress/nio/server/domain/ServiceContext.java b/src/main/java/org/summerboot/jexpress/nio/server/domain/ServiceContext.java index 8e7b8e13..f27e83e2 100644 --- a/src/main/java/org/summerboot/jexpress/nio/server/domain/ServiceContext.java +++ b/src/main/java/org/summerboot/jexpress/nio/server/domain/ServiceContext.java @@ -15,8 +15,6 @@ */ package org.summerboot.jexpress.nio.server.domain; -import org.summerboot.jexpress.nio.server.NioHttpUtil; -import org.summerboot.jexpress.security.auth.Caller; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.core.JsonProcessingException; import io.netty.channel.ChannelHandlerContext; @@ -25,6 +23,19 @@ import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpResponseStatus; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.apache.logging.log4j.Level; +import org.summerboot.jexpress.boot.BackOffice; +import org.summerboot.jexpress.boot.BootConstant; +import org.summerboot.jexpress.boot.BootErrorCode; +import org.summerboot.jexpress.boot.BootPOI; +import org.summerboot.jexpress.nio.server.NioConfig; +import org.summerboot.jexpress.nio.server.NioHttpUtil; +import org.summerboot.jexpress.nio.server.ResponseEncoder; +import org.summerboot.jexpress.security.auth.Caller; +import org.summerboot.jexpress.util.ApplicationUtil; + import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -40,20 +51,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.lang3.StringUtils; -import org.apache.logging.log4j.Level; -import org.summerboot.jexpress.boot.BootErrorCode; -import org.summerboot.jexpress.boot.BootPOI; -import org.summerboot.jexpress.nio.server.NioConfig; import java.util.Set; -import org.apache.commons.lang3.exception.ExceptionUtils; -import org.summerboot.jexpress.boot.BackOffice; -import org.summerboot.jexpress.boot.BootConstant; -import org.summerboot.jexpress.nio.server.ResponseEncoder; -import org.summerboot.jexpress.util.ApplicationUtil; /** - * * @author Changski Tie Zheng Zhang 张铁铮, 魏泽北, 杜旺财, 杜富贵 */ @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) @@ -133,7 +133,7 @@ private ServiceContext(ChannelHandlerContext ctx, String txId, long hit, long st this.localIP = null; this.remoteIP = null; } - this.txId = txId; + this.txId = txId; this.hit = hit; this.startTs = startTs; this.requestHeaders = requestHeaders; @@ -154,6 +154,7 @@ private ServiceContext(ChannelHandlerContext ctx, String txId, long hit, long st // attributes.clear(); // } // } + /** * get attribute value by kay * @@ -229,7 +230,7 @@ public ServiceContext reset() { public String txId() { return txId; } - + public long hit() { return hit; } @@ -283,7 +284,7 @@ public ServiceContext responseHeaders(HttpHeaders headers) { return this; } -// public Response addHeader(String key, Object value) { + // public Response addHeader(String key, Object value) { // if (StringUtils.isBlank(key) || value == null) { // return this; // } @@ -308,7 +309,7 @@ public ServiceContext responseHeader(String key, Object value) { return this; } -// public Response addHeaders(String key, Iterable values) { + // public Response addHeaders(String key, Iterable values) { // if (StringUtils.isBlank(key) || values == null) { // return this; // } @@ -379,7 +380,7 @@ public ServiceContext clientAcceptContentType(String clientAcceptContentType) { return this; } -// public ServiceContext contentTypeTry(String contentType) { + // public ServiceContext contentTypeTry(String contentType) { // if (contentType != null) { // this.contentType = contentType; // } @@ -511,7 +512,7 @@ public boolean precheckFile(File file, boolean isDownloadMode) { return true; } -// private static final List ERRPR_PAGES = new ArrayList(); + // private static final List ERRPR_PAGES = new ArrayList(); // // static { // ERRPR_PAGES.add(HttpResponseStatus.UNAUTHORIZED.code()); @@ -624,7 +625,7 @@ public ServiceContext callerId(String callerId) { return this; } -// public int errorCode() { + // public int errorCode() { // return errorCode; // } // @@ -862,7 +863,7 @@ public ServiceContext reportError(StringBuilder sb) throws JsonProcessingExcepti if (errors != null && !errors.isEmpty()) { sb.append("\n\n\tErrors: "); for (var error : errors) { - sb.append("\n\t ").append(error.toStringEx(false)); + sb.append("\n\t ").append(error.toStringEx(true)); } } From 36c9e728968fed2fc039d08a443da7f8d0721411 Mon Sep 17 00:00:00 2001 From: Summer Boot Framework Date: Thu, 14 Dec 2023 17:27:49 -0500 Subject: [PATCH 09/11] auto generate tempuploaddir --- pom.xml | 2 +- .../nio/server/BootHttpFileUploadHandler.java | 36 +++++++++++-------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index 9ea4a10e..e92ce458 100644 --- a/pom.xml +++ b/pom.xml @@ -195,7 +195,7 @@ 0.11.5 - 4.1.101.Final + 4.1.102.Final 2.0.62.Final 1.60.0 diff --git a/src/main/java/org/summerboot/jexpress/nio/server/BootHttpFileUploadHandler.java b/src/main/java/org/summerboot/jexpress/nio/server/BootHttpFileUploadHandler.java index 351fe0a0..665d5809 100644 --- a/src/main/java/org/summerboot/jexpress/nio/server/BootHttpFileUploadHandler.java +++ b/src/main/java/org/summerboot/jexpress/nio/server/BootHttpFileUploadHandler.java @@ -15,12 +15,9 @@ */ package org.summerboot.jexpress.nio.server; -import org.summerboot.jexpress.nio.server.domain.ServiceError; -import org.summerboot.jexpress.nio.server.domain.ServiceContext; -import org.summerboot.jexpress.nio.server.multipart.MultipartUtil; -import org.summerboot.jexpress.security.auth.Caller; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.handler.codec.DecoderException; import io.netty.handler.codec.http.HttpContent; import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpHeaders; @@ -41,18 +38,24 @@ import io.netty.handler.codec.http.multipart.InterfaceHttpData; import io.netty.handler.codec.http.multipart.InterfaceHttpData.HttpDataType; import io.netty.util.ReferenceCountUtil; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.summerboot.jexpress.boot.BootErrorCode; +import org.summerboot.jexpress.nio.server.domain.ServiceContext; +import org.summerboot.jexpress.nio.server.domain.ServiceError; +import org.summerboot.jexpress.nio.server.multipart.MultipartUtil; +import org.summerboot.jexpress.security.auth.Caller; + import java.io.File; import java.io.IOException; +import java.io.UncheckedIOException; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.summerboot.jexpress.boot.BootErrorCode; -import io.netty.handler.codec.DecoderException; /** - * * @author Changski Tie Zheng Zhang 张铁铮, 魏泽北, 杜旺财, 杜富贵 */ //NOT @ChannelHandler.Sharable due to BootHttpFileUploadHandler is stateful @@ -69,10 +72,16 @@ public abstract class BootHttpFileUploadHandler extends SimpleChannelInboundHand protected static final NioConfig uploadCfg = NioConfig.cfg; static { - DiskFileUpload.deleteOnExitTemporaryFile = true; // should delete file on exit (in normal exit) - DiskFileUpload.baseDirectory = uploadCfg.getTempUoloadDir(); // system temp directory - DiskAttribute.deleteOnExitTemporaryFile = true; // should delete file on exit (in normal exit) - DiskAttribute.baseDirectory = uploadCfg.getTempUoloadDir(); // system temp directory + String tempUoloadDir = uploadCfg.getTempUoloadDir(); + try { + Files.createDirectories(Path.of(tempUoloadDir)); + DiskFileUpload.deleteOnExitTemporaryFile = true; // should delete file on exit (in normal exit) + DiskFileUpload.baseDirectory = tempUoloadDir; // system temp directory + DiskAttribute.deleteOnExitTemporaryFile = true; // should delete file on exit (in normal exit) + DiskAttribute.baseDirectory = tempUoloadDir; // system temp directory + } catch (IOException e) { + throw new UncheckedIOException(e); + } } public BootHttpFileUploadHandler() { @@ -250,7 +259,6 @@ private void onLastChunk(ChannelHandlerContext ctx) throws IOException { } /** - * * @param ctx * @param req * @return quota (in bytes) of uploaded file size From 49253cef284ca2e3651ef372c9212fd962d8be9b Mon Sep 17 00:00:00 2001 From: Summer Boot Framework Date: Sun, 24 Dec 2023 10:43:59 -0500 Subject: [PATCH 10/11] rewording --- pom.xml | 10 +++++----- .../jexpress/boot/instrumentation/Timeout.java | 7 +++---- .../org/summerboot/jexpress/nio/server/domain/Err.java | 7 +++---- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index e92ce458..b51a7354 100644 --- a/pom.xml +++ b/pom.xml @@ -195,11 +195,11 @@ 0.11.5 - 4.1.102.Final + 4.1.104.Final 2.0.62.Final - 1.60.0 - 32.1.3-jre + 1.60.1 + 33.0.0-jre 3.25.1 2.2.19 @@ -223,7 +223,7 @@ 7.0.0 - 6.4.0.Final + 6.4.1.Final 5.1.0 @@ -423,7 +423,7 @@ ${grpc.version} - + com.google.guava guava diff --git a/src/main/java/org/summerboot/jexpress/boot/instrumentation/Timeout.java b/src/main/java/org/summerboot/jexpress/boot/instrumentation/Timeout.java index cd39649e..297df62f 100644 --- a/src/main/java/org/summerboot/jexpress/boot/instrumentation/Timeout.java +++ b/src/main/java/org/summerboot/jexpress/boot/instrumentation/Timeout.java @@ -63,16 +63,16 @@ private void startTheTimer() { lock.lock(); Runnable runnableTask = () -> { try { - log.info("Timeout watching: {} - {}", processName, System.currentTimeMillis()); + log.info("Task started: {} - {}", processName, System.currentTimeMillis()); if (lock.tryLock(timeoutMilliseconds, TimeUnit.MILLISECONDS)) { lock.unlock(); - log.info("Timeout ontime: {} - {}", processName, System.currentTimeMillis()); + log.info("Task finished: {} - {}", processName, System.currentTimeMillis()); return; } String desc = message == null ? "" : BootConstant.BR + "\t" + message; - log.warn(BootConstant.BR + BootConstant.BR + "\t*** Warning: " + processName + " has timed out for " + timeoutMilliseconds + " ms ***" + BootConstant.BR + desc + BootConstant.BR + BootConstant.BR); + log.warn(BootConstant.BR + BootConstant.BR + "\t*** Warning: " + processName + " has timed out over " + timeoutMilliseconds + " ms ***" + BootConstant.BR + desc + BootConstant.BR + BootConstant.BR); if (task != null) { BackOffice.execute(task); } @@ -87,5 +87,4 @@ private void startTheTimer() { public void close() throws Exception { lock.unlock(); } - } diff --git a/src/main/java/org/summerboot/jexpress/nio/server/domain/Err.java b/src/main/java/org/summerboot/jexpress/nio/server/domain/Err.java index 2709ed15..6c21b7c5 100644 --- a/src/main/java/org/summerboot/jexpress/nio/server/domain/Err.java +++ b/src/main/java/org/summerboot/jexpress/nio/server/domain/Err.java @@ -15,17 +15,16 @@ */ package org.summerboot.jexpress.nio.server.domain; -import org.summerboot.jexpress.util.BeanUtil; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import org.apache.commons.lang3.exception.ExceptionUtils; +import org.summerboot.jexpress.util.BeanUtil; /** - * - * @author Changski Tie Zheng Zhang 张铁铮, 魏泽北, 杜旺财, 杜富贵 * @param + * @author Changski Tie Zheng Zhang 张铁铮, 魏泽北, 杜旺财, 杜富贵 */ public class Err { @@ -70,7 +69,7 @@ public Err(String errorCode, String errorTag, String errorDesc, Throwable ex, T // : rootCause.toString(); } -// void showRootCause(boolean isEnable) { + // void showRootCause(boolean isEnable) { // this.cause = isEnable ? this._cause : null; // } public String toJson() { From c335603ba5b3f8a26f0f2b682e0f48b7389c9268 Mon Sep 17 00:00:00 2001 From: Summer Boot Framework Date: Sun, 24 Dec 2023 10:45:14 -0500 Subject: [PATCH 11/11] release 2.3.13 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b51a7354..849be0ec 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.summerboot jexpress - 2.3.13-SNAPSHOT + 2.3.13 jar Summer Boot jExpress Summer Boot jExpress focuses on solving non-functional and operational maintainability requirements,