Skip to content

Feature2.5.0 #291

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.summerboot</groupId>
<artifactId>jexpress</artifactId>
<version>2.4.18</version>
<version>2.5.0</version>
<packaging>jar</packaging>
<name>Summer Boot jExpress</name>
<description>Summer Boot jExpress focuses on solving non-functional and operational maintainability requirements,
Expand Down Expand Up @@ -60,7 +60,7 @@
<id>release</id>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.release>21</maven.compiler.release>
<maven-scm.version>2.1.0</maven-scm.version>
<maven-source.version>3.3.1</maven-source.version>
<maven-javadoc.version>3.11.2</maven-javadoc.version>
Expand Down Expand Up @@ -181,7 +181,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- <maven.compiler.source>21</maven.compiler.source>-->
<!-- <maven.compiler.target>21</maven.compiler.target>-->
<maven.compiler.release>17</maven.compiler.release>
<maven.compiler.release>21</maven.compiler.release>
<maven-clean.version>3.4.0</maven-clean.version>
<maven-compiler.version>3.13.0</maven-compiler.version>
<maven-dependency.version>3.8.1</maven-dependency.version>
Expand All @@ -201,19 +201,19 @@
<!-- Mail -->
<jakarta-mail.version>2.0.1</jakarta-mail.version>
<!-- Security -->
<bouncycastle.version>1.79</bouncycastle.version>
<bouncycastle.version>1.80</bouncycastle.version>
<!-- JWT -->
<jwt.version>0.12.6</jwt.version>

<!-- NIO Netty -->
<netty.version>4.1.116.Final</netty.version>
<netty.version>4.1.117.Final</netty.version>
<netty-tcnative.version>2.0.69.Final</netty-tcnative.version>
<!-- gRPC and protobuf -->
<grpc.version>1.69.0</grpc.version>
<grpc.version>1.70.0</grpc.version>
<guava.version>33.4.0-jre</guava.version>
<protobuf.version>4.29.2</protobuf.version>
<protobuf.version>4.29.3</protobuf.version>
<!-- Web JAX-RS -->
<swagger.core.version>2.2.27</swagger.core.version>
<swagger.core.version>2.2.28</swagger.core.version>
<!--<elastic-apm.version>1.36.0</elastic-apm.version>-->


Expand All @@ -235,7 +235,7 @@
<guice.version>7.0.0</guice.version>

<!-- JPA -->
<hibernate.version>6.6.4.Final</hibernate.version>
<hibernate.version>6.6.5.Final</hibernate.version>
<hikari-cp.version>6.2.1</hikari-cp.version>

<!-- Cache -->
Expand All @@ -259,7 +259,7 @@

<!-- Testing -->
<testng.version>7.10.2</testng.version>
<jdbc.version>9.1.0</jdbc.version>
<jdbc.version>9.2.0</jdbc.version>
</properties>

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

//version
String VERSION = "jExpress 2.4.18";
String VERSION = "jExpress 2.5.0";
String JEXPRESS_PACKAGE_NAME = "org.summerboot.jexpress";

