Skip to content

Commit

Permalink
Update ErrorData to include new method attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Nov 23, 2023
1 parent 014cc5a commit cb18f0c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
19 changes: 16 additions & 3 deletions api/src/main/java/jakarta/servlet/jsp/ErrorData.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates and others.
* Copyright (c) 1997, 2023 Oracle and/or its affiliates and others.
* All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
Expand Down Expand Up @@ -30,6 +30,7 @@ public final class ErrorData {

private final Throwable throwable;
private final int statusCode;
private final String method;
private final String uri;
private final String queryString;
private final String servletName;
Expand All @@ -46,21 +47,24 @@ public final class ErrorData {
*/
@Deprecated(since = "4.0", forRemoval = true)
public ErrorData(Throwable throwable, int statusCode, String uri, String servletName) {
this(throwable, statusCode, uri, servletName, null);
this(throwable, statusCode, null, uri, servletName, null);
}

/**
* Creates a new ErrorData object.
*
* @param throwable The Throwable that is the cause of the error
* @param statusCode The status code of the error
* @param method The request method
* @param uri The request URI
* @param servletName The name of the servlet invoked
* @param queryString The request query string
*/
public ErrorData(Throwable throwable, int statusCode, String uri, String servletName, String queryString) {
public ErrorData(Throwable throwable, int statusCode, String method, String uri, String servletName,
String queryString) {
this.throwable = throwable;
this.statusCode = statusCode;
this.method = method;
this.uri = uri;
this.servletName = servletName;
this.queryString = queryString;
Expand All @@ -84,6 +88,15 @@ public int getStatusCode() {
return this.statusCode;
}

/**
* Returns the request method.
*
* @return The request method
*/
public String getMethod() {
return this.method;
}

/**
* Returns the request URI.
*
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/java/jakarta/servlet/jsp/PageContext.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates and others.
* Copyright (c) 1997, 2023 Oracle and/or its affiliates and others.
* All rights reserved.
* Copyright 2004 The Apache Software Foundation
*
Expand Down Expand Up @@ -423,9 +423,9 @@ public BodyContent pushBody() {
public ErrorData getErrorData() {
return new ErrorData((Throwable) getRequest().getAttribute("jakarta.servlet.error.exception"),
((Integer) getRequest().getAttribute("jakarta.servlet.error.status_code")).intValue(),
(String) getRequest().getAttribute("jakarta.servlet.error.method"),
(String) getRequest().getAttribute("jakarta.servlet.error.request_uri"),
(String) getRequest().getAttribute("jakarta.servlet.error.servlet_name"),
(String) getRequest().getAttribute("jakarta.servlet.error.query_string"));
}

}

0 comments on commit cb18f0c

Please sign in to comment.