Skip to content

Commit a9a45a5

Browse files
update jetty version to 12.1.0.beta0
Signed-off-by: Lachlan Roberts <lachlan.p.roberts@gmail.com>
1 parent 54bae27 commit a9a45a5

2 files changed

Lines changed: 25 additions & 93 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<maven.compiler.target>1.8</maven.compiler.target>
6666
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6767
<jetty.version>9.4.57.v20241219</jetty.version>
68-
<jetty12.version>12.1.0.alpha2</jetty12.version>
68+
<jetty12.version>12.1.0.beta0</jetty12.version>
6969
<io.grpc>1.71.0</io.grpc>
7070
<io.netty>4.1.119.Final</io.netty>
7171
<slf4j.version>2.0.17</slf4j.version>

runtime/runtime_impl_jetty12/src/main/java/com/google/apphosting/runtime/jetty/ee10/EE10AppVersionHandlerFactory.java

Lines changed: 24 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,14 @@
2525
import com.google.apphosting.runtime.jetty.EE10SessionManagerHandler;
2626
import com.google.common.flogger.GoogleLogger;
2727
import com.google.common.html.HtmlEscapers;
28-
import jakarta.servlet.RequestDispatcher;
29-
import jakarta.servlet.ServletContext;
3028
import jakarta.servlet.ServletException;
31-
import jakarta.servlet.http.HttpServletRequest;
32-
import jakarta.servlet.http.HttpServletResponse;
3329
import java.io.File;
34-
import java.io.IOException;
3530
import java.io.PrintWriter;
3631
import javax.servlet.jsp.JspFactory;
3732
import org.eclipse.jetty.ee10.annotations.AnnotationConfiguration;
3833
import org.eclipse.jetty.ee10.quickstart.QuickStartConfiguration;
39-
import org.eclipse.jetty.ee10.servlet.Dispatcher;
4034
import org.eclipse.jetty.ee10.servlet.ErrorHandler;
4135
import org.eclipse.jetty.ee10.servlet.ErrorPageErrorHandler;
42-
import org.eclipse.jetty.ee10.servlet.ServletContextRequest;
4336
import org.eclipse.jetty.ee10.webapp.FragmentConfiguration;
4437
import org.eclipse.jetty.ee10.webapp.MetaInfConfiguration;
4538
import org.eclipse.jetty.ee10.webapp.WebInfConfiguration;
@@ -77,12 +70,6 @@ public class EE10AppVersionHandlerFactory implements AppVersionHandlerFactory {
7770
*/
7871
private static final String USE_ANNOTATION_SCANNING = "use.annotationscanning";
7972

80-
/**
81-
* A "private" request attribute to indicate if the dispatch to a most recent error page has run
82-
* to completion. Note an error page itself may generate errors.
83-
*/
84-
static final String ERROR_PAGE_HANDLED = ErrorHandler.ERROR_PAGE + ".handled";
85-
8673
private final Server server;
8774
private final String serverInfo;
8875
private final boolean useJettyErrorPageHandler;
@@ -223,93 +210,38 @@ public void exitScope(Context context, Request request) {
223210
}
224211
}
225212