String DEFAULT_ADMIN_MM = "changeit";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,21 @@ public static ThreadPoolExecutor buildThreadPoolExecutor(ThreadPoolExecutor tpe,
boolean prestartAllCoreThreads, boolean allowCoreThreadTimeOut, boolean isSingleton) {
boolean useVirtualThread = false;
switch (threadingMode) {
case Mixed, VirtualThread -> {// manual config is required when it is mixed
case VirtualThread -> { // Java 21+ only
useVirtualThread = true;
if (core < 1) {
core = Integer.MAX_VALUE;
allowCoreThreadTimeOut = true;
}
if (max < 1) {
max = Integer.MAX_VALUE;
}
if (max < core) {
//helper.addError("BizExecutor.MaxSize should not less than BizExecutor.CoreSize");
max = core;
}
}
case Mixed/*, VirtualThread*/ -> {// manual config is required when it is mixed
if (core < 1) {
core = CPU_CORE * 2 + 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public static ThreadFactory build(String tpeName, boolean useVirtualThread) {
String namePrefix = tpeName + "-"
+ poolNumber.getAndIncrement()
+ (useVirtualThread ? "-vt-" : "-pt-");
return new NamedDefaultThreadFactory(namePrefix);
return useVirtualThread
? Thread.ofVirtual().name(namePrefix, 0).factory() // Java 21+ only
: new NamedDefaultThreadFactory(namePrefix);
}
}
48 changes: 22 additions & 26 deletions src/main/java/org/summerboot/jexpress/nio/server/NioHttpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ private static void sendRedirect(ChannelHandlerContext ctx, String newUri, HttpR
ctx.writeAndFlush(resp).addListener(ChannelFutureListener.CLOSE);
}


public static long sendResponse(ChannelHandlerContext ctx, boolean isKeepAlive, final ServiceContext serviceContext, final ErrorAuditor errorAuditor, final ProcessorSettings processorSettings) {
String headerKey_reference;
String headerKey_serverTimestamp;
Expand All @@ -117,44 +118,40 @@ public static long sendResponse(ChannelHandlerContext ctx, boolean isKeepAlive,
}
serviceContext.responseHeader(headerKey_reference, serviceContext.txId());
serviceContext.responseHeader(headerKey_serverTimestamp, OffsetDateTime.now().format(TimeUtil.ISO_ZONED_DATE_TIME3));
final HttpResponseStatus status = serviceContext.status();

if (serviceContext.file() != null) {
return sendFile(ctx, isKeepAlive, serviceContext);
}
if (serviceContext.redirect() != null) {
sendRedirect(ctx, serviceContext.redirect(), status);
return 0;
}

HttpResponseStatus status = serviceContext.status();
ResponseEncoder responseEncoder = serviceContext.responseEncoder();
if (StringUtils.isBlank(serviceContext.txt()) && status.code() >= 400) {
boolean hasErrorContent = StringUtils.isEmpty(serviceContext.txt()) && status.code() >= 400;
if (hasErrorContent) {
if (serviceContext.error() == null) {
serviceContext.error(null);
}

String clientAcceptContentType = serviceContext.clientAcceptContentType();
String textResponse;
String errorResponse;
if (clientAcceptContentType != null && clientAcceptContentType.contains("xml")) {
textResponse = serviceContext.error().toXML();
errorResponse = serviceContext.error().toXML();
serviceContext.contentType(MediaType.APPLICATION_XML);
} else {
textResponse = serviceContext.error().toJson();
errorResponse = serviceContext.error().toJson();
serviceContext.contentType(MediaType.APPLICATION_JSON);
}
if (errorAuditor != null) {
textResponse = errorAuditor.beforeSendingError(textResponse);
errorResponse = errorAuditor.beforeSendingError(errorResponse);
}
serviceContext.txt(textResponse);
}
if (StringUtils.isNotBlank(serviceContext.txt())) {
return sendText(ctx, isKeepAlive, serviceContext.responseHeaders(), status, serviceContext.txt(), serviceContext.contentType(), serviceContext.charsetName(), true, responseEncoder);
}
if (serviceContext.redirect() != null) {
sendRedirect(ctx, serviceContext.redirect(), status);
return 0;
serviceContext.txt(errorResponse);
}

if (serviceContext.autoConvertBlank200To204() && HttpResponseStatus.OK.equals(status)) {
status = HttpResponseStatus.NO_CONTENT;
if (HttpResponseStatus.OK.equals(status) && serviceContext.autoConvertBlank200To204() && StringUtils.isEmpty(serviceContext.txt())) {
serviceContext.status(HttpResponseStatus.NO_CONTENT);
}
return sendText(ctx, isKeepAlive, serviceContext.responseHeaders(), status, null, serviceContext.contentType(), serviceContext.charsetName(), true, responseEncoder);
return sendText(ctx, isKeepAlive, serviceContext.responseHeaders(), serviceContext.status(), serviceContext.txt(), serviceContext.contentType(), serviceContext.charsetName(), true, serviceContext.responseEncoder());
}

protected static final String DEFAULT_CHARSET = "UTF-8";
Expand Down Expand Up @@ -195,13 +192,8 @@ protected static long sendText(ChannelHandlerContext ctx, boolean isKeepAlive, H
if (contentType != null) {
h.set(HttpHeaderNames.CONTENT_TYPE, contentType + ";charset=" + charsetName);
}
long contentLength = resp.content().readableBytes();

if (contentLength > Integer.MAX_VALUE) {
h.set(HttpHeaderNames.CONTENT_LENGTH, String.valueOf(contentLength));
} else {
h.setInt(HttpHeaderNames.CONTENT_LENGTH, (int) contentLength);
}
int contentLength = resp.content().readableBytes();
h.set(HttpHeaderNames.CONTENT_LENGTH, String.valueOf(contentLength));

// send
if (isKeepAlive) {//HttpUtil.isKeepAlive(req);
Expand All @@ -221,6 +213,9 @@ protected static long sendText(ChannelHandlerContext ctx, boolean isKeepAlive, H
ctx.write(resp).addListener(ChannelFutureListener.CLOSE);
}
}
if (serviceHeaders != null) {
serviceHeaders.set(h);
}
return contentLength;
}

Expand All @@ -231,6 +226,7 @@ private static long sendFile(ChannelHandlerContext ctx, boolean isKeepAlive, fin
long fileLength = -1;
final RandomAccessFile randomAccessFile;
File file = serviceContext.file();
serviceContext.memo("sendFile", file.getAbsolutePath());
String filePath = file.getName();
try {
randomAccessFile = new RandomAccessFile(file, "r");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package org.summerboot.jexpress.nio.server.domain;

import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;

public class LoginVo {
@NotNull
@NotEmpty
protected String username;

@NotNull
@NotEmpty
protected String password;

public LoginVo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import io.swagger.v3.oas.annotations.servers.Server;
import jakarta.annotation.Nonnull;
import jakarta.annotation.security.RolesAllowed;
import jakarta.validation.Valid;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.FormParam;
Expand Down Expand Up @@ -384,7 +385,7 @@ public Caller longin_jSecurityCheck(@Parameter(required = true) @Nonnull @FormPa
@Deamon
//@CaptureTransaction("user.signJWT")
@Log(requestBody = false, responseHeader = false)
public Caller longin_JSON(@Nonnull LoginVo loginVo,
public Caller longin_JSON(@Valid @Nonnull LoginVo loginVo,
@Parameter(hidden = true) final ServiceContext context) throws IOException, NamingException {
return login(auth, loginVo.getUsername(), loginVo.getPassword(), context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public String signJWT(String username, String pwd, E metaData, int validForMinut
Caller caller = authenticate(username, pwd, (E) metaData, authenticatorListener, context);
context.poi(BootPOI.LDAP_END);

context.caller(caller);
return signJWT(caller, validForMinutes, context);
}

Expand All @@ -109,7 +110,6 @@ public String signJWT(Caller caller, int validForMinutes, final ServiceContext c
if (authenticatorListener != null) {
authenticatorListener.onLoginSuccess(caller.getUid(), token);
}
context.caller(caller);
return token;
}

Expand Down
Loading