Skip to content

Commit 8c6b002

Browse files
committed
Add basic support for servlet 4.0
1 parent ffc4bbc commit 8c6b002

File tree

6 files changed

+137
-51
lines changed

6 files changed

+137
-51
lines changed

History.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
## 1.3.0 (UNRELEASED)
22

3+
- Require Java 11 or later
4+
- Support Javax Servlet API 4.0 (JEE 8)
35
- Adds basic compatibility with JRuby 10.0
6+
- Drop support for JRuby 9.3
47
- Drop unnecessary jruby.compat.version and RackConfig.getCompatVersion() API
58
- Drop JMS support
6-
- Drop support for JRuby 9.3
7-
- Require Java 11 or later
89
- update (bundled) rack to 2.2.17
910

1011
## 1.2.4 (UNRELEASED)

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<jruby.maven.plugins.version>3.0.6</jruby.maven.plugins.version>
2424
<gem.home>${project.build.directory}/rubygems</gem.home>
2525
<slf4j.version>2.0.17</slf4j.version>
26-
<spring.version>4.3.30.RELEASE</spring.version>
26+
<spring.version>5.3.39</spring.version>
2727
</properties>
2828

2929
<issueManagement>
@@ -99,9 +99,9 @@
9999
<scope>provided</scope>
100100
</dependency>
101101
<dependency>
102-
<groupId>javax.servlet</groupId>
103-
<artifactId>javax.servlet-api</artifactId>
104-
<version>3.0.1</version>
102+
<groupId>jakarta.servlet</groupId>
103+
<artifactId>jakarta.servlet-api</artifactId>
104+
<version>4.0.4</version>
105105
<scope>provided</scope>
106106
</dependency>
107107
<dependency>

src/main/java/org/jruby/rack/servlet/DefaultServletRackContext.java

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -270,57 +270,97 @@ public void declareRoles(String... roleNames) {
270270
context.declareRoles(roleNames);
271271
}
272272

273+
@Override
274+
public String getVirtualServerName() {
275+
return context.getVirtualServerName();
276+
}
277+
278+
@Override
279+
public int getSessionTimeout() {
280+
return context.getSessionTimeout();
281+
}
282+
283+
@Override
284+
public void setSessionTimeout(int sessionTimeout) {
285+
context.setSessionTimeout(sessionTimeout);
286+
}
287+
288+
@Override
289+
public String getRequestCharacterEncoding() {
290+
return context.getRequestCharacterEncoding();
291+
}
292+
293+
@Override
294+
public void setRequestCharacterEncoding(String encoding) {
295+
context.setRequestCharacterEncoding(encoding);
296+
}
297+
298+
@Override
299+
public String getResponseCharacterEncoding() {
300+
return context.getResponseCharacterEncoding();
301+
}
302+
303+
@Override
304+
public void setResponseCharacterEncoding(String encoding) {
305+
context.setResponseCharacterEncoding(encoding);
306+
}
307+
273308
@Override
274309
public <T extends Servlet> T createServlet(Class<T> type) throws ServletException {
275310
return context.createServlet(type);
276311
}
277312

278-
@Override // 3.0 in method signature
313+
@Override
279314
public ServletRegistration.Dynamic addServlet(String servletName, String className) throws IllegalArgumentException, IllegalStateException {
280315
return context.addServlet(servletName, className);
281316
}
282317

283-
@Override // 3.0 in method signature
318+
@Override
284319
public ServletRegistration.Dynamic addServlet(String servletName, Servlet servlet) throws IllegalArgumentException, IllegalStateException {
285320
return context.addServlet(servletName, servlet);
286321
}
287322

288-
@Override // 3.0 in method signature
323+
@Override
289324
public ServletRegistration.Dynamic addServlet(String servletName, Class<? extends Servlet> servletClass) throws IllegalArgumentException, IllegalStateException {
290325
return context.addServlet(servletName, servletClass);
291326
}
292327

293-
@Override // 3.0 in method signature
328+
@Override
329+
public ServletRegistration.Dynamic addJspFile(String servletName, String jspFile) {
330+
return context.addJspFile(servletName, jspFile);
331+
}
332+
333+
@Override
294334
public ServletRegistration getServletRegistration(String servletName) {
295335
return context.getServletRegistration(servletName);
296336
}
297337

