Skip to content

Commit 416202c

Browse files
committed
FELIX-6750-Jetty-12.1.0-tryout
- Fix merge - Move to EE11 for ErrorHandler - Use try with resources
1 parent 8e47a8f commit 416202c

7 files changed

Lines changed: 74 additions & 95 deletions

File tree

http/jetty12/src/main/java/org/apache/felix/http/jetty/internal/JettyErrorHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import java.util.Map;
2020

21-
import org.eclipse.jetty.ee10.servlet.ErrorHandler;
21+
import org.eclipse.jetty.ee11.servlet.ErrorHandler;
2222
import org.eclipse.jetty.http.HttpFields.Mutable;
2323
import org.eclipse.jetty.server.Request;
2424
import org.eclipse.jetty.server.Response;

http/jetty12/src/test/java/org/apache/felix/http/jetty/it/JettyMaxFormSizeIT.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,26 @@ public void setup(){
9595
@Test
9696
public void testFormSizeLimit() throws Exception {
9797
HttpClientTransportOverHTTP transport = new HttpClientTransportOverHTTP();
98-
HttpClient httpClient = new HttpClient(transport);
99-
httpClient.start();
98+
try (HttpClient httpClient = new HttpClient(transport)) {
99+
Object value = bundleContext.getServiceReference(HttpService.class).getProperty("org.osgi.service.http.port");
100+
int httpPort = Integer.parseInt((String) value);
100101

101-
Object value = bundleContext.getServiceReference(HttpService.class).getProperty("org.osgi.service.http.port");
102-
int httpPort = Integer.parseInt((String) value);
102+
URI uri = new URI(String.format("http://localhost:%d/endpoint", httpPort));
103103

104-
URI uri = new URI(String.format("http://localhost:%d/endpoint", httpPort));
104+
Fields formFields = new Fields();
105+
formFields.add(new Fields.Field("key", "value")); // under 10 bytes
106+
ContentResponse response = httpClient.FORM(uri, formFields);
105107

106-
Fields formFields = new Fields();
107-
formFields.add(new Fields.Field("key", "value")); // under 10 bytes
108-
ContentResponse response = httpClient.FORM(uri, formFields);
108+
assertEquals(200, response.getStatus());
109+
assertEquals("OK", response.getContentAsString());
109110

110-
assertEquals(200, response.getStatus());
111-
assertEquals("OK", response.getContentAsString());
111+
Fields formFieldsLimitExceeded = new Fields();
112+
formFieldsLimitExceeded.add(new Fields.Field("key", "valueoverlimit")); // over limit of 10 bytes
113+
ContentResponse responseExceeded = httpClient.FORM(uri, formFieldsLimitExceeded);
112114

113-
Fields formFieldsLimitExceeded = new Fields();
114-
formFieldsLimitExceeded.add(new Fields.Field("key", "valueoverlimit")); // over limit of 10 bytes
115-
ContentResponse responseExceeded = httpClient.FORM(uri, formFieldsLimitExceeded);
116-
117-
// HTTP 500 thrown, because req.getParameter("key") throws an IOException
118-
assertEquals(500, responseExceeded.getStatus());
119-
120-
httpClient.close();
115+
// HTTP 500 thrown, because req.getParameter("key") throws an IOException
116+
assertEquals(500, responseExceeded.getStatus());
117+
}
121118
}
122119

123120
static final class HelloWorldServlet extends HttpServlet {

http/jetty12/src/test/java/org/apache/felix/http/jetty/it/JettySizeLimitHandlerIT.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -98,33 +98,31 @@ public void setup(){
9898
@Test
9999
public void testRequestResponseLimits() throws Exception {
100100
HttpClientTransportOverHTTP transport = new HttpClientTransportOverHTTP();
101-
HttpClient httpClient = new HttpClient(transport);
102-
httpClient.start();
101+
try (HttpClient httpClient = new HttpClient(transport)) {
102+
Object value = bundleContext.getServiceReference(HttpService.class).getProperty("org.osgi.service.http.port");
103+
int httpPort = Integer.parseInt((String) value);
103104

104-
Object value = bundleContext.getServiceReference(HttpService.class).getProperty("org.osgi.service.http.port");
105-
int httpPort = Integer.parseInt((String) value);
105+
Fields formFields = new Fields();
106+
formFields.add(new Fields.Field("key","value")); // under 10 bytes
107+
ContentResponse responseWithinLimit = httpClient.FORM(new URI(String.format("http://localhost:%d/withinlimit/a", httpPort)), formFields);
106108

107-
Fields formFields = new Fields();
108-
formFields.add(new Fields.Field("key", "value")); // under 10 bytes
109-
ContentResponse responseWithinLimit = httpClient.FORM(new URI(String.format("http://localhost:%d/withinlimit/a", httpPort)), formFields);
109+
// Request limit ok, response limit ok
110+
assertEquals(200, responseWithinLimit.getStatus());
111+
assertEquals("OK", responseWithinLimit.getContentAsString());
110112

111-
// Request limit ok, response limit ok
112-
assertEquals(200, responseWithinLimit.getStatus());
113-
assertEquals("OK", responseWithinLimit.getContentAsString());
113+
// Request limit ok, response limit exceeded
114+
// org.eclipse.jetty.http.HttpException$RuntimeException: 500: Response body is too large: 17>10
115+
ContentResponse responseExceedingLimit = httpClient.FORM(new URI(String.format("http://localhost:%d/exceedinglimit/a", httpPort)), formFields);
114116

115-
// Request limit ok, response limit exceeded
116-
// org.eclipse.jetty.http.HttpException$RuntimeException: 500: Response body is too large: 17>10
117-
ContentResponse responseExceedingLimit = httpClient.FORM(new URI(String.format("http://localhost:%d/exceedinglimit/a", httpPort)), formFields);
118-
assertEquals(500, responseExceedingLimit.getStatus());
117+
assertEquals(500, responseExceedingLimit.getStatus());
119118

120-
Fields formFieldsLimitExceeded = new Fields();
121-
formFieldsLimitExceeded.add(new Fields.Field("key", "valueoverlimit")); // over limit of 10 bytes
122-
ContentResponse responseExceeded = httpClient.FORM(new URI(String.format("http://localhost:%d/withinlimit/a", httpPort)), formFieldsLimitExceeded);
119+
Fields formFieldsLimitExceeded = new Fields();
120+
formFieldsLimitExceeded.add(new Fields.Field("key","valueoverlimit")); // over limit of 10 bytes
121+
ContentResponse responseExceeded = httpClient.FORM(new URI(String.format("http://localhost:%d/withinlimit/a", httpPort)), formFieldsLimitExceeded);
123122

124-
// Request limit exceeded, HTTP 413 directly from Jetty
125-
assertEquals(413, responseExceeded.getStatus());
126-
127-
httpClient.close();
123+
// Request limit exceeded, HTTP 413 directly from Jetty
124+
assertEquals(413, responseExceeded.getStatus());
125+
}
128126
}
129127

130128
static final class HelloWorldServletWithinLimit extends HttpServlet {

http/jetty12/src/test/java/org/apache/felix/http/jetty/it/JettyUriComplianceModeDefaultIT.java

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,32 +92,29 @@ public void setup(){
9292
@Test
9393
public void testUriCompliance() throws Exception {
9494
HttpClientTransportOverHTTP transport = new HttpClientTransportOverHTTP();
95-
HttpClient httpClient = new HttpClient(transport);
96-
httpClient.start();
95+
try (HttpClient httpClient = new HttpClient(transport)) {
96+
Object value = bundleContext.getServiceReference(HttpService.class).getProperty("org.osgi.service.http.port");
97+
int httpPort = Integer.parseInt((String) value);
9798

98-
Object value = bundleContext.getServiceReference(HttpService.class).getProperty("org.osgi.service.http.port");
99-
int httpPort = Integer.parseInt((String) value);
99+
URI destUriWorking = new URI(String.format("http://localhost:%d/endpoint/working", httpPort));
100+
URI destUriAmbigousPath = new URI("http://localhost:" + httpPort + "/endpoint/ambigousPathitem_0_http%3A%2F%2Fwww.test.com%2F0.html/abc");
100101

101-
URI destUriWorking = new URI(String.format("http://localhost:%d/endpoint/working", httpPort));
102-
URI destUriAmbigousPath = new URI("http://localhost:" + httpPort + "/endpoint/ambigousPathitem_0_http%3A%2F%2Fwww.test.com%2F0.html/abc");
102+
ContentResponse response = httpClient.GET(destUriWorking);
103+
assertEquals(200, response.getStatus());
104+
assertEquals("OK", response.getContentAsString());
103105

104-
ContentResponse response = httpClient.GET(destUriWorking);
105-
assertEquals(200, response.getStatus());
106-
assertEquals("OK", response.getContentAsString());
106+
// Validate custom headers in case of success page, should not be present
107+
assertNull(response.getHeaders().get("Strict-Transport-Security"));
108+
assertNull(response.getHeaders().get("X-Custom-Header"));
107109

108-
// Validate custom headers in case of success page, should not be present
109-
assertNull(response.getHeaders().get("Strict-Transport-Security"));
110-
assertNull(response.getHeaders().get("X-Custom-Header"));
111110

112-
113-
// blocked with HTTP 400 by default
114-
// validate custom headers in case of error page
115-
ContentResponse responseAmbiguousPath = httpClient.GET(destUriAmbigousPath);
116-
assertEquals(400, responseAmbiguousPath.getStatus());
117-
assertEquals("max-age=31536000", responseAmbiguousPath.getHeaders().get("Strict-Transport-Security"));
118-
assertEquals("123", responseAmbiguousPath.getHeaders().get("X-Custom-Header"));
119-
120-
httpClient.close();
111+
// blocked with HTTP 400 by default
112+
// validate custom headers in case of error page
113+
ContentResponse responseAmbiguousPath = httpClient.GET(destUriAmbigousPath);
114+
assertEquals(400, responseAmbiguousPath.getStatus());
115+
assertEquals("max-age=31536000", responseAmbiguousPath.getHeaders().get("Strict-Transport-Security"));
116+
assertEquals("123", responseAmbiguousPath.getHeaders().get("X-Custom-Header"));
117+
}
121118
}
122119

123120
static final class UriComplianceEndpoint extends HttpServlet {

http/jetty12/src/test/java/org/apache/felix/http/jetty/it/JettyUriComplianceModeLegacyIT.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,21 @@ protected Option felixHttpConfig(int httpPort) {
6262
@Test
6363
public void testUriCompliance() throws Exception {
6464
HttpClientTransportOverHTTP transport = new HttpClientTransportOverHTTP();
65-
HttpClient httpClient = new HttpClient(transport);
66-
httpClient.start();
65+
try (HttpClient httpClient = new HttpClient(transport)) {
66+
Object value = bundleContext.getServiceReference(HttpService.class).getProperty("org.osgi.service.http.port");
67+
int httpPort = Integer.parseInt((String) value);
6768

68-
Object value = bundleContext.getServiceReference(HttpService.class).getProperty("org.osgi.service.http.port");
69-
int httpPort = Integer.parseInt((String) value);
69+
URI destUriWorking = new URI(String.format("http://localhost:%d/endpoint/working", httpPort));
70+
URI destUriAmbigousPath = new URI("http://localhost:" + httpPort + "/endpoint/ambigousPathitem_0_http%3A%2F%2Fwww.test.com%2F0.html/abc");
7071

71-
URI destUriWorking = new URI(String.format("http://localhost:%d/endpoint/working", httpPort));
72-
URI destUriAmbigousPath = new URI("http://localhost:" + httpPort + "/endpoint/ambigousPathitem_0_http%3A%2F%2Fwww.test.com%2F0.html/abc");
72+
ContentResponse response = httpClient.GET(destUriWorking);
73+
assertEquals(200, response.getStatus());
74+
assertEquals("OK", response.getContentAsString());
7375

74-
ContentResponse response = httpClient.GET(destUriWorking);
75-
assertEquals(200, response.getStatus());
76-
assertEquals("OK", response.getContentAsString());
77-
78-
// no longer blocked due to LEGACY compliance mode
79-
ContentResponse response2 = httpClient.GET(destUriAmbigousPath);
80-
assertEquals(200, response2.getStatus());
81-
assertEquals("OK", response2.getContentAsString());
82-
83-
httpClient.close();
76+
// no longer blocked due to LEGACY compliance mode
77+
ContentResponse response2 = httpClient.GET(destUriAmbigousPath);
78+
assertEquals(200, response2.getStatus());
79+
assertEquals("OK", response2.getContentAsString());
80+
}
8481
}
8582
}

http/jetty12/src/test/java/org/apache/felix/http/jetty/it/JettyVirtualThreadsIT.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,16 @@ public void testJettyRunningWithVirtualThreads() throws Exception {
9696
return;
9797
}
9898
HttpClientTransportOverHTTP transport = new HttpClientTransportOverHTTP();
99-
HttpClient httpClient = new HttpClient(transport);
100-
httpClient.start();
99+
try (HttpClient httpClient = new HttpClient(transport)) {
100+
Object value = bundleContext.getServiceReference(HttpService.class).getProperty("org.osgi.service.http.port");
101+
int httpPort = Integer.parseInt((String) value);
101102

102-
Object value = bundleContext.getServiceReference(HttpService.class).getProperty("org.osgi.service.http.port");
103-
int httpPort = Integer.parseInt((String) value);
103+
URI destUri = new URI(String.format("http://localhost:%d/endpoint/working", httpPort));
104104

105-
URI destUri = new URI(String.format("http://localhost:%d/endpoint/working", httpPort));
106-
107-
ContentResponse response = httpClient.GET(destUri);
108-
assertEquals(200, response.getStatus());
109-
assertEquals("OK", response.getContentAsString());
110-
111-
httpClient.close();
105+
ContentResponse response = httpClient.GET(destUri);
106+
assertEquals(200, response.getStatus());
107+
assertEquals("OK", response.getContentAsString());
108+
}
112109
}
113110

114111
static final class ExampleEndpoint extends HttpServlet {

http/wrappers/src/main/java/org/apache/felix/http/jakartawrappers/HttpServletResponseWrapper.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,6 @@ public void sendRedirect(String location, int sc) throws IOException {
8989
this.response.sendRedirect(location);
9090
}
9191

92-
@Override
93-
public void sendRedirect(String location, int sc, boolean clearBuffer) throws IOException {
94-
this.response.setStatus(sc);
95-
this.response.sendRedirect(location);
96-
this.response.flushBuffer();
97-
}
98-
9992
@Override
10093
public void setDateHeader(final String name, final long date) {
10194
this.response.setDateHeader(name, date);

0 commit comments

Comments
 (0)