Skip to content

Commit 68e4350

Browse files
committed
"Apply Grizzly 4.x." (eclipse-ee4j#123)
+ Upgraded Grizzly version from 2.4.4 to 4.x. + Upgraded Jetty version from 9.x to 12.x. + Test cases are comprehensively migrated based on the changed interface of the higher version. + Enabled GrizzlyTransferListenerTest. + Added mvn’s options. ex) “forkCount=1, reuseForks=false” + Fixed "SLF4J: Failed to load class org.slf4j.impl.StaticLoggerBinder" log.
1 parent a3d0ac8 commit 68e4350

File tree

64 files changed

+1489
-1231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1489
-1231
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ jobs:
3232
--no-transfer-progress \
3333
install \
3434
--define skipSBOM \
35-
--define 'test=*Test,!GrizzlyTransferListenerTest'
35+
--define forkCount=1 \
36+
--define reuseForks=false

pom.xml

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@
121121
<dependency>
122122
<groupId>org.slf4j</groupId>
123123
<artifactId>slf4j-api</artifactId>
124-
<version>1.7.36</version>
124+
<version>${slf4j.version}</version>
125+
</dependency>
126+
<dependency>
127+
<groupId>org.apache.logging.log4j</groupId>
128+
<artifactId>log4j-slf4j2-impl</artifactId>
129+
<version>${log4j.version}</version>
125130
</dependency>
126131

127132
<dependency>
@@ -132,24 +137,6 @@
132137
</dependency>
133138

134139
<!-- Test dependencies -->
135-
<dependency>
136-
<groupId>ch.qos.logback</groupId>
137-
<artifactId>logback-classic</artifactId>
138-
<version>1.5.19</version>
139-
<scope>test</scope>
140-
</dependency>
141-
<dependency>
142-
<groupId>org.apache.logging.log4j</groupId>
143-
<artifactId>log4j-core</artifactId>
144-
<version>2.25.2</version>
145-
<scope>test</scope>
146-
</dependency>
147-
<dependency>
148-
<groupId>org.apache.logging.log4j</groupId>
149-
<artifactId>log4j-1.2-api</artifactId>
150-
<version>2.25.2</version>
151-
<scope>test</scope>
152-
</dependency>
153140
<dependency>
154141
<groupId>org.testng</groupId>
155142
<artifactId>testng</artifactId>
@@ -175,14 +162,8 @@
175162
<scope>test</scope>
176163
</dependency>
177164
<dependency>
178-
<groupId>org.eclipse.jetty</groupId>
179-
<artifactId>jetty-proxy</artifactId>
180-
<version>${jetty.version}</version>
181-
<scope>test</scope>
182-
</dependency>
183-
<dependency>
184-
<groupId>org.eclipse.jetty.websocket</groupId>
185-
<artifactId>websocket-server</artifactId>
165+
<groupId>org.eclipse.jetty.ee11.websocket</groupId>
166+
<artifactId>jetty-ee11-websocket-jetty-server</artifactId>
186167
<version>${jetty.version}</version>
187168
<scope>test</scope>
188169
</dependency>
@@ -193,9 +174,9 @@
193174
<scope>test</scope>
194175
</dependency>
195176
<dependency>
196-
<groupId>commons-fileupload</groupId>
197-
<artifactId>commons-fileupload</artifactId>
198-
<version>1.6.0</version>
177+
<groupId>org.apache.commons</groupId>
178+
<artifactId>commons-fileupload2-jakarta-servlet6</artifactId>
179+
<version>2.0.0-M4</version>
199180
<scope>test</scope>
200181
</dependency>
201182
</dependencies>
@@ -533,12 +514,14 @@
533514
</profiles>
534515

535516
<properties>
536-
<grizzly.version>2.4.4</grizzly.version>
517+
<grizzly.version>4.0.2</grizzly.version>
537518
<maven.compiler.source>1.8</maven.compiler.source>
538519
<maven.compiler.target>1.8</maven.compiler.target>
539520
<maven.compiler.release>8</maven.compiler.release>
540521
<surefire.version>3.5.4</surefire.version>
541-
<jetty.version>9.4.46.v20220331</jetty.version>
522+
<jetty.version>12.1.2</jetty.version>
523+
<slf4j.version>2.0.17</slf4j.version>
524+
<log4j.version>2.25.2</log4j.version>
542525
</properties>
543526
</project>
544527

