package io.dropwizard.jetty;
import org.eclipse.jetty.io.EofException;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.servlet.ServletHolder;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
@SuppressWarnings("unused")
@Deprecated
public class NonblockingServletHolder extends ServletHolder {
private final Servlet servlet;
public NonblockingServletHolder(Servlet servlet) {
super(servlet);
setInitOrder(1);
this.servlet = servlet;
}
@Override
public boolean equals(Object o) {
return super.equals(o);
}
@Override
public int hashCode() {
return super.hashCode();
}
@Override
public synchronized Servlet getServlet() throws ServletException {
return servlet;
}
@Override
public void handle(Request baseRequest,
ServletRequest request,
ServletResponse response) throws ServletException, IOException {
final boolean asyncSupported = baseRequest.isAsyncSupported();
if (!isAsyncSupported()) {
baseRequest.setAsyncSupported(false, null);
}
try {
servlet.service(request, response);
} catch (EofException ignored) {
} finally {
baseRequest.setAsyncSupported(asyncSupported, null);
}
}
}