From 85064609614901fd6ee3f0fa6ea9b598d9c3ad37 Mon Sep 17 00:00:00 2001
From: "Erik C. Thauvin" null
.
*/
- @SuppressWarnings({"WeakerAccess"})
public static String getReasonPhrase(final String statusCode) {
return REASON_PHRASES.get(statusCode);
}
@@ -118,4 +117,4 @@ public final class Reasons {
System.out.println("Total: " + REASON_PHRASES.size());
}
}
-}
\ No newline at end of file
+}
diff --git a/version.properties b/version.properties
index 2759f0f..9ba483e 100644
--- a/version.properties
+++ b/version.properties
@@ -1,5 +1,5 @@
#Generated by the Semver Plugin for Gradle
-#Sun May 05 23:59:32 PDT 2019
+#Sat May 01 23:16:37 PDT 2021
version.buildmeta=
version.major=1
version.minor=0
From 74aaaf26cdd3e3636393c1cbaff51562d1aa1ad8 Mon Sep 17 00:00:00 2001
From: "Erik C. Thauvin" HttpStatus JSP Tag Library
+
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" %>
@@ -547,22 +547,22 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
Usage with Gradle or Maven
Include the following in your build.gradle
file:
dependencies {
- implementation 'net.thauvin.erik.httpstatus:httpstatus:1.0.5'
+ 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.5</version>
+ <version>1.0.6</version>
</dependency>
Command Line Usage
You can query the reason phrase for status codes as follows:
-$ java -jar httpstatus-1.0.5.jar 404 500
+
If no status code is specified, all will be printed:
-$ java -jar httpstatus-1.0.5.jar
+$ java -jar httpstatus-1.0.6.jar
100: Continue
101: Switching Protocols
102: Processing
diff --git a/src/test/java/net/thauvin/erik/httpstatus/UtilsTest.java b/src/test/java/net/thauvin/erik/httpstatus/UtilsTest.java
index 9b9b660..e03ec34 100644
--- a/src/test/java/net/thauvin/erik/httpstatus/UtilsTest.java
+++ b/src/test/java/net/thauvin/erik/httpstatus/UtilsTest.java
@@ -61,7 +61,7 @@ public class UtilsTest {
@SuppressFBWarnings("CE_CLASS_ENVY")
@Test
public void testOutWrite() throws IOException {
- try (final StringWriter sw = new StringWriter()) {
+ try (StringWriter sw = new StringWriter()) {
Utils.outWrite(sw, null, "default", false);
assertEquals(sw.toString(), "default", "outWrite(default)");
@@ -98,4 +98,4 @@ public class UtilsTest {
assertEquals(sw.toString(), "", "outWrite(null, xml)");
}
}
-}
\ No newline at end of file
+}
From 12936688ae3a7ca4603272ea3c7e7c66821d94dc Mon Sep 17 00:00:00 2001
From: "Erik C. Thauvin"
Date: Mon, 31 May 2021 11:53:29 -0700
Subject: [PATCH 13/29] Added Github workflow martix for JDK 1.8, 11 & 15.
---
.github/workflows/gradle.yml | 21 +++++++++++++------
build.gradle | 40 +++++++++++++++++++-----------------
2 files changed, 36 insertions(+), 25 deletions(-)
diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml
index 280a6a1..eef517b 100644
--- a/.github/workflows/gradle.yml
+++ b/.github/workflows/gradle.yml
@@ -5,17 +5,24 @@ on: [push, pull_request, workflow_dispatch]
jobs:
build:
runs-on: ubuntu-latest
+ env:
+ GRADLE_OPTS: "-Dorg.gradle.jvmargs=-XX:MaxMetaspaceSize=512m"
+ SONAR_JDK: "11"
+ strategy:
+ matrix:
+ java-version: [ 1.8, 11, 15 ]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- - name: Set up JDK 11
+ - name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v1
with:
- java-version: 11
+ java-version: ${{ matrix.java-version }}
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Cache SonarCloud packages
+ if: matrix.java-version == env.SONAR_JDK
uses: actions/cache@v1
with:
path: ~/.sonar/cache
@@ -27,15 +34,17 @@ jobs:
path: |
~/.gradle/caches
~/.gradle/wrapper
- key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
+ key: ${{ runner.os }}-gradle-${{ matrix.java-version }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
- ${{ runner.os }}-gradle-
+ ${{ runner.os }}-gradle-${{ matrix.java-version }}-
- name: Test with Gradle
+ run: ./gradlew build check --stacktrace
+ - name: SonarCloud
+ if: success() && matrix.java-version == env.SONAR_JDK
env:
- CI_NAME: "GitHub CI"
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- run: ./gradlew check sonarqube
+ run: ./gradlew sonarqube
- name: Cleanup Gradle Cache
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
diff --git a/build.gradle b/build.gradle
index 9ebf6da..0700f6c 100644
--- a/build.gradle
+++ b/build.gradle
@@ -93,8 +93,8 @@ clean {
test {
testLogging {
- exceptionFormat = "full"
- events("passed", "skipped", "failed")
+ exceptionFormat = 'full'
+ events('passed', 'skipped', 'failed')
}
useTestNG()
@@ -123,7 +123,7 @@ tasks.withType(Checkstyle) {
publishing {
publications {
mavenJava(MavenPublication) {
- from(components.java)
+ from components.java
groupId = project.group
artifactId = rootProject.name
@@ -155,11 +155,11 @@ publishing {
}
repositories {
maven {
- name = "ossrh"
+ name = 'ossrh'
project.afterEvaluate {
- url = project.version.contains("SNAPSHOT")
- ? "https://oss.sonatype.org/content/repositories/snapshots/"
- : "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
+ url = project.version.contains('SNAPSHOT')
+ ? 'https://oss.sonatype.org/content/repositories/snapshots/'
+ : 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
}
credentials(PasswordCredentials)
}
@@ -175,21 +175,23 @@ task copyToDeploy(type: Copy) {
from(configurations.runtimeClasspath) {
exclude('javax.servlet-api-*.jar', 'jsp-api-*.jar')
}
- from(jar)
- into(deployDir)
+ from jar
+ into deployDir
}
-task deploy(dependsOn: ['clean', 'build', 'copyToDeploy']) {
+task deploy {
description = "Copies all needed files to the ${deployDir} directory."
group = 'Publishing'
- outputs.dir(deployDir)
- inputs.files(copyToDeploy)
- mustRunAfter(clean)
+ dependsOn(clean, build, 'copyToDeploy')
+ outputs.dir deployDir
+ inputs.files copyToDeploy
+ mustRunAfter clean
}
-task release(dependsOn: ['wrapper', 'deploy', 'pandoc', 'publishToMavenLocal']) {
+task release {
group = 'Publishing'
description = 'Releases new version.'
+ dependsOn(wrapper, 'deploy', 'pandoc', publishToMavenLocal)
}
task pandoc(type: Exec) {
@@ -221,13 +223,13 @@ jacocoTestReport {
sonarqube {
properties {
- property("sonar.organization", "ethauvin-github")
- property("sonar.projectKey", "ethauvin_HttpStatus")
- property("sonar.host.url", "https://sonarcloud.io")
- property("sonar.sourceEncoding", "UTF-8")
+ property('sonar.organization', 'ethauvin-github')
+ property('sonar.projectKey', 'ethauvin_HttpStatus')
+ property('sonar.host.url', 'https://sonarcloud.io')
+ property('sonar.sourceEncoding', 'UTF-8')
}
}
tasks.sonarqube {
- dependsOn("jacocoTestReport")
+ dependsOn 'jacocoTestReport'
}
From 95f4c9714e743b7e11ba5299fffe2057c608bd26 Mon Sep 17 00:00:00 2001
From: "Erik C. Thauvin"
Date: Tue, 1 Jun 2021 02:37:32 -0700
Subject: [PATCH 14/29] Implemented StatusCode bean. Closes #5
---
.github/workflows/gradle.yml | 10 ++
README.md | 76 +++++++--
build.gradle | 8 +
.../thauvin/erik/httpstatus/StatusCode.java | 149 ++++++++++++++++++
.../erik/httpstatus/taglibs/ReasonTag.java | 2 -
.../erik/httpstatus/StatusCodeTest.java | 76 +++++++++
6 files changed, 306 insertions(+), 15 deletions(-)
create mode 100644 src/main/java/net/thauvin/erik/httpstatus/StatusCode.java
create mode 100644 src/test/java/net/thauvin/erik/httpstatus/StatusCodeTest.java
diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml
index eef517b..251e704 100644
--- a/.github/workflows/gradle.yml
+++ b/.github/workflows/gradle.yml
@@ -5,22 +5,28 @@ on: [push, pull_request, workflow_dispatch]
jobs:
build:
runs-on: ubuntu-latest
+
env:
GRADLE_OPTS: "-Dorg.gradle.jvmargs=-XX:MaxMetaspaceSize=512m"
SONAR_JDK: "11"
+
strategy:
matrix:
java-version: [ 1.8, 11, 15 ]
+
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
+
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java-version }}
+
- name: Grant execute permission for gradlew
run: chmod +x gradlew
+
- name: Cache SonarCloud packages
if: matrix.java-version == env.SONAR_JDK
uses: actions/cache@v1
@@ -28,6 +34,7 @@ jobs:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
+
- name: Cache Gradle packages
uses: actions/cache@v2
with:
@@ -37,14 +44,17 @@ jobs:
key: ${{ runner.os }}-gradle-${{ matrix.java-version }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-${{ matrix.java-version }}-
+
- name: Test with Gradle
run: ./gradlew build check --stacktrace
+
- name: SonarCloud
if: success() && matrix.java-version == env.SONAR_JDK
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew sonarqube
+
- name: Cleanup Gradle Cache
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
diff --git a/README.md b/README.md
index c19b75d..ee683a2 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,25 @@ would display on a [501 status code](http://www.w3.org/Protocols/rfc2616/rfc2616
Not Implemented
+## Usage with [Gradle](https://gradle.org/) or [Maven](http://maven.apache.org/)
+Include the following in your `build.gradle` file:
+
+```gradle
+dependencies {
+ implementation 'net.thauvin.erik.httpstatus:httpstatus:1.0.6'
+}
+```
+
+or as a Maven artifact:
+
+```xml
+
+ net.thauvin.erik.httpstatus
+ httpstatus
+ 1.0.6
+
+```
+
## hs:cause
The ` ` tag displays the cause of current HTTP status code, if any. A shorthand for:
@@ -175,24 +194,55 @@ Status Code | Reason
`598` | Network Read Timeout Error
`599` | Network Connect Timeout Error
-## Usage with [Gradle](https://gradle.org/) or [Maven](http://maven.apache.org/)
-Include the following in your `build.gradle` file:
+## StatusCode Bean
-```gradle
-dependencies {
- implementation 'net.thauvin.erik.httpstatus:httpstatus:1.0.6'
+The `StatusCode` bean can be used to check the class of the status code error. For example, using the JSTL:
+
+```jsp
+<%@ taglib prefix="hs" uri="http://erik.thauvin.net/taglibs/httpstatus" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ An error occurred on your side. ( )
+
+
+ An error occurred on our side. ( )
+
+
+```
+
+or in a Servlet:
+
+```java
+import net.thauvin.erik.httpstatus.StatusCode;
+
+// ---
+
+final StatusCode statusCode = new StatusCode((Integer) request.getAttribute("javax.servlet.error.status_code"));
+if (statusCode.isError()) {
+ if (statusCode.isServerError()) {
+ final String reason = statusCode.getReason();
+ } else {
+ // ...
+ }
}
```
-or as a Maven artifact:
+The `StatusCode` bean methods are:
-```xml
-
- net.thauvin.erik.httpstatus
- httpstatus
- 1.0.6
-
-```
+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.
## Command Line Usage
You can query the reason phrase for status codes as follows:
diff --git a/build.gradle b/build.gradle
index 0700f6c..4746236 100644
--- a/build.gradle
+++ b/build.gradle
@@ -103,6 +103,7 @@ test {
spotbugs {
toolVersion = versions.spotbugs
excludeFilter = file("$projectDir/config/spotbugs/excludeFilter.xml")
+
}
pmd {
@@ -120,6 +121,13 @@ tasks.withType(Checkstyle) {
}
}
+tasks.withType(SpotBugsTask) {
+ reports {
+ xml.enabled = false
+ html.enabled = true
+ }
+}
+
publishing {
publications {
mavenJava(MavenPublication) {
diff --git a/src/main/java/net/thauvin/erik/httpstatus/StatusCode.java b/src/main/java/net/thauvin/erik/httpstatus/StatusCode.java
new file mode 100644
index 0000000..e6a4df7
--- /dev/null
+++ b/src/main/java/net/thauvin/erik/httpstatus/StatusCode.java
@@ -0,0 +1,149 @@
+/*
+ * StatusCode.java
+ *
+ * Copyright (c) 2015-2021, Erik C. Thauvin (erik@thauvin.net)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * Neither the name of this project nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package net.thauvin.erik.httpstatus;
+
+import java.io.Serializable;
+
+/**
+ * The StatusCode
class implements methods to check the class of a HTTP status code.
+ *
+ * @author Erik C. Thauvin
+ */
+public class StatusCode implements Serializable {
+ private static final long serialVersionUID = 1L;
+ private int code;
+
+ /**
+ * Creates a new statusCode object.
+ */
+ public StatusCode() {
+ // Default construtor.
+ }
+
+ /**
+ * Creates a new StatusCode object.
+ *
+ * @param code The status code.
+ */
+ public StatusCode(final int code) {
+ this.code = code;
+ }
+
+ /**
+ * Returns the status code.
+ */
+ public int getCode() {
+ return code;
+ }
+
+ /**
+ * Returns the reason for the status code.
+ *
+ * @return The reason, or null
.
+ */
+ public String getReason() {
+ return Reasons.getReasonPhrase(code);
+ }
+
+ /**
+ * Checks if the status code is a client error.
+ *
+ * @return true
if the status code is a client error, false
otherwise.
+ */
+ public boolean isClientError() {
+ return code >= 400 && code < 500;
+ }
+
+ /**
+ * Checks if the status code is a client or server error.
+ *
+ * @return true
if the status code is an error, false
otherwise.
+ */
+ public boolean isError() {
+ return code >= 400 && code < 600;
+ }
+
+ /**
+ * Checks if the status code is informational.
+ *
+ * @return true
if the status code is informational, false
otherwise.
+ */
+ public boolean isInfo() {
+ return code >= 100 && code < 200;
+ }
+
+ /**
+ * Checks if the status code is a redirect.
+ *
+ * @return true
if the status code is a redirect, false
otherwise.
+ */
+ public boolean isRedirect() {
+ return code >= 300 && code < 400;
+ }
+
+ /**
+ * Checks if the status code is a server error.
+ *
+ * @return true
if the status code is a server error, false
otherwise.
+ */
+ public boolean isServerError() {
+ return code >= 500 && code < 600;
+ }
+
+ /**
+ * Checks if the status code is a (OK
) success.
+ *
+ * @return true
if the status code is a success, false
otherwise.
+ */
+ public boolean isSuccess() {
+ return code >= 200 && code < 300;
+ }
+
+ /**
+ * Checks if the status code is valid.
+ *
+ * @return true
if the status code is valid, false
otherwise.
+ */
+ public boolean isValid() {
+ return code >= 100 && code < 600;
+ }
+
+ /**
+ * Sets the status code.
+ *
+ * @param code The HTTP status code.
+ */
+ public void setCode(final int code) {
+ this.code = code;
+ }
+}
diff --git a/src/main/java/net/thauvin/erik/httpstatus/taglibs/ReasonTag.java b/src/main/java/net/thauvin/erik/httpstatus/taglibs/ReasonTag.java
index 684449f..b862eac 100644
--- a/src/main/java/net/thauvin/erik/httpstatus/taglibs/ReasonTag.java
+++ b/src/main/java/net/thauvin/erik/httpstatus/taglibs/ReasonTag.java
@@ -79,6 +79,4 @@ public class ReasonTag extends XmlSupport {
public void setCode(final int statusCode) {
this.statusCode = statusCode;
}
-
-
}
diff --git a/src/test/java/net/thauvin/erik/httpstatus/StatusCodeTest.java b/src/test/java/net/thauvin/erik/httpstatus/StatusCodeTest.java
new file mode 100644
index 0000000..0ce8357
--- /dev/null
+++ b/src/test/java/net/thauvin/erik/httpstatus/StatusCodeTest.java
@@ -0,0 +1,76 @@
+/*
+ * StatusCodeTest.java
+ *
+ * Copyright (c) 2015-2021, Erik C. Thauvin (erik@thauvin.net)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * Neither the name of this project nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package net.thauvin.erik.httpstatus;
+
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+/**
+ * StatusCode Tests.
+ *
+ * @author Erik C. Thauvin
+ */
+@SuppressFBWarnings("CE_CLASS_ENVY")
+public class StatusCodeTest {
+ @Test
+ void testStatusCode() {
+ final StatusCode statusCode = new StatusCode(100);
+
+ assertEquals(statusCode.getCode(), 100, "100 is 100");
+ assertTrue(statusCode.isInfo(), "100 is informational");
+
+ statusCode.setCode(200);
+ assertEquals(statusCode.getCode(), 200, "200 is 200");
+ assertTrue(statusCode.isSuccess(), "200 is OK");
+
+ statusCode.setCode(300);
+ assertTrue(statusCode.isRedirect(), "300 is redirect");
+
+ statusCode.setCode(400);
+ assertTrue(statusCode.isClientError(), "400 is client error");
+ assertTrue(statusCode.isError(), "400 is error");
+
+ statusCode.setCode(500);
+ assertTrue(statusCode.isServerError(), "500 is server error");
+ assertTrue(statusCode.isError(), "500 is error");
+ assertEquals(statusCode.getReason(), Reasons.getReasonPhrase(500), "500 reason phrase");
+ assertTrue(statusCode.isValid(), "500 is valid");
+
+ statusCode.setCode(600);
+ assertFalse(statusCode.isValid(), "600 is invalid()");
+ }
+}
From e77c8595cba91cb3b9b5066b01106e147c3983d7 Mon Sep 17 00:00:00 2001
From: "Erik C. Thauvin"
Date: Tue, 1 Jun 2021 03:03:55 -0700
Subject: [PATCH 15/29] Cleanup.
---
README.md | 102 +++++++++---------
.../thauvin/erik/httpstatus/StatusCode.java | 2 +-
.../erik/httpstatus/ReasonsMainTest.java | 2 +-
.../thauvin/erik/httpstatus/ReasonsTest.java | 4 +-
.../erik/httpstatus/StatusCodeTest.java | 6 +-
.../thauvin/erik/httpstatus/UtilsTest.java | 2 +-
6 files changed, 60 insertions(+), 58 deletions(-)
diff --git a/README.md b/README.md
index ee683a2..a8f2c4c 100644
--- a/README.md
+++ b/README.md
@@ -98,6 +98,58 @@ Attribute | Description
`default` | The fallback value to output, if no reason is available.
`escapeXml` | Converts <, >, &, ', " to their corresponding [entity codes](http://dev.w3.org/html5/html-author/charref). Value is `true` by default.
+## StatusCode Bean
+
+The `StatusCode` bean can be used to check the class of the status code error. For example, using the JSTL:
+
+```jsp
+<%@ taglib prefix="hs" uri="http://erik.thauvin.net/taglibs/httpstatus" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+ An error occurred on your side. ( )
+
+
+ An error occurred on our side. ( )
+
+
+```
+
+or in a Servlet:
+
+```java
+import net.thauvin.erik.httpstatus.StatusCode;
+
+// ---
+
+StatusCode statusCode = new StatusCode((Integer) request.getAttribute("javax.servlet.error.status_code"));
+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.
+
+## Reasons
+
The reasons are defined in a [ResourceBundle](http://docs.oracle.com/javase/8/docs/api/java/util/ResourceBundle.html) properties as follows:
Status Code | Reason
@@ -194,56 +246,6 @@ Status Code | Reason
`598` | Network Read Timeout Error
`599` | Network Connect Timeout Error
-## StatusCode Bean
-
-The `StatusCode` bean can be used to check the class of the status code error. For example, using the JSTL:
-
-```jsp
-<%@ taglib prefix="hs" uri="http://erik.thauvin.net/taglibs/httpstatus" %>
-<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
-
-
-
-
-
- An error occurred on your side. ( )
-
-
- An error occurred on our side. ( )
-
-
-```
-
-or in a Servlet:
-
-```java
-import net.thauvin.erik.httpstatus.StatusCode;
-
-// ---
-
-final StatusCode statusCode = new StatusCode((Integer) request.getAttribute("javax.servlet.error.status_code"));
-if (statusCode.isError()) {
- if (statusCode.isServerError()) {
- final 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.
-
## Command Line Usage
You can query the reason phrase for status codes as follows:
diff --git a/src/main/java/net/thauvin/erik/httpstatus/StatusCode.java b/src/main/java/net/thauvin/erik/httpstatus/StatusCode.java
index e6a4df7..a09f7e2 100644
--- a/src/main/java/net/thauvin/erik/httpstatus/StatusCode.java
+++ b/src/main/java/net/thauvin/erik/httpstatus/StatusCode.java
@@ -76,7 +76,7 @@ public class StatusCode implements Serializable {
}
/**
- * Checks if the status code is a client error.
+ * Checks if the status code is a client error. (eg: Interal Server Error
)
*
* @return true
if the status code is a client error, false
otherwise.
*/
diff --git a/src/test/java/net/thauvin/erik/httpstatus/ReasonsMainTest.java b/src/test/java/net/thauvin/erik/httpstatus/ReasonsMainTest.java
index a4175b4..642dfb6 100644
--- a/src/test/java/net/thauvin/erik/httpstatus/ReasonsMainTest.java
+++ b/src/test/java/net/thauvin/erik/httpstatus/ReasonsMainTest.java
@@ -45,7 +45,7 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
/**
- * The TestMain
class.
+ * Main Class Tests.
*
* @author Erik C. Thauvin
* @created 2019-05-06
diff --git a/src/test/java/net/thauvin/erik/httpstatus/ReasonsTest.java b/src/test/java/net/thauvin/erik/httpstatus/ReasonsTest.java
index 7dee1d8..76806c2 100644
--- a/src/test/java/net/thauvin/erik/httpstatus/ReasonsTest.java
+++ b/src/test/java/net/thauvin/erik/httpstatus/ReasonsTest.java
@@ -39,7 +39,7 @@ import java.util.ResourceBundle;
import static org.testng.Assert.assertEquals;
/**
- * The ReasonsTest
class.
+ * Reasons Tests.
*
* @author Erik C. Thauvin
* @created 2015-12-03
@@ -56,4 +56,4 @@ public class ReasonsTest {
}
}
-}
\ No newline at end of file
+}
diff --git a/src/test/java/net/thauvin/erik/httpstatus/StatusCodeTest.java b/src/test/java/net/thauvin/erik/httpstatus/StatusCodeTest.java
index 0ce8357..1bee73a 100644
--- a/src/test/java/net/thauvin/erik/httpstatus/StatusCodeTest.java
+++ b/src/test/java/net/thauvin/erik/httpstatus/StatusCodeTest.java
@@ -48,12 +48,12 @@ import static org.testng.Assert.assertTrue;
public class StatusCodeTest {
@Test
void testStatusCode() {
- final StatusCode statusCode = new StatusCode(100);
-
+ StatusCode statusCode = new StatusCode();
+ statusCode.setCode(100);
assertEquals(statusCode.getCode(), 100, "100 is 100");
assertTrue(statusCode.isInfo(), "100 is informational");
- statusCode.setCode(200);
+ statusCode = new StatusCode(200);
assertEquals(statusCode.getCode(), 200, "200 is 200");
assertTrue(statusCode.isSuccess(), "200 is OK");
diff --git a/src/test/java/net/thauvin/erik/httpstatus/UtilsTest.java b/src/test/java/net/thauvin/erik/httpstatus/UtilsTest.java
index e03ec34..93bb6ff 100644
--- a/src/test/java/net/thauvin/erik/httpstatus/UtilsTest.java
+++ b/src/test/java/net/thauvin/erik/httpstatus/UtilsTest.java
@@ -41,7 +41,7 @@ import java.io.StringWriter;
import static org.testng.Assert.assertEquals;
/**
- * The UtilsTest
class.
+ * Utils Tests.
*
* @author Erik C. Thauvin
* @created 2015-12-03
From 7dc9a51a7fd9486e64cfcf0ba0a3d8bb8456f69e Mon Sep 17 00:00:00 2001
From: "Erik C. Thauvin"
Date: Fri, 25 Mar 2022 11:50:32 -0700
Subject: [PATCH 16/29] Updated dependencies.
---
.circleci/config.yml | 74 +++--
.github/workflows/gradle.yml | 2 +-
.idea/.name | 1 +
.idea/HttpStatus.iml | 9 -
.idea/compiler.xml | 6 +
.idea/inspectionProfiles/Project_Default.xml | 7 +-
.idea/jarRepositories.xml | 30 ++
.idea/misc.xml | 2 +
.idea/modules.xml | 8 -
.idea/vcs.xml | 1 +
appveyor.yml | 2 +-
build.gradle | 32 +-
docs/README.html | 299 ++++++++++++-------
gradle/wrapper/gradle-wrapper.jar | Bin 59203 -> 59821 bytes
gradle/wrapper/gradle-wrapper.properties | 2 +-
gradlew | 269 ++++++++++-------
16 files changed, 449 insertions(+), 295 deletions(-)
create mode 100644 .idea/.name
delete mode 100644 .idea/HttpStatus.iml
create mode 100644 .idea/compiler.xml
create mode 100644 .idea/jarRepositories.xml
delete mode 100644 .idea/modules.xml
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 @@
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..61a9130
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index 78c3966..63787bb 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -2,7 +2,6 @@
-
@@ -47,13 +46,9 @@
+
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..4e9cedf
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,30 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 28a804d..9d92aa6 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,6 +1,8 @@
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 4c575ac..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 94a25f7..49e611e 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -1,6 +1,7 @@
+
\ No newline at end of file
diff --git a/appveyor.yml b/appveyor.yml
index f858073..877b3ed 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -23,7 +23,7 @@ cache:
environment:
matrix:
- - JAVA_HOME: C:\Program Files\Java\jdk15
+ - JAVA_HOME: C:\Program Files\Java\jdk17
- JAVA_HOME: C:\Program Files\Java\jdk11
matrix:
diff --git a/build.gradle b/build.gradle
index 4746236..eea5bf9 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,5 +1,4 @@
plugins {
- id 'checkstyle'
id 'java'
id 'jacoco'
id 'idea'
@@ -7,10 +6,10 @@ plugins {
id 'maven-publish'
id 'signing'
id 'pmd'
- id 'com.github.ben-manes.versions' version '0.38.0'
+ id 'com.github.ben-manes.versions' version '0.42.0'
id 'net.thauvin.erik.gradle.semver' version '1.0.4'
- id 'com.github.spotbugs' version '4.7.1'
- id 'org.sonarqube' version '3.2.0'
+ id 'com.github.spotbugs' version '5.0.6'
+ id 'org.sonarqube' version '3.3'
}
import com.github.spotbugs.snom.SpotBugsTask
@@ -35,20 +34,20 @@ mainClassName = 'net.thauvin.erik.httpstatus.Reasons'
ext {
versions = [
pmd: '6.35.0',
- spotbugs: '4.2.3'
+ spotbugs: '4.6.0'
]
}
repositories {
mavenLocal()
mavenCentral()
+ maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
- implementation 'javax.servlet:javax.servlet-api:4.0.1'
- implementation 'javax.servlet.jsp:jsp-api:2.2.1-b03'
- implementation 'javax.el:javax.el-api:3.0.1-b06'
-
+ compileOnly 'javax.servlet:javax.servlet-api:4.0.1'
+ compileOnly 'javax.servlet.jsp:jsp-api:2.2.1-b03'
+ compileOnly 'javax.el:javax.el-api:3.0.1-b06'
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.11.0'
spotbugsPlugins 'com.mebigfatguy.sb-contrib:sb-contrib:7.4.7'
@@ -56,7 +55,7 @@ dependencies {
compileOnly "com.github.spotbugs:spotbugs-annotations:$versions.spotbugs"
testCompileOnly "com.github.spotbugs:spotbugs-annotations:$versions.spotbugs"
- testImplementation 'org.testng:testng:7.4.0'
+ testImplementation 'org.testng:testng:7.5'
}
tasks.withType(JavaCompile) {
@@ -114,13 +113,6 @@ pmd {
consoleOutput = true
}
-tasks.withType(Checkstyle) {
- reports {
- xml.enabled = false
- html.enabled = true
- }
-}
-
tasks.withType(SpotBugsTask) {
reports {
xml.enabled = false
@@ -223,9 +215,13 @@ task pandoc(type: Exec) {
}
}
+jacoco {
+ toolVersion = '0.8.8-SNAPSHOT'
+}
+
jacocoTestReport {
reports {
- xml.enabled true
+ xml.required = true
}
}
diff --git a/docs/README.html b/docs/README.html
index c024860..4afcd01 100644
--- a/docs/README.html
+++ b/docs/README.html
@@ -5,74 +5,75 @@
HttpStatus JSP Tag Library
-
-
@@ -83,24 +84,36 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
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
+Usage with Gradle or Maven
+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>
hs:cause
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:
@@ -122,10 +135,10 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
hs:code
The <hs:code/>
tag displays the current HTTP status code, if any. A shorthand for:
-
+<%= pageContext.getErrorData().getStatusCode() %>
hs:message
The <hs:message/>
tag displays the current error message, if any. A shorthand for:
-
+<%= request.getAttribute("javax.servlet.error.message") %>
Optional attributes are:
@@ -169,6 +182,78 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
+StatusCode Bean
+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.
+
+
+
+Reasons
The reasons are defined in a ResourceBundle properties as follows:
@@ -544,39 +629,27 @@ code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warni
-Usage with Gradle or Maven
-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>
Command Line Usage
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
+...