Skip to content

Commit

Permalink
Fix #235 Add support for query string in ErrorData
Browse files Browse the repository at this point in the history
Servlet 6.1 adds new attribute jakarta.servlet.error.query_string
  • Loading branch information
markt-asf committed Dec 12, 2022
1 parent b8b3a52 commit 5bf8b94
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
36 changes: 32 additions & 4 deletions api/src/main/java/jakarta/servlet/jsp/ErrorData.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
*/
public final class ErrorData {

private Throwable throwable;
private int statusCode;
private String uri;
private String servletName;
private final Throwable throwable;
private final int statusCode;
private final String uri;
private final String queryString;
private final String servletName;

/**
* Creates a new ErrorData object.
Expand All @@ -40,12 +41,29 @@ public final class ErrorData {
* @param statusCode The status code of the error
* @param uri The request URI
* @param servletName The name of the servlet invoked
*
* @deprecated Use {@link ErrorData#ErrorData(Throwable, int, String, String, String)}
*/
@Deprecated(since = "4.0", forRemoval = true)
public ErrorData(Throwable throwable, int statusCode, String uri, String servletName) {
this(throwable, statusCode, 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 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) {
this.throwable = throwable;
this.statusCode = statusCode;
this.uri = uri;
this.servletName = servletName;
this.queryString = queryString;
}

/**
Expand Down Expand Up @@ -83,4 +101,14 @@ public String getRequestURI() {
public String getServletName() {
return this.servletName;
}

/**
* Returns the request query string or {@code null} if the request had no
* query string.
*
* @return The request query string
*/
public String getQueryString() {
return this.queryString;
}
}
3 changes: 2 additions & 1 deletion api/src/main/java/jakarta/servlet/jsp/PageContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ 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.request_uri"),
(String) getRequest().getAttribute("jakarta.servlet.error.servlet_name"));
(String) getRequest().getAttribute("jakarta.servlet.error.servlet_name"),
(String) getRequest().getAttribute("jakarta.servlet.error.query_string"));
}

}
4 changes: 4 additions & 0 deletions spec/src/main/asciidoc/ServerPages.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11443,6 +11443,10 @@ Jakarta Server Pages specification. This appendix is non-normative.

* Remove the deprecated `jsp:plugin` action and related actions.

* https://github.com/eclipse-ee4j/jsp-api/issues/235[#235]
Update `ErrorData` to add support for the new attribute
`jakarta.servlet.error.query_string`

=== Changes between JSP 3.1 and JSP 3.0

* Deprecate methods that override `ELResolver.getFeatureDescriptors()` as that
Expand Down

0 comments on commit 5bf8b94

Please sign in to comment.