Skip to content

Commit a176f17

Browse files
author
wangzihao
committed
Merge remote-tracking branch 'origin/master'
2 parents 0c90aa5 + af5cea2 commit a176f17

File tree

8 files changed

+37
-22
lines changed

8 files changed

+37
-22
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
![](https://user-images.githubusercontent.com/18204507/68989252-9d871a80-087e-11ea-96e1-20c12689c12a.png)
1212

13+
### 注意
14+
本项目不支持springboot3和jakarta-servlet,如果有需要可联系我,看下是否需要继续支持。
15+
1316
### 优势
1417

1518
- 1.针对spring项目# 可以替代tomcat或jetty. 导包后一个@EnableNettyEmbedded注解即用.
@@ -149,7 +152,7 @@ github地址 : https://github.com/wangzihaogithub/spring-boot-protocol
149152
<dependency>
150153
<groupId>com.github.wangzihaogithub</groupId>
151154
<artifactId>spring-boot-protocol</artifactId>
152-
<version>2.3.23</version>
155+
<version>2.3.25</version>
153156
</dependency>
154157
```
155158

@@ -161,7 +164,7 @@ github地址 : https://github.com/wangzihaogithub/spring-boot-protocol
161164
<dependency>
162165
<groupId>com.github.wangzihaogithub</groupId>
163166
<artifactId>netty-servlet</artifactId>
164-
<version>2.3.23</version>
167+
<version>2.3.25</version>
165168
</dependency>
166169
```
167170

@@ -317,7 +320,7 @@ github地址 : https://github.com/wangzihaogithub/spring-boot-protocol
317320
<dependency>
318321
<groupId>com.github.wangzihaogithub</groupId>
319322
<artifactId>spring-boot-protocol</artifactId>
320-
<version>2.3.23</version>
323+
<version>2.3.25</version>
321324
</dependency>
322325

323326
2.编写代码
@@ -397,7 +400,7 @@ github地址 : https://github.com/wangzihaogithub/spring-boot-protocol
397400
<dependency>
398401
<groupId>com.github.wangzihaogithub</groupId>
399402
<artifactId>spring-boot-protocol</artifactId>
400-
<version>2.3.23</version>
403+
<version>2.3.25</version>
401404
</dependency>
402405

403406
2.编写代码
@@ -486,7 +489,7 @@ github地址 : https://github.com/wangzihaogithub/spring-boot-protocol
486489
<dependency>
487490
<groupId>com.github.wangzihaogithub</groupId>
488491
<artifactId>spring-boot-protocol</artifactId>
489-
<version>2.3.23</version>
492+
<version>2.3.25</version>
490493
</dependency>
491494
492495
2.编写启动类

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.github.wangzihaogithub</groupId>
66
<artifactId>spring-boot-protocol</artifactId>
7-
<version>2.3.23</version>
7+
<version>2.3.25</version>
88
<packaging>jar</packaging>
99

1010
<name>Spring Boot Protocol</name>
@@ -49,7 +49,7 @@
4949
<connection>scm:git:https://github.com/wangzihaogithub/spring-boot-protocol.git</connection>
5050
<developerConnection>scm:git:git@github.com:wangzihaogithub/spring-boot-protocol.git</developerConnection>
5151
<url>git@github.com:wangzihaogithub/spring-boot-protocol.git</url>
52-
<tag>v2.3.23</tag>
52+
<tag>v2.3.25</tag>
5353
</scm>
5454

5555
<!-- 开发者信息 -->
@@ -609,4 +609,4 @@
609609
<!--gpg &#45;&#45;keyserver hkp://pool.sks-keyservers.net &#45;&#45;send-keys A12DCF7DF1-->
610610
<!--JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8-->
611611
<!-- jar -cvf bundle.jar spring-boot-protocol-* -->
612-
</project>
612+
</project>

src/main/java/com/github/netty/protocol/servlet/ServletHttpAsyncRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private void decodePaths() {
219219
} else {
220220
queryString = null;
221221
}
222-
this.requestURI = com.github.netty.protocol.servlet.ServletContext.normPath(requestURI);
222+
this.requestURI = requestURI;
223223
this.queryString = queryString;
224224
}
225225
this.decodePathsFlag = true;

src/main/java/com/github/netty/protocol/servlet/ServletHttpForwardRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private void decodePaths() {
221221
} else {
222222
queryString = null;
223223
}
224-
this.requestURI = com.github.netty.protocol.servlet.ServletContext.normPath(requestURI);
224+
this.requestURI = requestURI;
225225
this.queryString = queryString;
226226
}
227227
this.decodePathsFlag = true;

