Browse Source

适配最新版

zhengjw22 5 months ago
parent
commit
2f429b3d7b

+ 4 - 9
frameworks/Java/smart-socket/pom.xml

@@ -11,7 +11,7 @@
         <maven.compiler.source>21</maven.compiler.source>
         <maven.compiler.source>21</maven.compiler.source>
         <maven.compiler.target>21</maven.compiler.target>
         <maven.compiler.target>21</maven.compiler.target>
         <log4j.version>2.17.1</log4j.version>
         <log4j.version>2.17.1</log4j.version>
-        <smartservlet.version>2.8</smartservlet.version>
+        <smartservlet.version>2.9.1</smartservlet.version>
         <hikaricp.version>5.0.0</hikaricp.version>
         <hikaricp.version>5.0.0</hikaricp.version>
         <jsoniter.version>0.9.23</jsoniter.version>
         <jsoniter.version>0.9.23</jsoniter.version>
     </properties>
     </properties>
@@ -19,13 +19,8 @@
     <dependencies>
     <dependencies>
         <dependency>
         <dependency>
             <groupId>tech.smartboot.feat</groupId>
             <groupId>tech.smartboot.feat</groupId>
-            <artifactId>feat-restful</artifactId>
-            <version>0.5</version>
-        </dependency>
-        <dependency>
-            <groupId>io.edap</groupId>
-            <artifactId>edapx-json</artifactId>
-            <version>0.1-SNAPSHOT</version>
+            <artifactId>feat-cloud-starter</artifactId>
+            <version>0.8.2</version>
         </dependency>
         </dependency>
         <dependency>
         <dependency>
             <groupId>tech.smartboot.servlet</groupId>
             <groupId>tech.smartboot.servlet</groupId>
@@ -34,7 +29,7 @@
             <exclusions>
             <exclusions>
                 <exclusion>
                 <exclusion>
                     <groupId>tech.smartboot.feat</groupId>
                     <groupId>tech.smartboot.feat</groupId>
-                    <artifactId>feat-restful</artifactId>
+                    <artifactId>feat-core</artifactId>
                 </exclusion>
                 </exclusion>
             </exclusions>
             </exclusions>
         </dependency>
         </dependency>

+ 3 - 20
frameworks/Java/smart-socket/src/main/java/org/smartboot/http/Bootstrap.java

@@ -8,31 +8,14 @@
 
 
 package org.smartboot.http;
 package org.smartboot.http;
 
 