298-
@Override // 3.0 in method signature
338+
@Override
299339
public Map<String, ? extends ServletRegistration> getServletRegistrations() {
300340
return context.getServletRegistrations();
301341
}
302342

303-
@Override // 3.0 in method signature
343+
@Override
304344
public <T extends Filter> T createFilter(Class<T> type) throws ServletException {
305345
return context.createFilter(type);
306346
}
307347

308-
@Override // 3.0 in method signature
348+
@Override
309349
public FilterRegistration.Dynamic addFilter(String filterName, String className) throws IllegalArgumentException, IllegalStateException {
310350
return context.addFilter(filterName, className);
311351
}
312352

313-
@Override // 3.0 in method signature
353+
@Override
314354
public FilterRegistration.Dynamic addFilter(String filterName, Filter filter) throws IllegalArgumentException, IllegalStateException {
315355
return context.addFilter(filterName, filter);
316356
}
317357

318-
@Override // 3.0 in method signature
358+
@Override
319359
public FilterRegistration.Dynamic addFilter(String filterName, Class<? extends Filter> filterClass) throws IllegalArgumentException, IllegalStateException {
320360
return context.addFilter(filterName, filterClass);
321361
}
322362

323-
@Override // 3.0 in method signature
363+
@Override
324364
public FilterRegistration getFilterRegistration(String filterName) {
325365
return context.getFilterRegistration(filterName);
326366
}
@@ -350,7 +390,7 @@ public <T extends EventListener> T createListener(Class<T> listenerClass) throws
350390
return context.createListener(listenerClass);
351391
}
352392

353-
@Override // 3.0 in method signature
393+
@Override
354394
public SessionCookieConfig getSessionCookieConfig() {
355395
return context.getSessionCookieConfig();
356396
}
@@ -370,7 +410,7 @@ public Set<SessionTrackingMode> getEffectiveSessionTrackingModes() {
370410
return context.getEffectiveSessionTrackingModes();
371411
}
372412

373-
@Override // 3.0 in method signature
413+
@Override
374414
public JspConfigDescriptor getJspConfigDescriptor() {
375415
return context.getJspConfigDescriptor();
376416
}

src/main/java/org/jruby/rack/servlet/ResponseCapture.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.Set;
2020