src/main/java/com/github/netty/protocol/servlet/ServletHttpIncludeRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private void decodePaths() {
221221
} else {
222222
queryString = null;
223223
}
224-
this.requestURI = com.github.netty.protocol.servlet.ServletContext.normPath(requestURI);
224+
this.requestURI = requestURI;
225225
this.queryString = queryString;
226226
}
227227
this.decodePathsFlag = true;

src/main/java/com/github/netty/protocol/servlet/ServletHttpServletRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ private void decodePaths() {
514514
} else {
515515
queryString = null;
516516
}
517-
this.requestURI = com.github.netty.protocol.servlet.ServletContext.normPath(requestURI);
517+
this.requestURI = requestURI;
518518
this.queryString = queryString;
519519
this.decodePathsFlag = true;
520520
}

src/main/java/com/github/netty/springboot/server/NettyTcpServerFactory.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.github.netty.protocol.HttpServletProtocol;
99
import com.github.netty.protocol.servlet.ServletContext;
1010
import com.github.netty.protocol.servlet.ServletRegistration;
11+
import com.github.netty.protocol.servlet.util.HttpLazyThreadPool;
1112
import com.github.netty.springboot.NettyProperties;
1213
import org.springframework.boot.web.reactive.server.ConfigurableReactiveWebServerFactory;
1314
import org.springframework.boot.web.server.WebServer;
@@ -23,7 +24,6 @@
2324
import java.net.InetSocketAddress;
2425
import java.net.UnknownHostException;
2526
import java.util.Collection;
26-
import java.util.Objects;
2727
import java.util.TreeSet;
2828
import java.util.function.Supplier;
2929

@@ -83,12 +83,13 @@ public WebServer getWebServer(HttpHandler httpHandler) {
8383
//Server port
8484
InetSocketAddress serverAddress = getServerSocketAddress(getAddress(), getPort());
8585
ServletContext servletContext = getServletContext();
86-
if (servletContext != null) {
87-
ServletRegistration.Dynamic servletRegistration = servletContext.addServlet("default", new ServletHttpHandlerAdapter(httpHandler));
88-
servletRegistration.setAsyncSupported(true);
89-
servletRegistration.addMapping("/");
90-
servletContext.setServerAddress(serverAddress);
86+
if (servletContext == null) {
87+
servletContext = createHttpServletProtocolSpringAdapter().getServletContext();
9188
}
89+
ServletRegistration.Dynamic servletRegistration = servletContext.addServlet("default", new ServletHttpHandlerAdapter(httpHandler));
90+
servletRegistration.setAsyncSupported(true);
91+
servletRegistration.addMapping("/");
92+
servletContext.setServerAddress(serverAddress);
9293
return new NettyTcpServer(serverAddress, properties, protocolHandlers, serverListeners, channelHandlerSupplier);
9394
} catch (Exception e) {
9495
throw new IllegalStateException(e.getMessage(), e);
@@ -103,7 +104,10 @@ public WebServer getWebServer(HttpHandler httpHandler) {
103104
*/
104105
@Override
105106
public WebServer getWebServer(ServletContextInitializer... initializers) {
106-
ServletContext servletContext = Objects.requireNonNull(getServletContext());
107+
ServletContext servletContext = getServletContext();
108+
if (servletContext == null) {
109+
servletContext = createHttpServletProtocolSpringAdapter().getServletContext();
110+
}
107111
try {
108112
//Server port
109113
InetSocketAddress serverAddress = getServerSocketAddress(getAddress(), getPort());
@@ -162,6 +166,14 @@ public ServletContext getServletContext() {
162166
return null;
163167
}
164168

169+
protected HttpServletProtocol createHttpServletProtocolSpringAdapter() {
170+
HttpLazyThreadPool threadPool = new HttpLazyThreadPool("NettyX-http");
171+
HttpServletProtocolSpringAdapter adapter = new HttpServletProtocolSpringAdapter(new NettyProperties(), null, threadPool, threadPool);
172+
protocolHandlers.add(adapter);
173+
serverListeners.add(adapter);
174+
return adapter;
175+
}
176+
165177
public Collection<ProtocolHandler> getProtocolHandlers() {
166178
return protocolHandlers;
167179
}

src/main/resources/server.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
server.info=Github Spring-boot-protocol/2.3.23
17-
server.number=2.3.23
18-
server.built=Sep 13 2024 13:23:31 UTC+8
16+
server.info=Github Spring-boot-protocol/2.3.25
17+
server.number=2.3.25
18+
server.built=Apr 12 2025 19:14:22 UTC+8

0 commit comments

Comments
 (0)