diff --git a/frameworks/Java/smart-socket/pom.xml b/frameworks/Java/smart-socket/pom.xml index e4bbc87e873..81fbc295b98 100644 --- a/frameworks/Java/smart-socket/pom.xml +++ b/frameworks/Java/smart-socket/pom.xml @@ -8,10 +8,10 @@ jar UTF-8 - 11 - 11 + 17 + 17 2.17.1 - 0.2.1-SNAPSHOT + 0.6-SNAPSHOT 5.0.0 0.9.23 diff --git a/frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile b/frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile index b6fa2e31680..8b1cbe79930 100644 --- a/frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile +++ b/frameworks/Java/smart-socket/smart-socket-smart-servlet.dockerfile @@ -1,13 +1,13 @@ -FROM maven:3.6.1-jdk-11-slim as maven +FROM maven:3.8.6-openjdk-18-slim as maven WORKDIR /smart-socket COPY pom.xml pom.xml COPY src src RUN mvn compile assembly:single -q -FROM openjdk:11.0.3-jdk-slim +FROM openjdk:21-jdk-slim WORKDIR /smart-socket COPY --from=maven /smart-socket/target/smart-socket-benchmark-1.0-jar-with-dependencies.jar app.jar EXPOSE 8080 -CMD ["java", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-XX:+AggressiveOpts", "-cp", "app.jar", "org.smartboot.servlet.Bootstrap"] +CMD ["java", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-cp", "app.jar", "org.smartboot.servlet.Bootstrap"] diff --git a/frameworks/Java/smart-socket/smart-socket.dockerfile b/frameworks/Java/smart-socket/smart-socket.dockerfile index f51ddcbd178..b40ad2c8d43 100644 --- a/frameworks/Java/smart-socket/smart-socket.dockerfile +++ b/frameworks/Java/smart-socket/smart-socket.dockerfile @@ -1,13 +1,13 @@ -FROM maven:3.6.1-jdk-11-slim as maven +FROM maven:3.8.6-openjdk-18-slim as maven WORKDIR /smart-socket COPY pom.xml pom.xml COPY src src RUN mvn compile assembly:single -q -FROM openjdk:11.0.3-jdk-slim +FROM openjdk:21-jdk-slim WORKDIR /smart-socket COPY --from=maven /smart-socket/target/smart-socket-benchmark-1.0-jar-with-dependencies.jar app.jar EXPOSE 8080 -CMD ["java", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-XX:+AggressiveOpts", "-cp", "app.jar", "org.smartboot.http.Bootstrap"] +CMD ["java", "-server", "-XX:+UseNUMA", "-XX:+UseParallelGC", "-cp", "app.jar", "org.smartboot.http.Bootstrap"] diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java index 0aa0f44a2d1..b20525ec571 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/http/JsonUtil.java @@ -1,11 +1,12 @@ package org.smartboot.http; +import com.jsoniter.output.JsonStream; +import com.jsoniter.output.JsonStreamPool; import com.jsoniter.spi.JsonException; -import io.edap.x.json.Eson; -import io.edap.x.json.JsonWriter; +import com.jsoniter.spi.Slice; +import jakarta.servlet.http.HttpServletResponse; import org.smartboot.http.server.HttpResponse; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** @@ -13,57 +14,56 @@ * @version V1.0 , 2020/6/16 */ public class JsonUtil { + // public static void writeJsonBytes(HttpResponse httpResponse, Object obj) { +// JsonWriter writer = Eson.THREAD_WRITER.get(); +// try { +// writer.reset(); +// Eson.serialize(obj, writer); +// httpResponse.setContentLength(writer.size()); +// writer.toStream(httpResponse.getOutputStream()); +// } catch (IOException e) { +// throw new JsonException(e); +// } +// } public static void writeJsonBytes(HttpResponse httpResponse, Object obj) { - JsonWriter writer = Eson.THREAD_WRITER.get(); + JsonStream stream = JsonStreamPool.borrowJsonStream(); try { - writer.reset(); - Eson.serialize(obj, writer); - httpResponse.setContentLength(writer.size()); - writer.toStream(httpResponse.getOutputStream()); + stream.reset(null); + stream.writeVal(obj.getClass(), obj); + Slice slice = stream.buffer(); + httpResponse.setContentLength(slice.tail()); + httpResponse.getOutputStream().write(slice.data(), 0, slice.tail()); } catch (IOException e) { throw new JsonException(e); + } finally { + JsonStreamPool.returnJsonStream(stream); } } -// public static void writeJsonBytes(HttpResponse httpResponse, Object obj) { -// JsonStream stream = JsonStreamPool.borrowJsonStream(); -// try { -// stream.reset(null); -// stream.writeVal(obj.getClass(), obj); -// Slice slice = stream.buffer(); -// httpResponse.setContentLength(slice.tail()); -// httpResponse.getOutputStream().write(slice.data(), 0, slice.tail()); -// } catch (IOException e) { -// throw new JsonException(e); -// } finally { -// JsonStreamPool.returnJsonStream(stream); -// } -// } + public static void writeJsonBytes(HttpServletResponse httpResponse, Object obj) { + JsonStream stream = JsonStreamPool.borrowJsonStream(); + try { + stream.reset(null); + stream.writeVal(obj.getClass(), obj); + Slice slice = stream.buffer(); + httpResponse.setContentLength(slice.tail()); + httpResponse.getOutputStream().write(slice.data(), 0, slice.tail()); + } catch (IOException e) { + throw new JsonException(e); + } finally { + JsonStreamPool.returnJsonStream(stream); + } + } // public static void writeJsonBytes(HttpServletResponse httpResponse, Object obj) { -// JsonStream stream = JsonStreamPool.borrowJsonStream(); +// JsonWriter writer = Eson.THREAD_WRITER.get(); // try { -// stream.reset(null); -// stream.writeVal(obj.getClass(), obj); -// Slice slice = stream.buffer(); -// httpResponse.setContentLength(slice.tail()); -// httpResponse.getOutputStream().write(slice.data(), 0, slice.tail()); +// writer.reset(); +// Eson.serialize(obj, writer); +// httpResponse.setContentLength(writer.size()); +// writer.toStream(httpResponse.getOutputStream()); // } catch (IOException e) { // throw new JsonException(e); -// } finally { -// JsonStreamPool.returnJsonStream(stream); // } // } - - public static void writeJsonBytes(HttpServletResponse httpResponse, Object obj) { - JsonWriter writer = Eson.THREAD_WRITER.get(); - try { - writer.reset(); - Eson.serialize(obj, writer); - httpResponse.setContentLength(writer.size()); - writer.toStream(httpResponse.getOutputStream()); - } catch (IOException e) { - throw new JsonException(e); - } - } } diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java index 23efbecbd3f..681ad1a7593 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java @@ -4,13 +4,9 @@ import org.smartboot.http.server.HttpRequest; import org.smartboot.http.server.HttpResponse; import org.smartboot.http.server.HttpServerHandler; -import org.smartboot.http.server.impl.Request; import org.smartboot.servlet.conf.ServletInfo; -import org.smartboot.socket.StateMachineEnum; -import org.smartboot.socket.extension.processor.AbstractMessageProcessor; -import org.smartboot.socket.transport.AioSession; -import java.io.IOException; +import java.util.concurrent.CompletableFuture; /** * @author 三刀(zhengjunweimail@163.com) @@ -18,7 +14,7 @@ */ public class Bootstrap { - public static void main(String[] args) { + public static void main(String[] args) throws Throwable { ContainerRuntime containerRuntime = new ContainerRuntime(); // plaintext ServletContextRuntime applicationRuntime = new ServletContextRuntime("/"); @@ -50,8 +46,8 @@ public static void main(String[] args) { bootstrap.setPort(8080) .httpHandler(new HttpServerHandler() { @Override - public void handle(HttpRequest request, HttpResponse response) throws IOException { - containerRuntime.doHandle(request, response); + public void handle(HttpRequest request, HttpResponse response, CompletableFuture completableFuture) throws Throwable { + containerRuntime.doHandle(request, response, completableFuture); } }) .start(); diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java index f5c2ca710c6..c3900de716c 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/HelloWorldServlet.java @@ -1,9 +1,10 @@ package org.smartboot.servlet; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + import java.io.IOException; /** @@ -16,7 +17,7 @@ public class HelloWorldServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentLength(BODY.length); - resp.setContentType("text/plain; charset=UTF-8"); + resp.setContentType("text/plain;charset=UTF-8"); resp.setBufferSize(0); resp.getOutputStream().write(BODY); } diff --git a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java index 1c0081d7f23..064bc80556d 100644 --- a/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java +++ b/frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/JsonServlet.java @@ -1,12 +1,12 @@ package org.smartboot.servlet; +import jakarta.servlet.ServletException; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import org.smartboot.Message; import org.smartboot.http.JsonUtil; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** @@ -16,7 +16,7 @@ public class JsonServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - resp.setContentType("application/json"); + resp.setContentType("application/json;charset=UTF-8"); resp.setBufferSize(0); JsonUtil.writeJsonBytes(resp, new Message("Hello, World!")); }