2121
import javax.servlet.ServletOutputStream;
22+
import javax.servlet.WriteListener;
2223
import javax.servlet.http.HttpServletRequest;
2324
import javax.servlet.http.HttpServletResponse;
2425
import javax.servlet.http.HttpServletResponseWrapper;
@@ -166,7 +167,17 @@ public ServletOutputStream getOutputStream() throws IOException {
166167
// backwards compatibility with isError() :
167168
return new ServletOutputStream() {
168169
@Override
169-
public void write(int b) throws IOException {
170+
public boolean isReady() {
171+
return true;
172+
}
173+
174+
@Override
175+
public void setWriteListener(WriteListener writeListener) {
176+
// swallow listeners, as we're also going to swallow output
177+
}
178+
179+
@Override
180+
public void write(int b) {
170181
// swallow output, because we're going to discard it
171182
}
172183
};

src/main/java/org/jruby/rack/servlet/RewindableInputStream.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.io.RandomAccessFile;
1414
import java.nio.ByteBuffer;
1515

16+
import javax.servlet.ReadListener;
1617
import javax.servlet.ServletInputStream;
1718

1819
/**
@@ -401,5 +402,27 @@ public int getCurrentBufferSize() {
401402
public int getMaximumBufferSize() {
402403
return bufferMax;
403404
}
404-
405+
406+
@Override
407+
public boolean isFinished() {
408+
try {
409+
return input.available() <= 0;
410+
} catch (IOException e) {
411+
throw new RuntimeException(e);
412+
}
413+
}
414+
415+
@Override
416+
public boolean isReady() {
417+
try {
418+
return input.available() >= 0;
419+
} catch (IOException e) {
420+
throw new RuntimeException(e);
421+
}
422+
}
423+
424+
@Override
425+
public void setReadListener(ReadListener readListener) {
426+
throw new UnsupportedOperationException("readListener not supported");
427+
}
405428
}

src/main/java/org/jruby/rack/servlet/ServletRackIncludedResponse.java

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import javax.servlet.ServletOutputStream;
1818
import javax.servlet.ServletResponse;
19+
import javax.servlet.WriteListener;
1920
import javax.servlet.http.HttpServletResponse;
2021
import javax.servlet.http.HttpServletResponseWrapper;
2122

@@ -158,7 +159,7 @@ private void initializeOutputStream() {
158159
*/
159160
private static class ByteArrayServletOutputStream extends ServletOutputStream {
160161

161-
private final static String LINE_SEPARATOR = System.getProperty("line.separator");
162+
private final static String LINE_SEPARATOR = System.lineSeparator();
162163
private final DataOutputStream dataOutputStream;
163164
private final String charSet;
164165

@@ -169,23 +170,33 @@ public ByteArrayServletOutputStream(ByteArrayOutputStream byteOutputStream, Stri
169170
}
170171

171172
@Override
172-
public void print(boolean b) throws IOException {
173-
dataOutputStream.writeBoolean(b);
173+
public void write(byte[] b, int off, int len) throws IOException {
174+
dataOutputStream.write(b, off, len);
174175
}
175176

176177
@Override
177-
public void print(char c) throws IOException {
178-
dataOutputStream.writeChar(c);
178+
public void write(byte[] b) throws IOException {
179+
dataOutputStream.write(b);
179180
}
180181

181182
@Override
182-
public void print(double d) throws IOException {
183-
dataOutputStream.writeDouble(d);
183+
public void write(int i) throws IOException {
184+
dataOutputStream.write(i);
184185
}
185186

186187
@Override
187-
public void print(float f) throws IOException {
188-
dataOutputStream.writeFloat(f);
188+
public void print(String s) throws IOException {
189+
dataOutputStream.write(s.getBytes(charSet));
190+
}
191+
192+
@Override
193+
public void print(boolean b) throws IOException {
194+
dataOutputStream.writeBoolean(b);
195+
}
196+
197+
@Override
198+
public void print(char c) throws IOException {
199+
dataOutputStream.writeChar(c);
189200
}
190201

191202
@Override
@@ -199,36 +210,34 @@ public void print(long l) throws IOException {
199210
}
200211

201212
@Override
202-
public void print(String s) throws IOException {
203-
dataOutputStream.write(s.getBytes(charSet));
213+
public void print(float f) throws IOException {
214+
dataOutputStream.writeFloat(f);
204215
}
205216

206217
@Override
207-
public void println() throws IOException {
208-
dataOutputStream.write(LINE_SEPARATOR.getBytes(charSet));
218+
public void print(double d) throws IOException {
219+
dataOutputStream.writeDouble(d);
209220
}
210221

211222
@Override
212-
public void println(boolean b) throws IOException {
213-
print(b);
214-
println();
223+
public void println() throws IOException {
224+
dataOutputStream.write(LINE_SEPARATOR.getBytes(charSet));
215225
}
216226

217227
@Override
218-
public void println(char c) throws IOException {
219-
print(c);
220-
println();
228+
public void println(String s) throws IOException {
229+
print(s);
221230
}
222231

223232
@Override
224-
public void println(double d) throws IOException {
225-
print(d);
233+
public void println(boolean b) throws IOException {
234+
print(b);
226235
println();
227236
}
228237

229238
@Override
230-
public void println(float f) throws IOException {
231-
print(f);
239+
public void println(char c) throws IOException {
240+
print(c);
232241
println();
233242
}
234243

@@ -245,23 +254,25 @@ public void println(long l) throws IOException {
245254
}
246255

247256
@Override
248-
public void println(String s) throws IOException {
249-
print(s);
257+
public void println(float f) throws IOException {
258+
print(f);
259+
println();
250260
}
251261

252262
@Override
253-
public void write(byte[] b, int off, int len) throws IOException {
254-
dataOutputStream.write(b, off, len);
263+
public void println(double d) throws IOException {
264+
print(d);
265+
println();
255266
}
256267

257268
@Override
258-
public void write(byte[] b) throws IOException {
259-
dataOutputStream.write(b);
269+
public boolean isReady() {
270+
return true;
260271
}
261272

262273
@Override
263-
public void write(int i) throws IOException {
264-
dataOutputStream.write(i);
274+
public void setWriteListener(WriteListener writeListener) {
275+
throw new UnsupportedOperationException("writeListener not supported");
265276
}
266277
}
267278
}

0 commit comments

Comments
 (0)