src/test/java/com/ning/http/client/async/AbstractBasicTest.java

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
23
* Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
34
* Copyright 2010 Ning, Inc.
45
*
@@ -26,24 +27,28 @@
2627
import com.ning.http.client.HttpResponseStatus;
2728
import com.ning.http.client.Response;
2829

30+
import org.eclipse.jetty.http.HttpCookie;
31+
import org.eclipse.jetty.http.HttpField;
32+
import org.eclipse.jetty.http.HttpFields;
33+
import org.eclipse.jetty.http.HttpHeader;
34+
import org.eclipse.jetty.http.HttpStatus;
35+
import org.eclipse.jetty.io.Content;
36+
import org.eclipse.jetty.server.Handler;
2937
import org.eclipse.jetty.server.ServerConnector;
3038
import org.eclipse.jetty.server.Request;
3139
import org.eclipse.jetty.server.Server;
32-
import org.eclipse.jetty.server.handler.AbstractHandler;
33-
import org.eclipse.jetty.server.handler.HandlerWrapper;
40+
import org.eclipse.jetty.util.Callback;
41+
import org.eclipse.jetty.util.Fields;
3442
import org.slf4j.Logger;
3543
import org.slf4j.LoggerFactory;
3644
import org.testng.Assert;
3745
import org.testng.annotations.AfterClass;
3846
import org.testng.annotations.BeforeClass;
3947

40-
import javax.servlet.ServletException;
41-
import javax.servlet.http.HttpServletRequest;
42-
import javax.servlet.http.HttpServletResponse;
43-
4448
import java.io.IOException;
49+
import java.io.InputStream;
4550
import java.net.ServerSocket;
46-
import java.util.Enumeration;
51+
import java.util.List;
4752