-import tech.smartboot.feat.restful.RestFeat;
+
+import tech.smartboot.feat.cloud.FeatCloud;
 
 
 public class Bootstrap {
 public class Bootstrap {
-    static byte[] body = "Hello, World!".getBytes();
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
         int cpuNum = Runtime.getRuntime().availableProcessors();
         int cpuNum = Runtime.getRuntime().availableProcessors();
-        // 定义服务器接受的消息类型以及各类消息对应的处理器
-//        Feat.createHttpServer(options -> {
-//            options.threadNum(cpuNum + 1)
-//                    .headerLimiter(0)
-//                    .readBufferSize(1024 * 4)
-//                    .writeBufferSize(1024 * 4);
-//        }).httpHandler(request -> {
-//            HttpResponse response = request.getResponse();
-//            if ("/plaintext".equals(request.getRequestURI())) {
-//                response.setContentLength(body.length);
-//                response.setContentType(HeaderValueEnum.ContentType.TEXT_PLAIN_UTF8);
-//                response.write(body);
-//            } else if ("/json".equals(request.getRequestURI())) {
-//                response.setContentType("application/json");
-//                JsonUtil.writeJsonBytes(response, new Message("Hello, World!"));
-//            }
-//        }).listen(8080);
-        RestFeat.createServer(options -> {
+        FeatCloud.cloudServer(options -> {
             options.threadNum(cpuNum + 1)
             options.threadNum(cpuNum + 1)
                     .headerLimiter(0)
                     .headerLimiter(0)
                     .readBufferSize(1024 * 4)
                     .readBufferSize(1024 * 4)

+ 5 - 5
frameworks/Java/smart-socket/src/main/java/org/smartboot/http/FeatController.java

@@ -1,9 +1,9 @@
 package org.smartboot.http;
 package org.smartboot.http;
 
 
 import org.smartboot.Message;
 import org.smartboot.Message;
-import tech.smartboot.feat.core.apt.annotation.Controller;
-import tech.smartboot.feat.core.apt.annotation.RequestMapping;
-import tech.smartboot.feat.core.common.enums.HeaderValueEnum;
+import tech.smartboot.feat.cloud.annotation.Controller;
+import tech.smartboot.feat.cloud.annotation.RequestMapping;
+import tech.smartboot.feat.core.common.HeaderValue;
 import tech.smartboot.feat.core.server.HttpResponse;
 import tech.smartboot.feat.core.server.HttpResponse;
 
 
 @Controller
 @Controller
@@ -12,13 +12,13 @@ public class FeatController {
 
 
     @RequestMapping("/plaintext")
     @RequestMapping("/plaintext")
     public byte[] plaintext(HttpResponse response) {
     public byte[] plaintext(HttpResponse response) {
-        response.setContentType(HeaderValueEnum.ContentType.TEXT_PLAIN_UTF8);
+        response.setContentType(HeaderValue.ContentType.TEXT_PLAIN_UTF8);
         return body;
         return body;
     }
     }
 
 
     @RequestMapping("/json")
     @RequestMapping("/json")
     public Message json(HttpResponse response) {
     public Message json(HttpResponse response) {
-        response.setContentType(HeaderValueEnum.ContentType.APPLICATION_JSON_UTF8);
+        response.setContentType(HeaderValue.ContentType.APPLICATION_JSON_UTF8);
         return new Message("Hello, World!");
         return new Message("Hello, World!");
     }
     }
 }
 }

+ 7 - 2
frameworks/Java/smart-socket/src/main/java/org/smartboot/http/MultipleQueriesHandler.java

@@ -2,9 +2,9 @@ package org.smartboot.http;
 
 
 
 
 import tech.smartboot.feat.core.common.utils.NumberUtils;
 import tech.smartboot.feat.core.common.utils.NumberUtils;
+import tech.smartboot.feat.core.server.HttpHandler;
 import tech.smartboot.feat.core.server.HttpRequest;
 import tech.smartboot.feat.core.server.HttpRequest;
 import tech.smartboot.feat.core.server.HttpResponse;
 import tech.smartboot.feat.core.server.HttpResponse;
-import tech.smartboot.feat.core.server.handler.BaseHttpHandler;
 
 
 import javax.sql.DataSource;
 import javax.sql.DataSource;
 import java.io.IOException;
 import java.io.IOException;
@@ -19,7 +19,7 @@ import java.util.concurrent.ThreadLocalRandom;
  * @author 三刀
  * @author 三刀
  * @version V1.0 , 2020/6/16
  * @version V1.0 , 2020/6/16
  */
  */
-public class MultipleQueriesHandler extends BaseHttpHandler {
+public class MultipleQueriesHandler implements HttpHandler {
     private DataSource dataSource;
     private DataSource dataSource;
 
 
     public MultipleQueriesHandler(DataSource dataSource) {
     public MultipleQueriesHandler(DataSource dataSource) {
@@ -59,6 +59,11 @@ public class MultipleQueriesHandler extends BaseHttpHandler {
 
 
     }
     }
 
 
+    @Override
+    public void handle(HttpRequest request) throws Throwable {
+
+    }
+
     protected int getRandomNumber() {
     protected int getRandomNumber() {
         return 1 + ThreadLocalRandom.current().nextInt(10000);
         return 1 + ThreadLocalRandom.current().nextInt(10000);
     }
     }

+ 7 - 2
frameworks/Java/smart-socket/src/main/java/org/smartboot/http/SingleQueryHandler.java

@@ -1,9 +1,9 @@
 package org.smartboot.http;
 package org.smartboot.http;
 
 
 
 
+import tech.smartboot.feat.core.server.HttpHandler;
 import tech.smartboot.feat.core.server.HttpRequest;
 import tech.smartboot.feat.core.server.HttpRequest;
 import tech.smartboot.feat.core.server.HttpResponse;
 import tech.smartboot.feat.core.server.HttpResponse;
-import tech.smartboot.feat.core.server.handler.BaseHttpHandler;
 
 
 import javax.sql.DataSource;
 import javax.sql.DataSource;
 import java.io.IOException;
 import java.io.IOException;
@@ -18,7 +18,7 @@ import java.util.concurrent.ThreadLocalRandom;
  * @author 三刀
  * @author 三刀
  * @version V1.0 , 2020/6/16
  * @version V1.0 , 2020/6/16
  */
  */
-public class SingleQueryHandler extends BaseHttpHandler {
+public class SingleQueryHandler implements HttpHandler {
     private DataSource dataSource;
     private DataSource dataSource;
 
 
     public SingleQueryHandler(DataSource dataSource) {
     public SingleQueryHandler(DataSource dataSource) {
@@ -49,6 +49,11 @@ public class SingleQueryHandler extends BaseHttpHandler {
 
 
     }
     }
 
 
+    @Override
+    public void handle(HttpRequest request) throws Throwable {
+
+    }
+
     protected int getRandomNumber() {
     protected int getRandomNumber() {
         return 1 + ThreadLocalRandom.current().nextInt(10000);
         return 1 + ThreadLocalRandom.current().nextInt(10000);
     }
     }

+ 5 - 5
frameworks/Java/smart-socket/src/main/java/org/smartboot/servlet/Bootstrap.java

@@ -4,7 +4,6 @@ package org.smartboot.servlet;
 import tech.smartboot.servlet.Container;
 import tech.smartboot.servlet.Container;
 import tech.smartboot.servlet.ServletContextRuntime;
 import tech.smartboot.servlet.ServletContextRuntime;
 import tech.smartboot.servlet.conf.ServletInfo;
 import tech.smartboot.servlet.conf.ServletInfo;
-import tech.smartboot.servlet.conf.ServletMappingInfo;
 
 
 /**
 /**
  * @author 三刀([email protected]
  * @author 三刀([email protected]
@@ -13,7 +12,7 @@ import tech.smartboot.servlet.conf.ServletMappingInfo;
 public class Bootstrap {
 public class Bootstrap {
 
 
     public static void main(String[] args) throws Throwable {
     public static void main(String[] args) throws Throwable {
-        System.setProperty("smart-servlet-spring-boot-starter","true");
+        System.setProperty("smart-servlet-spring-boot-starter", "true");
         Container containerRuntime = new Container();
         Container containerRuntime = new Container();
         // plaintext
         // plaintext
         ServletContextRuntime applicationRuntime = new ServletContextRuntime(null, Thread.currentThread().getContextClassLoader(), "/");
         ServletContextRuntime applicationRuntime = new ServletContextRuntime(null, Thread.currentThread().getContextClassLoader(), "/");
@@ -23,23 +22,24 @@ public class Bootstrap {
         ServletInfo plainTextServletInfo = new ServletInfo();
         ServletInfo plainTextServletInfo = new ServletInfo();
         plainTextServletInfo.setServletName("plaintext");
         plainTextServletInfo.setServletName("plaintext");
         plainTextServletInfo.setServletClass(HelloWorldServlet.class.getName());
         plainTextServletInfo.setServletClass(HelloWorldServlet.class.getName());
-        applicationRuntime.getDeploymentInfo().addServletMapping(new ServletMappingInfo(plainTextServletInfo.getServletName(), "/plaintext"));
+        plainTextServletInfo.addServletMapping("/plaintext", applicationRuntime);
         applicationRuntime.getDeploymentInfo().addServlet(plainTextServletInfo);
         applicationRuntime.getDeploymentInfo().addServlet(plainTextServletInfo);
 
 
         // json
         // json
         ServletInfo jsonServletInfo = new ServletInfo();
         ServletInfo jsonServletInfo = new ServletInfo();
         jsonServletInfo.setServletName("json");
         jsonServletInfo.setServletName("json");
         jsonServletInfo.setServletClass(JsonServlet.class.getName());
         jsonServletInfo.setServletClass(JsonServlet.class.getName());
+        jsonServletInfo.addServletMapping("/json", applicationRuntime);
         applicationRuntime.getDeploymentInfo().addServlet(jsonServletInfo);
         applicationRuntime.getDeploymentInfo().addServlet(jsonServletInfo);
-        applicationRuntime.getDeploymentInfo().addServletMapping(new ServletMappingInfo(jsonServletInfo.getServletName(), "/json"));
         containerRuntime.addRuntime(applicationRuntime);
         containerRuntime.addRuntime(applicationRuntime);
         int cpuNum = Runtime.getRuntime().availableProcessors();
         int cpuNum = Runtime.getRuntime().availableProcessors();
         // 定义服务器接受的消息类型以及各类消息对应的处理器
         // 定义服务器接受的消息类型以及各类消息对应的处理器
         containerRuntime.getConfiguration()
         containerRuntime.getConfiguration()
                 .setThreadNum(cpuNum)
                 .setThreadNum(cpuNum)
+                .setHeaderLimiter(0)
                 .setReadBufferSize(1024 * 4);
                 .setReadBufferSize(1024 * 4);
         containerRuntime.initialize();
         containerRuntime.initialize();
         containerRuntime.start();
         containerRuntime.start();
-        
+
     }
     }
 }
 }