diff --git a/.circleci/config.yml b/.circleci/config.yml
index be10f4a..d873524 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -1,37 +1,55 @@
version: 2
-jobs:
- build:
- docker:
- - image: circleci/openjdk:8-jdk
+defaults: &defaults
+ working_directory: ~/repo
+ environment:
+ JVM_OPTS: -Xmx3200m
+ TERM: dumb
+ CI_NAME: "CircleCI"
- working_directory: ~/repo
-
- environment:
- JVM_OPTS: -Xmx3200m
- TERM: dumb
-
- steps:
- - checkout
- - restore_cache:
- keys:
+defaults_gradle: &defaults_gradle
+ steps:
+ - checkout
+ - restore_cache:
+ keys:
- gradle-dependencies-{{ checksum "build.gradle" }}
# fallback to using the latest cache if no exact match is found
- gradle-dependencies-
+ - run:
+ name: Gradle Dependencies
+ command: ./gradlew dependencies
+ - save_cache:
+ paths:
+ - ~/.m2
+ key: gradle-dependencies-{{ checksum "build.gradle" }}
+ - run:
+ name: Run All Checks
+ command: ./gradlew check
+ - store_artifacts:
+ path: build/reports/
+ destination: reports
+ - store_test_results:
+ path: build/reports/
- - run:
- name: Gradle Dependencies
- command: ./gradlew dependencies
+jobs:
+ build_gradle_jdk17:
+ <<: *defaults
- - save_cache:
- paths: ~/.m2
- key: gradle-dependencies-{{ checksum "build.gradle" }}
+ docker:
+ - image: cimg/openjdk:17.0
- - run:
- name: Run All Checks
- command: ./gradlew check
+ <<: *defaults_gradle
- - store_artifacts:
- path: build/reports/
- destination: reports
- - store_test_results:
- path: build/reports/
+ build_gradle_jdk8:
+ <<: *defaults
+
+ docker:
+ - image: circleci/openjdk:8-jdk
+
+ <<: *defaults_gradle
+
+workflows:
+ version: 2
+ gradle:
+ jobs:
+ - build_gradle_jdk8
+ - build_gradle_jdk17
diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml
index 251e704..86d7e7f 100644
--- a/.github/workflows/gradle.yml
+++ b/.github/workflows/gradle.yml
@@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
- java-version: [ 1.8, 11, 15 ]
+ java-version: [ 1.8, 11, 17, 18 ]
steps:
- uses: actions/checkout@v2
diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..6bf8b6f
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+httpstatus
\ No newline at end of file
diff --git a/.idea/HttpStatus.iml b/.idea/HttpStatus.iml
deleted file mode 100644
index d6ebd48..0000000
--- a/.idea/HttpStatus.iml
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
A simple JSP Tag Library to display the code, reason, cause and/or message for HTTP status codes in JSP error pages.
For example:
-<%@ page isErrorPage="true" %>
-<%@ taglib prefix="hs" uri="http://erik.thauvin.net/taglibs/httpstatus" %>
-<html><head>
-<title><hs:code/> <hs:reason default="Server Error"/></title>
-</head>
-<h1><hs:reason default="Server Error"/></h1>
-Cause: <pre><hs:cause default="Unable to complete your request."/></pre>
-Message: <pre><hs:message default="A server error has occured."/></pre>
-...
<%@ page isErrorPage="true" %>
+<%@ taglib prefix="hs" uri="http://erik.thauvin.net/taglibs/httpstatus" %>
+
+ <html><head><hs:code/> <hs:reason default="Server Error"/></title>
+ <title>
+ </head><hs:reason default="Server Error"/></h1>
+ <h1><hs:cause default="Unable to complete your request."/></pre>
+ Cause: <pre><hs:message default="A server error has occured."/></pre>
+ Message: <pre> ...
or
-<%@ page isErrorPage="true" import="net.thauvin.erik.httpstatus.Reasons" %>
-<%= Reasons.getReasonPhrase(pageContext.getErrorData().getStatusCode()) %>
<%@ page isErrorPage="true" import="net.thauvin.erik.httpstatus.Reasons" %>
+<%= Reasons.getReasonPhrase(pageContext.getErrorData().getStatusCode()) %>
would display on a 501 status code:
Not Implemented
+Include the following in your build.gradle
file:
dependencies {
+ implementation 'net.thauvin.erik.httpstatus:httpstatus:1.0.6'
+}
+
+or as a Maven artifact:
+<dependency>
+<groupId>net.thauvin.erik.httpstatus</groupId>
+ <artifactId>httpstatus</artifactId>
+ <version>1.0.6</version>
+ </dependency>
The <hs:cause/>
tag displays the cause of current HTTP status code, if any. A shorthand for:
<%= pageContext.getErrorData().getThrowable().getCause().getLocalizedMessage() %>
Optional attributes are:
The <hs:code/>
tag displays the current HTTP status code, if any. A shorthand for:
<%= pageContext.getErrorData().getStatusCode() %>
The <hs:message/>
tag displays the current error message, if any. A shorthand for:
<%= request.getAttribute("javax.servlet.error.message") %>
Optional attributes are:
The StatusCode
bean can be used to check the class of the status code error. For example, using the JSTL:
<%@ taglib prefix="hs" uri="http://erik.thauvin.net/taglibs/httpstatus" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+<jsp:useBean id="statusCode" class="net.thauvin.erik.httpstatus.StatusCode"/>
+<c:set target="${statusCode}" property="code"><hs:code/></c:set>
+<c:choose>
+<c:when test="${statusCode.isClientError()}">
+ <hs:reason/>)
+ An error occurred on your side. (</c:when>
+ <c:otherwise>
+ <hs:message/>)
+ An error occurred on our side. (</c:otherwise>
+ </c:choose>
or in a Servlet:
+import net.thauvin.erik.httpstatus.StatusCode;
+
+// ---
+
+new StatusCode((Integer) request.getAttribute("javax.servlet.error.status_code"));
+ StatusCode statusCode = if (statusCode.isError()) {
+if (statusCode.isServerError()) {
+ String reason = statusCode.getReason();
+ else {
+ } // ...
+
+ } }
The StatusCode
bean methods are:
Method | +Description | +
---|---|
getReason |
+Returns the reason for the status code (eg: Internal Server Error ) |
+
isClientError |
+Checks if the status code is a client error. | +
isError |
+Checks if the status code is a server or client error. | +
isInfo |
+Checks if the status code is informational. | +
isRedirect |
+Checks if the status code is a redirect. | +
isServerError |
+Checks if the status code is a server error. | +
isSuccess |
+Checks if the status code is a success. (OK ) |
+
isValid |
+Checks if the status code is valid. | +
The reasons are defined in a ResourceBundle properties as follows:
Include the following in your build.gradle
file:
dependencies {
- implementation 'net.thauvin.erik.httpstatus:httpstatus:1.0.6'
-}
-
-or as a Maven artifact:
-<dependency>
- <groupId>net.thauvin.erik.httpstatus</groupId>
- <artifactId>httpstatus</artifactId>
- <version>1.0.6</version>
-</dependency>
You can query the reason phrase for status codes as follows:
- +java -jar httpstatus-1.0.6.jar 404 500
+ $ 404: Not Found
+500: Internal Server Error
If no status code is specified, all will be printed:
-$ java -jar httpstatus-1.0.6.jar
-100: Continue
-101: Switching Protocols
-102: Processing
-103: Early Hints
-200: OK
-201: Created
-202: Accepted
-203: Non-Authoritative Information
-204: No Content
-205: Reset Content
-206: Partial Content
-207: Multi-Status
-208: Already Reported
-226: IM Used
-...
java -jar httpstatus-1.0.6.jar
+ $ 100: Continue
+101: Switching Protocols
+102: Processing
+103: Early Hints
+200: OK
+201: Created
+202: Accepted
+203: Non-Authoritative Information
+204: No Content
+205: Reset Content
+206: Partial Content
+207: Multi-Status
+208: Already Reported
+226: IM Used
+...