Skip to content

Commit 32d3ee7

Browse files
author
Luca Di Grazia
committed
Restore and deprecate NonblockingServletHolder
1 parent af6ccf1 commit 32d3ee7

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

dataset/GitHub_Java/dropwizard.dropwizard/dropwizard-jetty/src/main/java/io/dropwizard/jetty/NonblockingServletHolder.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.dropwizard.jetty;
22

3+
import org.eclipse.jetty.io.EofException;
34
import org.eclipse.jetty.server.Request;
45
import org.eclipse.jetty.servlet.ServletHolder;
56

@@ -12,7 +13,12 @@
1213
/**
1314
* A {@link ServletHolder} subclass which removes the synchronization around servlet initialization
1415
* by requiring a pre-initialized servlet holder.
16+
*
17+
* @deprecated If necessary, use {@link ServletHolder} or {@link org.eclipse.jetty.servlet.FilterHolder} directly.
18+
* This class will be removed in Dropwizard 2.1.0.
1519
*/
20+
@SuppressWarnings("unused")
21+
@Deprecated
1622
public class NonblockingServletHolder extends ServletHolder {
1723
private final Servlet servlet;
1824

@@ -47,6 +53,11 @@ public void handle(Request baseRequest,
4753
}
4854
try {
4955
servlet.service(request, response);
56+
} catch (EofException ignored) {
57+
// Want to ignore the EofException as this signifies the client has disconnected or the
58+
// response has already been written. The problem with using an ExceptionMapper is that
59+
// we don't actually want to write a response given that the connection has already been
60+
// closed
5061
} finally {
5162
baseRequest.setAsyncSupported(asyncSupported, null);
5263
}

dataset/GitHub_Java/dropwizard.dropwizard/dropwizard-jetty/src/test/java/io/dropwizard/jetty/NonblockingServletHolderTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ public class NonblockingServletHolderTest {
2828
private final ServletResponse response = mock(ServletResponse.class);
2929

3030
@Test
31-
void hasAServlet() throws Exception {
31+
public void hasAServlet() throws Exception {
3232
assertThat(holder.getServlet())
3333
.isEqualTo(servlet);
3434
}
3535

3636
@Test
37-
void servicesRequests() throws Exception {
37+
public void servicesRequests() throws Exception {
3838
holder.handle(baseRequest, request, response);
3939

4040
verify(servlet).service(request, response);
4141
}
4242

4343
@Test
44-
void servicesRequestHandleEofException() throws Exception {
44+
public void servicesRequestHandleEofException() throws Exception {
4545
doThrow(new EofException()).when(servlet).service(eq(request), eq(response));
4646
assertThatCode(() -> {
4747
holder.handle(baseRequest, request, response);
@@ -50,15 +50,15 @@ void servicesRequestHandleEofException() throws Exception {
5050
}
5151

5252
@Test
53-
void servicesRequestException() throws Exception {
53+
public void servicesRequestException() throws Exception {
5454
doThrow(new IOException()).when(servlet).service(eq(request), eq(response));
5555
assertThatExceptionOfType(IOException.class).isThrownBy(() -> {
5656
holder.handle(baseRequest, request, response);
5757
});
5858
}
5959

6060
@Test
61-
void temporarilyDisablesAsyncRequestsIfDisabled() throws Exception {
61+
public void temporarilyDisablesAsyncRequestsIfDisabled() throws Exception {
6262
holder.setAsyncSupported(false);
6363

6464
holder.handle(baseRequest, request, response);
@@ -70,7 +70,7 @@ void temporarilyDisablesAsyncRequestsIfDisabled() throws Exception {
7070
}
7171

7272
@Test
73-
void isEagerlyInitialized() throws Exception {
73+
public void isEagerlyInitialized() throws Exception {
7474
assertThat(holder.getInitOrder())
7575
.isEqualTo(1);
7676
}

0 commit comments

Comments
 (0)