4853
public abstract class AbstractBasicTest {
4954

@@ -56,33 +61,32 @@ public abstract class AbstractBasicTest {
5661

5762
public final static int TIMEOUT = 30;
5863

59-
public static class EchoHandler extends HandlerWrapper {
64+
public static class EchoHandler extends Handler.Abstract {
6065

6166
@Override
62-
public void handle(String pathInContext,
63-
Request request,
64-
HttpServletRequest httpRequest,
65-
HttpServletResponse httpResponse) throws IOException, ServletException {
67+
public boolean handle(org.eclipse.jetty.server.Request request, org.eclipse.jetty.server.Response response,
68+
Callback callback) throws Exception {
69+
70+
final HttpFields requestHeaders = request.getHeaders();
71+
final HttpFields.Mutable responseHeaders = response.getHeaders();
6672

67-
if (httpRequest.getHeader("X-HEAD") != null) {
68-
httpResponse.setContentLength(1);
73+
if (requestHeaders.get("X-HEAD") != null) {
74+
responseHeaders.put(HttpHeader.CONTENT_LENGTH, 1L);
6975
}
7076

71-
if (httpRequest.getHeader("X-ISO") != null) {
72-
httpResponse.setContentType("text/html; charset=ISO-8859-1");
77+
if (requestHeaders.get("X-ISO") != null) {
78+
responseHeaders.put(HttpHeader.CONTENT_TYPE, "text/html; charset=ISO-8859-1");
7379
} else {
74-
httpResponse.setContentType(TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET);
80+
responseHeaders.put(HttpHeader.CONTENT_TYPE, TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET);
7581
}
7682

7783
if (request.getMethod().equalsIgnoreCase("OPTIONS")) {
78-
httpResponse.addHeader("Allow","GET,HEAD,POST,OPTIONS,TRACE");
79-
};
84+
responseHeaders.put(HttpHeader.ALLOW, "GET,HEAD,POST,OPTIONS,TRACE");
85+
}
8086

81-
Enumeration<?> e = httpRequest.getHeaderNames();
8287
String param;
83-
while (e.hasMoreElements()) {
84-
param = e.nextElement().toString();
85-
88+
for (final HttpField httpField: requestHeaders) {
89+
param = httpField.getName();
8690
if (param.startsWith("LockThread")) {
8791
try {
8892
Thread.sleep(40 * 1000);
@@ -91,65 +95,67 @@ public void handle(String pathInContext,
9195
}
9296

9397
if (param.startsWith("X-redirect")) {
94-
httpResponse.sendRedirect(httpRequest.getHeader("X-redirect"));
95-
return;
98+
org.eclipse.jetty.server.Response.sendRedirect(request, response, callback, httpField.getValue());
99+
callback.succeeded();
100+
return true;
96101
}
97102
if (param.startsWith("Y-")) {
98-
httpResponse.addHeader(param.substring(2), httpRequest.getHeader(param));
103+
responseHeaders.put(param.substring(2), httpField.getValue());
99104
} else {
100-
httpResponse.addHeader("X-" + param, httpRequest.getHeader(param));
105+
responseHeaders.put("X-" + param, httpField.getValue());
101106
}
102107
}
103108

104-
Enumeration<?> i = httpRequest.getParameterNames();
105-
106-
StringBuilder requestBody = new StringBuilder();
107-
while (i.hasMoreElements()) {
108-
param = i.nextElement().toString();
109-
httpResponse.addHeader("X-" + param, httpRequest.getParameter(param));
109+
final StringBuilder requestBody = new StringBuilder();
110+
final Fields allParameters = Request.getParameters(request);
111+
for (final Fields.Field field: allParameters) {
112+
param = field.getName();
113+
responseHeaders.put("X-" + param, field.getValue());
110114
requestBody.append(param);
111115
requestBody.append("_");
112116
}
113117

114-
String pathInfo = httpRequest.getPathInfo();
118+
final String pathInfo = Request.getPathInContext(request);
115119
if (pathInfo != null)
116-
httpResponse.addHeader("X-pathInfo", pathInfo);
120+
responseHeaders.put("X-pathInfo", pathInfo);
117121

118-
String queryString = httpRequest.getQueryString();
122+
final String queryString = request.getHttpURI().getQuery();
119123
if (queryString != null)
120-
httpResponse.addHeader("X-queryString", queryString);
124+
responseHeaders.put("X-queryString", queryString);
121125

122-
httpResponse.addHeader("X-KEEP-ALIVE", httpRequest.getRemoteAddr() + ":" + httpRequest.getRemotePort());
126+
responseHeaders.put("X-KEEP-ALIVE", Request.getRemoteAddr(request) + ":" + Request.getRemotePort(request));
123127

124-
javax.servlet.http.Cookie[] cs = httpRequest.getCookies();
125-
if (cs != null) {
126-
for (javax.servlet.http.Cookie c : cs) {
127-
httpResponse.addCookie(c);
128-
}
128+
final List<HttpCookie> cookies = Request.getCookies(request);
129+
for (final HttpCookie cookie: cookies) {
130+
org.eclipse.jetty.server.Response.addCookie(response, cookie);
129131
}
130132

131133
if (requestBody.length() > 0) {
132-
httpResponse.getOutputStream().write(requestBody.toString().getBytes());
134+
Content.Sink.asOutputStream(response).write(requestBody.toString().getBytes());
133135
}
134136

135137
int size = 16384;
136-
if (httpRequest.getContentLength() > 0) {
137-
size = httpRequest.getContentLength();
138+
if (request.getLength() > 0) {
139+
size = (int) request.getLength();
138140
}
139141
byte[] bytes = new byte[size];
140142
if (bytes.length > 0) {
141143
int read = 0;
142-
while (read > -1) {
143-
read = httpRequest.getInputStream().read(bytes);
144-
if (read > 0) {
145-
httpResponse.getOutputStream().write(bytes, 0, read);
144+
try (final InputStream in = Content.Source.asInputStream(request)) {
145+
while (read > -1) {
146+
read = in.read(bytes);
147+
if (read > 0) {
148+
Content.Sink.asOutputStream(response).write(bytes, 0, read);
149+
}
146150
}
147151
}
148152
}
149153

150-
httpResponse.setStatus(200);
151-
httpResponse.getOutputStream().flush();
152-
httpResponse.getOutputStream().close();
154+
response.setStatus(HttpStatus.OK_200);
155+
Content.Sink.asOutputStream(response).flush();
156+
Content.Sink.asOutputStream(response).close();
157+
callback.succeeded();
158+
return true;
153159
}
154160
}
155161

@@ -173,7 +179,7 @@ protected String getTargetUrl2() {
173179
return String.format("https://127.0.0.1:%d/foo/test", port2);
174180
}
175181

176-
public AbstractHandler configureHandler() throws Exception {
182+
public Handler.Abstract configureHandler() throws Exception {
177183
return new EchoHandler();
178184
}
179185

src/test/java/com/ning/http/client/async/AsyncProvidersBasicTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
import java.util.concurrent.atomic.AtomicReference;
7171

7272
public abstract class AsyncProvidersBasicTest extends AbstractBasicTest {
73-
private static final String TEXT_HTML_UTF_8 = "text/html;charset=utf-8";
73+
private static final String TEXT_HTML_UTF_8 = "text/html; charset=utf-8";
7474

7575
@Test(groups = { "standalone", "default_provider", "async" })
7676
public void asyncProviderEncodingTest() throws Throwable {

src/test/java/com/ning/http/client/async/AsyncStreamHandlerTest.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@
4545

4646
public abstract class AsyncStreamHandlerTest extends AbstractBasicTest {
4747
private final static String RESPONSE = "param_1_";
48-
49-
private String jetty8ContentTypeMadness(String saneValue) {
50-
return saneValue.replace(" ", "");
51-
}
5248

5349
@Test(groups = { "standalone", "default_provider" })
5450
public void asyncStreamGETTest() throws Exception {
@@ -84,7 +80,7 @@ public void onThrowable(Throwable t) {
8480

8581
FluentCaseInsensitiveStringsMap h = responseHeaders.get();
8682
assertNotNull(h, "No response headers");
87-
assertEquals(h.getJoinedValue("content-type", ","), jetty8ContentTypeMadness(TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET), "Unexpected content-type");
83+
assertEquals(h.getJoinedValue("content-type", ","), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET, "Unexpected content-type");
8884
assertNull(throwable.get(), "Unexpected exception");
8985
}
9086
}
@@ -122,7 +118,7 @@ public String onCompleted() throws Exception {
122118
String responseBody = f.get(10, TimeUnit.SECONDS);
123119
FluentCaseInsensitiveStringsMap h = responseHeaders.get();
124120
assertNotNull(h);
125-
assertEquals(h.getJoinedValue("content-type", ","), jetty8ContentTypeMadness(TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET));
121+
assertEquals(h.getJoinedValue("content-type", ","), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET);
126122
assertEquals(responseBody, RESPONSE);
127123
}
128124
}
@@ -163,7 +159,7 @@ public void onThrowable(Throwable t) {
163159
assertTrue(!bodyReceived.get(), "Interrupted not working");
164160
FluentCaseInsensitiveStringsMap h = responseHeaders.get();
165161
assertNotNull(h, "Should receive non null headers");
166-
assertEquals(h.getJoinedValue("content-type", ", "), jetty8ContentTypeMadness(TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET), "Unexpected content-type");
162+
assertEquals(h.getJoinedValue("content-type", ", "), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET, "Unexpected content-type");
167163
assertNull(throwable.get(), "Should get an exception");
168164
}
169165
}
@@ -202,7 +198,7 @@ public void onThrowable(Throwable t) {
202198
String responseBody = f.get(5, TimeUnit.SECONDS);
203199
FluentCaseInsensitiveStringsMap h = responseHeaders.get();
204200
assertNotNull(h, "Should receive non null headers");
205-
assertEquals(h.getJoinedValue("content-type", ", "), jetty8ContentTypeMadness(TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET), "Unexpected content-type");
201+
assertEquals(h.getJoinedValue("content-type", ", "), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET, "Unexpected content-type");
206202
assertNotNull(responseBody, "No response body");
207203
assertEquals(responseBody.trim(), RESPONSE, "Unexpected response body");
208204
assertNull(throwable.get(), "Unexpected exception");
@@ -272,7 +268,7 @@ public String onCompleted() throws Exception {
272268
String r = f.get(5, TimeUnit.SECONDS);
273269
FluentCaseInsensitiveStringsMap h = responseHeaders.get();
274270
assertNotNull(h, "Should receive non null headers");
275-
assertEquals(h.getJoinedValue("content-type", ", "), jetty8ContentTypeMadness(TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET), "Unexpected content-type");
271+
assertEquals(h.getJoinedValue("content-type", ", "), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET, "Unexpected content-type");
276272
assertNotNull(r, "No response body");
277273
assertEquals(r.trim(), RESPONSE, "Unexpected response body");
278274

@@ -303,7 +299,7 @@ public String onCompleted() throws Exception {
303299
f.get(5, TimeUnit.SECONDS);
304300
h = responseHeaders.get();
305301
assertNotNull(h, "Should receive non null headers");
306-
assertEquals(h.getJoinedValue("content-type", ", "), jetty8ContentTypeMadness(TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET), "Unexpected content-type");
302+
assertEquals(h.getJoinedValue("content-type", ", "), TEXT_HTML_CONTENT_TYPE_WITH_UTF_8_CHARSET, "Unexpected content-type");
307303
assertNotNull(r, "No response body");
308304
assertEquals(r.trim(), RESPONSE, "Unexpected response body");
309305
}

0 commit comments

Comments
 (0)