226-
/**
227-
* {@code NullErrorHandler} does nothing when an error occurs. The exception is already stored in
228-
* an attribute of {@code request}, but we don't do any rendering of it into the response, UNLESS
229-
* the webapp has a designated error page (servlet, jsp, or static html) for the current error
230-
* condition (exception type or error code).
231-
*/
232213
private static class NullErrorHandler extends ErrorPageErrorHandler {
233-
@Override
234-
public boolean handle(Request request, Response response, Callback callback) throws Exception {
235-
logger.atFine().log("Custom Jetty ErrorHandler received an error notification.");
236-
mayHandleByErrorPage(request, response, callback);
237-
// We don't want Jetty to do anything further.
238-
return true;
239-
}
240214

241215
/**
242-
* Try to invoke a custom error page if a handler is available. If not, render a simple HTML
243-
* response for {@link HttpServletResponse#sendError} calls, but do nothing for unhandled
244-
* exceptions.
245-
*
246-
* <p>This is loosely based on {@link ErrorPageErrorHandler#handle} but has been modified to add
247-
* a fallback simple HTML response (because Jetty's default response is not satisfactory) and to
248-
* set a special {@code ERROR_PAGE_HANDLED} attribute that disables our default behavior of
249-
* returning the exception to the appserver for rendering.
216+
* Override the response generation when not mapped to a servlet error page.
250217
*/
251-
private void mayHandleByErrorPage(Request request, Response response, Callback callback)
252-
throws IOException {
253-
ServletContextRequest contextRequest = Request.as(request, ServletContextRequest.class);
254-
HttpServletRequest httpServletRequest = contextRequest.getServletApiRequest();
255-
HttpServletResponse httpServletResponse = contextRequest.getHttpServletResponse();
256-
// Extract some error handling info from Jetty's proprietary attributes.
257-
Throwable error = (Throwable) contextRequest.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
258-
Integer code = (Integer) contextRequest.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
259-
String message = (String) contextRequest.getAttribute(RequestDispatcher.ERROR_MESSAGE);
260-
// Now try to find an error handler...
261-
String errorPage = getErrorPage(httpServletRequest);
262-
// If we found an error handler, dispatch to it.
263-
if (errorPage != null) {
264-
// Check for reentry into the same error page.
265-
String oldErrorPage = (String) request.getAttribute(ErrorHandler.ERROR_PAGE);
266-
if (oldErrorPage == null || !oldErrorPage.equals(errorPage)) {
267-
request.setAttribute(ErrorHandler.ERROR_PAGE, errorPage);
268-
ServletContext servletContext = httpServletRequest.getServletContext();
269-
Dispatcher dispatcher = (Dispatcher) servletContext.getRequestDispatcher(errorPage);
270-
try {
271-
if (dispatcher != null) {
272-
dispatcher.error(httpServletRequest, httpServletResponse);
273-
// Set this special attribute iff the dispatch actually works!
274-
// We use this attribute to decide if we want to keep the response content
275-
// or let the Runtime generate the default error page
276-
// TODO: an invalid html dispatch (404) will mask the exception
277-
request.setAttribute(ERROR_PAGE_HANDLED, errorPage);
278-
callback.succeeded();
279-
return;
280-
} else {
281-
logger.atWarning().log("No error page %s", errorPage);
282-
}
283-
} catch (ServletException e) {
284-
logger.atWarning().withCause(e).log("Failed to handle error page.");
285-
}
286-
}
287-
}
218+
@Override
219+
protected void generateResponse(
220+
Request request,
221+
Response response,
222+
int code,
223+
String message,
224+
Throwable cause,
225+
Callback callback) {
288226
// If we got an error code (e.g. this is a call to HttpServletResponse#sendError),
289227
// then render our own HTML. XFE has logic to do this, but the PFE only invokes it
290228
// for error conditions that it or the AppServer detect.
291-
if (code != null && message != null) {
292-
// This template is based on the default XFE error response.
293-
response.getHeaders().put(HttpHeader.CONTENT_TYPE, "text/html; charset=UTF-8");
294-
String messageEscaped = HtmlEscapers.htmlEscaper().escape(message);
295-
try (PrintWriter writer = new PrintWriter(Content.Sink.asOutputStream(response))) {
296-
writer.println("<html><head>");
297-
writer.println("<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">");
298-
writer.println("<title>" + code + " " + messageEscaped + "</title>");
299-
writer.println("</head>");
300-
writer.println("<body text=#000000 bgcolor=#ffffff>");
301-
writer.println("<h1>Error: " + messageEscaped + "</h1>");
302-
writer.println("</body></html>");
303-
writer.close();
304-
callback.succeeded();
305-
} catch (Throwable t) {
306-
callback.failed(t);
307-
}
308-
return;
229+
// This template is based on the default XFE error response.
230+
response.getHeaders().put(HttpHeader.CONTENT_TYPE, "text/html; charset=UTF-8");
231+
String messageEscaped = HtmlEscapers.htmlEscaper().escape(message);
232+
try (PrintWriter writer = new PrintWriter(Content.Sink.asOutputStream(response))) {
233+
writer.println("<html><head>");
234+
writer.println("<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">");
235+
writer.println("<title>" + code + " " + messageEscaped + "</title>");
236+
writer.println("</head>");
237+
writer.println("<body text=#000000 bgcolor=#ffffff>");
238+
writer.println("<h1>Error: " + messageEscaped + "</h1>");
239+
writer.println("</body></html>");
240+
writer.close();
241+
callback.succeeded();
242+
} catch (Throwable t) {
243+
callback.failed(t);
309244
}
310-
// If we got this far and *did* have an exception, it will be
311-
// retrieved and thrown at the end of JettyServletEngineAdapter#serviceRequest.
312-
throw new IllegalStateException(error);
313245
}
314246
}
315247
}

0 commit comments

Comments
 (0)