Compare commits

..

192 commits
1.0 ... master

Author SHA1 Message Date
3e9c9eb106
Bump PMD extension to version 1.2.3 2025-04-25 09:30:50 -07:00
018ccd86b4
Update extensions
Bump JaCoCo Report to version 0.9.10
Bump PMD to version 1.2.2
2025-04-13 13:36:12 -07:00
312e396052
Bump JUnit to version 5.12.2 2025-04-13 13:35:33 -07:00
ac1209abec
Add OS matrix for Ubuntu, Windows and macOS 2025-03-26 13:27:12 -07:00
4b82d03234
JDK 24 2025-03-18 23:58:13 -07:00
08d006af82
Update dependencies & copyright
Bump bld to version 2.2.1
Bump AssertJ to version 3.27.3
Bump JUnit to version 5.12.1
Bump Jacoco Report extension to version 0.9.9
Bump PMD exception to version 1.2.1
2025-03-16 13:10:19 -07:00
f596469b5b
Cleaned up tests and added soft assertions 2024-10-26 21:16:18 -07:00
7ee45b34a4
Improved JavaDocs 2024-10-26 20:36:13 -07:00
96497f7f27
Updated dependencies
Bumped JUnit to version 5.11.3
Bumped PMD extension to version 1.1.7
Bumped JDK to version 23 (GitHub CI Workflow)
2024-10-26 20:35:43 -07:00
ec75fc4690
Fixed snapshot badge 2024-09-21 12:59:35 -07:00
1bb7167aba
Bumped bld to version 2.1.0 2024-09-21 12:44:55 -07:00
71467db442
Version 1.1.1 2024-06-07 17:41:41 -07:00
1c4b20e11c
Bumped PMD extension to version 1.0.1 2024-06-07 16:15:44 -07:00
053dcba26b
Sort command line output. Closes #10
Updated copyright

Code cleanup
2024-06-07 15:39:49 -07:00
8c79c0e17a
Added more status codes from Wikipedia, etc. Closes #9 2024-06-07 12:46:26 -07:00
91e19d325e
Changed rootPom() to pomRoot() 2024-06-07 12:16:10 -07:00
2d0167e5e9
Bumped AssertJ to version 3.26.0 2024-06-07 12:15:55 -07:00
780a5c30c4
Bumped PMD extension to version 1.0.0 2024-06-07 12:14:59 -07:00
96565dbfe7
Minor cleanup 2024-05-09 23:04:53 -07:00
1a0d4eb958
Updated copyright 2024-05-09 23:02:39 -07:00
774eadaac2
Bumped dependencies versions 2024-05-09 23:02:10 -07:00
6af9b46df9
Bumped JaCoCo extension to version 0.9.5 2024-05-09 22:58:06 -07:00
18f5e92261
Bumped PMD extension to version 0.9.9 2024-05-09 22:57:32 -07:00
d6f6c40d77
Bumped bld to version 1.9.1 2024-05-09 22:56:47 -07:00
cd68004962
Bumped workflow actions to lastest versions 2024-05-09 22:47:23 -07:00
59c775e33a Changed sh format to console 2024-01-31 17:31:49 -08:00
e784b5a8f0 Added contributing section 2024-01-31 17:26:09 -08:00
1d6a7824fe Bumped bld to 1.8.0 2024-01-31 15:42:25 -08:00
4011fe8024 Upgraded bld 2023-10-20 16:10:25 -07:00
477ef6237c Fixed bld badge 2023-09-29 05:13:36 -07:00
30f8b4c206 Version 1.1 2023-09-29 04:27:27 -07:00
5b47bf704e Added table of contents 2023-09-29 01:58:55 -07:00
b0826267b5 Simplified printing list of all status codes 2023-09-28 23:57:54 -07:00
1fca084fc9 Added printing of status code by response classes. Close #8 2023-09-28 23:34:02 -07:00
7b3e4adfc8 Cleanup before 1.1 release 2023-09-28 22:01:04 -07:00
3bedb10705 Cleaned up README 2023-08-20 16:48:08 -07:00
d0770a76f6 Upgraded to bld 1.7.2 2023-08-20 16:47:57 -07:00
55c0cfdce5 Fix snapshot badge 2023-08-19 00:57:54 -07:00
c319102581 Fix copyright 2023-08-19 00:57:31 -07:00
5d911ddca2 Added root pom generation using new syntax 2023-08-18 13:45:37 -07:00
f16eba7bac Upgrade to bld 1.7.1 2023-08-18 06:28:28 -07:00
0d98e8a602
Update config.yml 2023-08-17 13:14:00 -07:00
a855bb6079
Update bld-wrapper.properties 2023-08-17 12:41:28 -07:00
80e7766206 Minor cleanup 2023-08-17 08:27:29 -07:00
eeb861a7c9 Added bld badge 2023-08-17 07:42:40 -07:00
1b46eaff7f Cleaned up repositories 2023-08-17 07:26:39 -07:00
7b27ddbc86 Minor cleanup 2023-08-16 09:14:42 -07:00
c80ea7b7d3 Upgraded dependencies 2023-08-16 09:14:00 -07:00
9a2647e7f4 Added tests for the cause tag 2023-08-16 09:12:01 -07:00
2ff4128bc9 Revert "Testing sonar with less options"
This reverts commit 917131860f.
2023-08-12 21:37:59 -07:00
917131860f Testing sonar with less options 2023-08-12 21:34:16 -07:00
18aa6ddb59 Minor cleanup 2023-08-12 21:33:58 -07:00
2cfbed3291 Fixed COVERAGE_SDK 2023-08-12 18:24:45 -07:00
32ba057820 Added COVERAGE_SDK 2023-08-12 18:22:27 -07:00
cc50ac9d31 Added codecov 2023-08-12 18:12:39 -07:00
09e5de99e7 Added compile dependencies 2023-08-12 14:55:13 -07:00
62c9b665dd Made sonar.java.libraries empty 2023-08-12 14:24:42 -07:00
f92cc8561a Added sonar.java.libraries 2023-08-12 14:22:16 -07:00
f76cee867d Removed pom.xml in action 2023-08-12 14:07:55 -07:00
4a5c68cdb5 Added SonarCloud badge 2023-08-12 13:55:34 -07:00
1144930002 Added sonar.java.binaries 2023-08-12 13:37:53 -07:00
8b7d57114b Fixed project key 2023-08-12 13:33:11 -07:00
5d74358523 Removed pom for testing 2023-08-12 13:26:17 -07:00
d08b4bbeb2 Added sonar-project.properties 2023-08-12 13:21:49 -07:00
75d68c941e Removed verbose 2023-08-12 13:17:18 -07:00
9270788386 Added Sonar JDK to worklow 2023-08-12 12:58:10 -07:00
92ed30a415 Added sonarcloud to GitHub workflow 2023-08-12 12:52:56 -07:00
2c6493c631 Upgraded to RIFE2 1.7.0 2023-05-12 15:40:44 -07:00
b236998e72 Removed deploy script 2023-05-10 11:08:45 -07:00
d41d89b477 Minor cleanup 2023-05-10 02:04:05 -07:00
2c0b074a10 Merge branch '1.1.0-dev' 2023-05-10 01:55:49 -07:00
5a1d4eecec Fixed CircleCI workflow 2023-05-10 01:46:23 -07:00
a24eec1f51 Removed appveyor 2023-05-10 01:17:57 -07:00
68975a497b Moved from Gradle to bld 2023-05-10 00:21:31 -07:00
84cfe6098d Fixed OpenJDK image aliases 2022-08-27 18:47:13 -07:00
1f0a920ca3 Fixed CIs, maybe... 2022-08-27 18:34:22 -07:00
c75ba0b38b Removed Java 8 from CIs 2022-08-27 18:25:28 -07:00
45af218f39 Moved to Jakarta EE. Closes #7 2022-08-27 18:14:54 -07:00
c4edb4fd1f Cleaned up and updated dependencies 2022-04-24 00:49:11 -07:00
8ed5bc951f More status code tests improvements. 2022-03-25 13:06:48 -07:00
3616136f4e Improved status code testing. 2022-03-25 12:57:00 -07:00
5486074d1e Updated copyright. 2022-03-25 12:56:41 -07:00
6344d7a68b Only use XML character entities in Utils.escapeXml(). Closes #6 2022-03-25 12:05:07 -07:00
1ab96e5b3a Cleanup. 2022-03-25 12:04:05 -07:00
7dc9a51a7f Updated dependencies. 2022-03-25 12:02:54 -07:00
e77c8595cb Cleanup. 2021-06-01 03:03:55 -07:00
95f4c9714e Implemented StatusCode bean. Closes #5 2021-06-01 02:38:08 -07:00
12936688ae Added Github workflow martix for JDK 1.8, 11 & 15. 2021-05-31 11:53:29 -07:00
b967f13230 Updated PMD rules. 2021-05-29 21:54:19 -07:00
c3adfb1f07 Added Visual Studio 2019 image. 2021-05-21 14:52:56 -07:00
8dd40acdfb Added branch to appveyor. 2021-05-21 14:46:08 -07:00
8b87ddae42 Moved to JDK 11 and 15. 2021-05-21 00:03:32 -07:00
f9fcd3a425 Removed TravisCI. 2021-05-20 21:51:25 -07:00
c30a705a85 Fixed typo, again. 2021-05-19 23:03:24 -07:00
0862186633 Fixed typo. 2021-05-19 23:00:32 -07:00
31b8c48bad Fixed sonarcloud project name. 2021-05-19 22:55:52 -07:00
37789dc633 Moved Sonarqube to GitHub action. 2021-05-19 22:52:19 -07:00
6f15433034 Upgraded to Gradle 7.0.1 2021-05-11 20:43:59 -07:00
74aaaf26cd Added support for snapshot. 2021-05-02 22:01:12 -07:00
8506460961 Updated dependencies. 2021-05-01 23:17:48 -07:00
bd47e55869 Cleanup. 2021-03-22 10:52:45 -07:00
d5005f18ea Changed badges cases. 2021-03-19 21:18:35 -07:00
bc73cb6093 Updated MavenCentral badge. 2021-03-19 21:15:15 -07:00
357d18e393 Updated README for 1.0.5. 2021-03-19 19:27:54 -07:00
d02a8a7a0a Moved entirely to maven-publish. 2021-03-19 17:53:48 -07:00
495f9cca31 Added artificats back. 2021-03-19 16:23:43 -07:00
bbda52c19e Version 1.0.5 2021-03-19 15:30:44 -07:00
109e3894ab Fix for CI problem with missing mavenDeployer authentication. 2021-03-19 14:52:01 -07:00
74dddbba69 Added <hs:message/> to example. 2021-03-19 11:14:01 -07:00
ab231453a8 Updated copryright. 2021-03-18 23:33:48 -07:00
e8e421b159 Code reformat. 2021-03-17 19:18:56 -07:00
a64147959f Switched gpg command for signing. 2021-03-17 14:58:33 -07:00
589f451927 Cleanup. 2021-03-17 12:29:46 -07:00
41471e31af Cleaned up main() tests. 2021-03-17 12:26:47 -07:00
3a64bd57d5 Cleanup. 2021-03-17 12:26:03 -07:00
3688384b0d Updated dependencies. 2021-03-16 18:16:17 -07:00
319878ec1a Switched from bintray/jCenter to maven central. 2021-03-16 16:59:51 -07:00
9ff860af40 Added MessageTag. Closes #4 2021-03-16 09:56:02 -07:00
0dafe87021 Updated dependencies. 2021-03-16 02:31:49 -07:00
2ca48c0aef Sonarcloud needs jacco reports in xml format now. 2020-03-22 21:56:16 -07:00
8d2b387c97 Fix Build #32, hopefully. 2020-03-22 21:32:35 -07:00
66db0b801f Add Unofficial Codes from Cloudflare, IIS, Nginx, and AWS. Closes #3 2020-03-22 21:13:28 -07:00
9d21dd76c0 Fixed containsKey() before get(). 2020-03-22 21:11:15 -07:00
4a701e1ee0 Updated dependencies and cleanup. 2020-03-22 20:59:53 -07:00
aa8fadd37c Added changelog. 2019-05-08 10:01:57 -07:00
e768496fe6 Cleanup. 2019-05-08 09:53:19 -07:00
54426f834b Re-arranged badges. 2019-05-07 23:01:55 -07:00
b464017501 Misc IDEA files updates. 2019-05-07 20:50:57 -07:00
8c717b49fa Fixed bintray version. 2019-05-07 19:48:57 -07:00
37fad706ec Added command line usage. 2019-05-07 18:54:41 -07:00
398355e0b8 Updated copyright, version. 2019-05-07 18:50:09 -07:00
6a6e800e93 Added command line usage. 2019-05-07 01:06:25 -07:00
dff03ed4e8 Updated wrapper. 2019-05-07 00:50:05 -07:00
cea041703a Change compatibility to 1.8. 2019-05-06 22:46:56 -07:00
56878419bd Improved javadoc for main(). 2019-05-06 22:46:32 -07:00
cb581bf0d9 Fixed bug where <hs:cause> would always return the default value. Closes #2. 2019-05-06 22:28:57 -07:00
3172b2b39f Added sonarqube. 2019-05-06 15:09:17 -07:00
4fa2fd2726 Added tests for Reasons.main(). 2019-05-06 15:08:57 -07:00
58baccab90 Updated copyright. 2019-05-06 15:08:36 -07:00
9a4de2ebc8 Added tests for getReasonPhrase() with int. 2019-05-06 15:08:24 -07:00
465add5837 Added more tests for outWrite. 2019-05-06 15:07:53 -07:00
40338c4269 Improved main method. 2019-05-06 15:07:26 -07:00
f6759afd31 Added INA HTTP status codes. Closes #1 2019-05-06 03:10:32 -07:00
4dbc2bbc08 Cleanup. 2019-05-06 03:09:05 -07:00
14cb07ef0d Added testOutWrite. 2019-05-06 03:08:45 -07:00
709a33e1bd Removed dataProvider. 2019-05-06 03:07:14 -07:00
4d4575ddd9 Added disabled constructor. 2019-05-06 03:05:58 -07:00
4fbc229beb Cleanup. 2019-05-06 03:05:37 -07:00
7245515df1 Added checkstyle, pmd, spotbugs, sonarqube. 2019-05-06 03:02:35 -07:00
f366f9c037 Removed pom. 2019-05-06 02:52:49 -07:00
5d5a8fa6ad Fixed badges. 2018-06-18 19:25:48 -07:00
202d5430d0 Added snyk badge. 2018-01-16 20:47:48 -08:00
7f615ba709 Updated to Servlet API 4.0.0. 2018-01-16 20:35:52 -08:00
e0a76ac839 Moved go Gemnasium since VersionEye is shutting down. 2018-01-16 20:32:51 -08:00
f416d5ea91 Added source & target compatibilties. 2017-11-06 12:16:50 -08:00
761e6854c1 Updated Gradle wrapper. 2017-10-31 01:15:25 -07:00
a570848319 Added CircleCI 2.0 configuration. 2017-10-31 01:13:27 -07:00
f511db7b98 Dependency updates. 2017-10-31 01:13:06 -07:00
dbd17858b5 Fixed release task. 2017-06-09 21:05:42 -07:00
d8fa58d9d3 Fixed badges. 2017-06-07 16:14:54 -07:00
22819033ea Moved README.html to docs. 2017-06-07 15:56:26 -07:00
0f223fd254 Fixed circledci badge. 2017-05-29 22:30:12 -07:00
09727b752a Added circleci configuration. 2017-05-29 22:24:30 -07:00
b78bdf73f0 Misc. javadoc updates. 2016-07-18 18:32:33 -07:00
32a1bf3875 Code format, tabs to space, etc. 2016-07-18 18:17:22 -07:00
c707b342aa Removed mavenCentral() in build. 2016-07-08 21:23:50 -07:00
b8a387aeb7 Fixed release task dependencies. 2016-07-08 21:22:20 -07:00
94a5511bd8 Fixed release task dependencies. 2016-07-08 06:09:27 -07:00
2120576cce Added jcenter for latest version of testng. 2016-06-30 16:51:24 -07:00
7998e44939 Added Github css style for pandoc. 2016-06-30 12:49:56 -07:00
90dd1dfc5d Updated pandoc task. 2016-06-29 23:31:50 -07:00
26e5afa5d3 Updated to testng 6.9.12. 2016-06-29 12:39:31 -07:00
e18fc4a9e9 Code formatting. 2016-02-02 21:38:48 -08:00
b50a026997 Added release badge. 2016-01-25 23:28:11 -08:00
5b56399b26 Added appveyor badge. 2016-01-25 15:29:08 -08:00
d06795e0af Added appveyor.yml configuration. 2016-01-25 15:26:36 -08:00
537b2716ad Added jcenter badge. 2016-01-25 13:59:30 -08:00
c062b7f24a Added chmod to .travis.yml 2016-01-25 13:40:15 -08:00
0bd4fdd742 Added travis-ci. 2016-01-25 13:32:46 -08:00
42f35c10c2 Added license.
Updated javadoc task & comments.
2016-01-24 12:27:24 -08:00
1539462d1d Added maven POM info. 2016-01-22 14:42:39 -08:00
439d8e9669 Added Gradle instructions. 2016-01-21 17:09:00 -08:00
b8599caffe Bintray release. 2016-01-21 15:14:14 -08:00
c63f6d8389 Added version properties. 2016-01-21 15:02:59 -08:00
51a03bde4c Added bintray publishing. 2016-01-18 22:32:40 -08:00
ce8833ca53 Fixed release task. 2015-12-16 15:36:06 -08:00
f5f9d5cbda Improved source documentation.
Some PMD optimization.
2015-12-07 02:46:45 -08:00
1b59f8e5dc Made pandoc task cross-platform. 2015-12-05 02:25:53 -08:00
229c9144dd Added JSP reference. 2015-12-05 02:25:52 -08:00
e872c226e8 PMD optimization. 2015-12-05 02:20:43 -08:00
8767f5239c Added pandoc task. 2015-12-04 14:18:29 -08:00
504fdb6bd5 Added Bundle base name constant. 2015-12-04 01:30:26 -08:00
58 changed files with 2207 additions and 1403 deletions

42
.circleci/config.yml Normal file
View file

@ -0,0 +1,42 @@
version: 2.1
commands:
build_and_test:
parameters:
reports-dir:
type: string
default: "build/reports/test_results"
steps:
- checkout
- run:
name: Download dependencies
command: ./bld download
- run:
name: Compile source
command: ./bld compile
- run:
name: Run tests
command: ./bld jacoco -reports-dir=<< parameters.reports-dir >>
- store_test_results:
path: << parameters.reports-dir >>
- store_artifacts:
path: build/reports/jacoco/test/html
jobs:
bld_jdk17:
docker:
- image: cimg/openjdk:17.0
steps:
- build_and_test
bld_jdk21:
docker:
- image: cimg/openjdk:21.0
steps:
- build_and_test
workflows:
bld:
jobs:
- bld_jdk17
- bld_jdk21

53
.github/workflows/bld.yml vendored Normal file
View file

@ -0,0 +1,53 @@
name: bld-ci
on: [ push, pull_request, workflow_dispatch ]
jobs:
build-bld-project:
env:
COVERAGE_JDK: "17"
strategy:
matrix:
java-version: [ 17, 21, 24 ]
os: [ ubuntu-latest, windows-latest, macos-latest ]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout source repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v4
with:
distribution: "zulu"
java-version: ${{ matrix.java-version }}
- name: Download dependencies
run: ./bld download
- name: Compile source
run: ./bld compile
- name: Run tests
run: ./bld jacoco
- name: Remove pom.xml
if: success() && matrix.java-version == env.COVERAGE_JDK && matrix.os == 'ubuntu-latest'
run: rm -rf pom.xml
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master
if: success() && matrix.java-version == env.COVERAGE_JDK && matrix.os == 'ubuntu-latest'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
if: success() && matrix.java-version == env.COVERAGE_JDK && matrix.os == 'ubuntu-latest'
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

View file

@ -0,0 +1 @@
future-release=1.1.2

80
.gitignore vendored
View file

@ -1,24 +1,58 @@
**/.idea/dictionaries
**/.idea/gradle.xml
**/.idea/libraries
**/.idea/tasks.xml
**/.idea/workspace.xml
*.iws
.DS_Store
.classpath
.gradle
.nb-gradle
.project
.settings
/bin
/build
/deploy
/dist
/gen
/local.properties
/out
/proguard-project.txt
/project.properties
/test-output
Thumbs.db
ehthumbs.db
.DS_Store
build
lib/bld/**
!lib/bld/bld-wrapper.properties
!lib/bld/bld-wrapper.jar
lib/compile/
lib/runtime/
lib/standalone/
lib/test/
# IDEA ignores
# User-specific
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# AWS User-specific
.idea/**/aws.xml
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# SonarLint plugin
.idea/sonarlint/
# Editor-based Rest Client
.idea/httpRequests
target
local.properties

29
.idea/app.iml generated Normal file
View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/build/main" />
<output-test url="file://$MODULE_DIR$/build/test" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/src/main/resources/templates" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="RUNTIME">
<library>
<CLASSES>
<root url="file://$MODULE_DIR$/src/main/resources/templates" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="compile" level="project" />
<orderEntry type="library" scope="RUNTIME" name="runtime" level="project" />
<orderEntry type="library" scope="TEST" name="test" level="project" />
</component>
</module>

14
.idea/bld.iml generated Normal file
View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/build/bld" />
<output-test url="file://$MODULE_DIR$/build/bld" />
<exclude-output />
<content url="file://$MODULE_DIR$/src/bld">
<sourceFolder url="file://$MODULE_DIR$/src/bld/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="bld" level="project" />
</component>
</module>

6
.idea/bld.xml generated Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="BldConfiguration">
<events />
</component>
</project>

5
.idea/codeStyles/codeStyleConfig.xml generated Normal file
View file

@ -0,0 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Erik's Code Style" />
</state>
</component>

6
.idea/copyright/Erik_s_Copyright.xml generated Normal file
View file

@ -0,0 +1,6 @@
<component name="CopyrightManager">
<copyright>
<option name="notice" value="&amp;#36;file.fileName&#10;&#10;Copyright 2015-&amp;#36;today.year Erik C. Thauvin (erik@thauvin.net)&#10;All rights reserved.&#10;&#10;Redistribution and use in source and binary forms, with or without&#10;modification, are permitted provided that the following conditions are met:&#10;&#10; Redistributions of source code must retain the above copyright notice, this&#10; list of conditions and the following disclaimer.&#10;&#10; Redistributions in binary form must reproduce the above copyright notice,&#10; this list of conditions and the following disclaimer in the documentation&#10; and/or other materials provided with the distribution.&#10;&#10; Neither the name of this project nor the names of its contributors may be&#10; used to endorse or promote products derived from this software without&#10; specific prior written permission.&#10;&#10;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS IS&quot;&#10;AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE&#10;IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE&#10;DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE&#10;FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL&#10;DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR&#10;SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER&#10;CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,&#10;OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE&#10;OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." />
<option name="myName" value="Erik's Copyright Notice" />
</copyright>
</component>

3
.idea/copyright/profiles_settings.xml generated Normal file
View file

@ -0,0 +1,3 @@
<component name="CopyrightManager">
<settings default="Erik's Copyright Notice" />
</component>

View file

@ -0,0 +1,8 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="JavadocDeclaration" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ADDITIONAL_TAGS" value="created" />
</inspection_tool>
</profile>
</component>

18
.idea/libraries/bld.xml generated Normal file
View file

@ -0,0 +1,18 @@
<component name="libraryTable">
<library name="bld">
<CLASSES>
<root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-2.2.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/lib/bld" />
<root url="jar://$USER_HOME$/.bld/dist/bld-2.2.1-sources.jar!/" />
</SOURCES>
<excluded>
<root url="jar://$PROJECT_DIR$/lib/bld/bld-wrapper.jar!/" />
</excluded>
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" />
<jarDirectory url="file://$PROJECT_DIR$/lib/bld" recursive="false" type="SOURCES" />
</library>
</component>

13
.idea/libraries/compile.xml generated Normal file
View file

@ -0,0 +1,13 @@
<component name="libraryTable">
<library name="compile">
<CLASSES>
<root url="file://$PROJECT_DIR$/lib/compile" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/lib/compile" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/lib/compile" recursive="true" />
<jarDirectory url="file://$PROJECT_DIR$/lib/compile" recursive="true" type="SOURCES" />
</library>
</component>

14
.idea/libraries/runtime.xml generated Normal file
View file

@ -0,0 +1,14 @@
<component name="libraryTable">
<library name="runtime">
<CLASSES>
<root url="file://$PROJECT_DIR$/lib/runtime" />
<root url="file://$PROJECT_DIR$/src/main/resources" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/lib/runtime" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/lib/runtime" recursive="true" />
<jarDirectory url="file://$PROJECT_DIR$/lib/runtime" recursive="true" type="SOURCES" />
</library>
</component>

14
.idea/libraries/test.xml generated Normal file
View file

@ -0,0 +1,14 @@
<component name="libraryTable">
<library name="test">
<CLASSES>
<root url="file://$PROJECT_DIR$/lib/test" />
<root url="file://$PROJECT_DIR$/src/test/resources" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="file://$PROJECT_DIR$/lib/test" />
</SOURCES>
<jarDirectory url="file://$PROJECT_DIR$/lib/test" recursive="true" />
<jarDirectory url="file://$PROJECT_DIR$/lib/test" recursive="true" type="SOURCES" />
</library>
</component>

25
.idea/misc.xml generated Normal file
View file

@ -0,0 +1,25 @@
<project version="4">
<component name="EntryPointsManager">
<pattern value="net.thauvin.erik.httpstatus.HttpStatusBuild" />
<pattern value="net.thauvin.erik.httpstatus.HttpStatusBuild" method="pmd" />
<pattern value="net.thauvin.erik.httpstatus.HttpStatusBuild" method="jacoco" />
<pattern value="net.thauvin.erik.httpstatus.taglibs.ReasonTag" method="setCode" />
<pattern value="net.thauvin.erik.httpstatus.HttpStatusBuild" method="pmdCli" />
</component>
<component name="PDMPlugin">
<option name="customRuleSets">
<list>
<option value="K:\java\semver\config\pmd.xml" />
<option value="$PROJECT_DIR$/../bld-pitest/config/pmd.xml" />
<option value="$PROJECT_DIR$/../bld-jacoco-report/config/pmd.xml" />
<option value="$PROJECT_DIR$/../bld-checkstyle/config/pmd.xml" />
<option value="$PROJECT_DIR$/../bld-exec/config/pmd.xml" />
<option value="$PROJECT_DIR$/../bld-testng/config/pmd.xml" />
</list>
</option>
<option name="skipTestSources" value="false" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build" />
</component>
</project>

9
.idea/modules.xml generated Normal file
View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/app.iml" filepath="$PROJECT_DIR$/.idea/app.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/bld.iml" filepath="$PROJECT_DIR$/.idea/bld.iml" />
</modules>
</component>
</project>

9
.idea/runConfigurations/Run Tests.xml generated Normal file
View file

@ -0,0 +1,9 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run Tests" type="Application" factoryName="Application" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="net.thauvin.erik.httpstatus.HttpStatusTest" />
<module name="app" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
</component>

6
.idea/vcs.xml generated Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

11
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "Run Tests",
"request": "launch",
"mainClass": "net.thauvin.erik.httpstatus.HttpStatusTest"
}
]
}

14
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,14 @@
{
"java.project.sourcePaths": [
"src/main/java",
"src/main/resources",
"src/test/java",
"src/bld/java",
"src/bld/resources"
],
"java.configuration.updateBuildConfiguration": "automatic",
"java.project.referencedLibraries": [
"${HOME}/.bld/dist/bld-2.2.1.jar",
"lib/**/*.jar",
]
}

62
CHANGELOG.md Normal file
View file

@ -0,0 +1,62 @@
# Changelog
## [1.1.1](https://github.com/ethauvin/httpstatus/tree/1.1.1) (2024-06-07)
[Full Changelog](https://github.com/ethauvin/httpstatus/compare/1.1.0...1.1.1)
**Implemented enhancements:**
- Sort command line output [\#10](https://github.com/ethauvin/HttpStatus/issues/10)
- Update reasons properties status codes [\#9](https://github.com/ethauvin/HttpStatus/issues/9)
## [1.1.0](https://github.com/ethauvin/httpstatus/tree/1.1.0) (2023-09-29)
[Full Changelog](https://github.com/ethauvin/httpstatus/compare/1.0.5...1.1.0)
**Implemented enhancements:**
- Print status code by response classes [\#8](https://github.com/ethauvin/HttpStatus/issues/8)
- Move to Jakarta EE [\#7](https://github.com/ethauvin/HttpStatus/issues/7)
- Only use XML character entities in Utils.escapeXml\(\) [\#6](https://github.com/ethauvin/HttpStatus/issues/6)
- Implement a StatusCode bean to check the status code. [\#5](https://github.com/ethauvin/HttpStatus/issues/5)
## [1.0.5](https://github.com/ethauvin/httpstatus/tree/1.0.5) (2021-03-20)
[Full Changelog](https://github.com/ethauvin/httpstatus/compare/1.0.4...1.0.5)
**Implemented enhancements:**
- Retrieve the error message from the request, if available. [\#4](https://github.com/ethauvin/HttpStatus/issues/4)
- Add Unofficial Codes [\#3](https://github.com/ethauvin/HttpStatus/issues/3)
## [1.0.4](https://github.com/ethauvin/httpstatus/tree/1.0.4) (2019-05-08)
[Full Changelog](https://github.com/ethauvin/httpstatus/compare/1.0.3...1.0.4)
**Implemented enhancements:**
- Implement all INA HTTP status codes [\#1](https://github.com/ethauvin/HttpStatus/issues/1)
**Fixed bugs:**
- hs:reason always outputs the default value. [\#2](https://github.com/ethauvin/HttpStatus/issues/2)
## [1.0.3](https://github.com/ethauvin/httpstatus/tree/1.0.3) (2016-01-22)
[Full Changelog](https://github.com/ethauvin/httpstatus/compare/1.0.2...1.0.3)
## [1.0.2](https://github.com/ethauvin/httpstatus/tree/1.0.2) (2016-01-21)
[Full Changelog](https://github.com/ethauvin/httpstatus/compare/1.0.1...1.0.2)
## [1.0.1](https://github.com/ethauvin/httpstatus/tree/1.0.1) (2015-12-16)
[Full Changelog](https://github.com/ethauvin/httpstatus/compare/1.0...1.0.1)
## [1.0](https://github.com/ethauvin/httpstatus/tree/1.0) (2015-12-04)
[Full Changelog](https://github.com/ethauvin/httpstatus/compare/ad982eff1b27c31b54df4abae00ac2d4065543d6...1.0)
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*

View file

@ -1,129 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="HttpStatus" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="1.0" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/classes/main" />
<output-test url="file://$MODULE_DIR$/build/classes/test" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="Gradle: servletapi:servlet-api:2.4-20040521">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/servletapi/servlet-api/2.4-20040521/d66b0e9c78a90552042ab6f9f2f0afb1d87a268f/servlet-api-2.4-20040521.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Gradle: javax.servlet.jsp:jsp-api:2.2.1-b03">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/javax.servlet.jsp/jsp-api/2.2.1-b03/c7205b380e9ceb4b96745656755f31f76ae01b74/jsp-api-2.2.1-b03.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="Gradle: javax.servlet:servlet-api:2.4-20040521">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/javax.servlet/servlet-api/2.4-20040521/d66b0e9c78a90552042ab6f9f2f0afb1d87a268f/servlet-api-2.4-20040521.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="Gradle: org.testng:testng:6.9.9">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.testng/testng/6.9.9/1bf509349476d6a48978cc2b04af9caa907781ab/testng-6.9.9.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.testng/testng/6.9.9/45c07e00b4cea80ac8715deb749a54d784f7cb6/testng-6.9.9-sources.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="Gradle: junit:junit:4.10">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/junit/junit/4.10/e4f1766ce7404a08f45d859fb9c226fc9e41a861/junit-4.10.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/junit/junit/4.10/6c98d6766e72d5575f96c9479d1c1d3b865c6e25/junit-4.10-sources.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="Gradle: com.beust:jcommander:1.48">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.beust/jcommander/1.48/bfcb96281ea3b59d626704f74bc6d625ff51cbce/jcommander-1.48.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/com.beust/jcommander/1.48/6deefcf90f144dfca29d4950c665a592ba029d42/jcommander-1.48-sources.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="Gradle: org.apache.ant:ant:1.7.0">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.ant/ant/1.7.0/9746af1a485e50cf18dcb232489032a847067066/ant-1.7.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.ant/ant/1.7.0/58ec0e378f1d33cb72a92ee3a9442909789090db/ant-1.7.0-sources.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="Gradle: org.yaml:snakeyaml:1.15">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.yaml/snakeyaml/1.15/3b132bea69e8ee099f416044970997bde80f4ea6/snakeyaml-1.15.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.yaml/snakeyaml/1.15/7dc55271cad1cf73bb495e372164269e75d9345a/snakeyaml-1.15-sources.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="Gradle: org.beanshell:bsh:2.0b4">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.beanshell/bsh/2.0b4/a05f0a0feefa8d8467ac80e16e7de071489f0d9c/bsh-2.0b4.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="Gradle: org.hamcrest:hamcrest-core:1.1">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.1/860340562250678d1a344907ac75754e259cdb14/hamcrest-core-1.1.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.hamcrest/hamcrest-core/1.1/2ccf1154d1a8936042a8a742dc3e611d02ac7213/hamcrest-core-1.1-sources.jar!/" />
</SOURCES>
</library>
</orderEntry>
<orderEntry type="module-library" scope="TEST">
<library name="Gradle: org.apache.ant:ant-launcher:1.7.0">
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.apache.ant/ant-launcher/1.7.0/e7e30789211e074aa70ef3eaea59bd5b22a7fa7a/ant-launcher-1.7.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View file

@ -1,272 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<option name="DEFAULT_COMPILER" value="Javac" />
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />
<entry name="!?*.flex" />
<entry name="!?*.kt" />
<entry name="!?*.clj" />
<entry name="!?*.aj" />
</wildcardResourcePatterns>
<annotationProcessing>
<profile default="true" name="Default" enabled="false">
<processorPath useClasspath="true" />
</profile>
</annotationProcessing>
</component>
<component name="CopyrightManager" default="Erik's Copyright Notice">
<copyright>
<option name="myName" value="Erik's Copyright Notice" />
<option name="notice" value="&amp;#36;file.fileName&#10;&#10;Copyright (c) &amp;#36;today.year, Erik C. Thauvin (erik@thauvin.net)&#10;All rights reserved.&#10;&#10;Redistribution and use in source and binary forms, with or without&#10;modification, are permitted provided that the following conditions are&#10;met:&#10;&#10;Redistributions of source code must retain the above copyright notice,&#10;this list of conditions and the following disclaimer.&#10;&#10;Redistributions in binary form must reproduce the above copyright notice,&#10;this list of conditions and the following disclaimer in the documentation&#10;and/or other materials provided with the distribution.&#10;&#10;Neither the name of the author nor the names of its contributors may be&#10;used to endorse or promote products derived from this software without&#10;specific prior written permission.&#10;&#10;THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS &quot;AS&#10;IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,&#10;THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR&#10;PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR&#10;CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&#10;EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&#10;PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&#10;PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&#10;LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&#10;NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&#10;SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." />
<option name="allowReplaceKeyword" value="Erik C. Thauvin" />
</copyright>
<module2copyright>
<element module="Source" copyright="Erik's Copyright Notice" />
</module2copyright>
<LanguageOptions name="JAVA">
<option name="fileTypeOverride" value="3" />
<option name="addBlankAfter" value="false" />
</LanguageOptions>
<LanguageOptions name="XML">
<option name="fileTypeOverride" value="3" />
<option name="addBlankAfter" value="false" />
<option name="prefixLines" value="false" />
</LanguageOptions>
</component>
<component name="DependencyValidationManager">
<scope name="Source" pattern="file[HttpStatus]:src/main/java/*.java||file[HttpStatus]:src/test/java/*.java||file:src/main/resources/META-INF/httpstatus.tld" />
</component>
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="createEmptyContentRootDirectories" value="true" />
<option name="disableWrapperSourceDistributionNotification" value="true" />
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleHome" value="C:/gradle" />
<option name="gradleJvm" value="#JAVA_HOME" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
<option name="useAutoImport" value="true" />
<option name="myModules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<option name="myLocal" value="true" />
<inspection_tool class="FieldMayBeFinal" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="JavaDoc" enabled="true" level="WARNING" enabled_by_default="true">
<option name="TOP_LEVEL_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="INNER_CLASS_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="METHOD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="@return@param@throws or @exception" />
</value>
</option>
<option name="FIELD_OPTIONS">
<value>
<option name="ACCESS_JAVADOC_REQUIRED_FOR" value="none" />
<option name="REQUIRED_TAGS" value="" />
</value>
</option>
<option name="IGNORE_DEPRECATED" value="false" />
<option name="IGNORE_JAVADOC_PERIOD" value="true" />
<option name="IGNORE_DUPLICATED_THROWS" value="false" />
<option name="IGNORE_POINT_TO_ITSELF" value="false" />
<option name="myAdditionalJavadocTags" value="created" />
</inspection_tool>
<inspection_tool class="LocalCanBeFinal" enabled="true" level="WARNING" enabled_by_default="true">
<option name="REPORT_VARIABLES" value="true" />
<option name="REPORT_PARAMETERS" value="false" />
<option name="REPORT_CATCH_PARAMETERS" value="false" />
</inspection_tool>
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
<option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
<option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
</inspection_tool>
<inspection_tool class="UnnecessarySemicolon" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="WeakerAccess" enabled="true" level="WARNING" enabled_by_default="true">
<option name="SUGGEST_PACKAGE_LOCAL_FOR_MEMBERS" value="true" />
<option name="SUGGEST_PACKAGE_LOCAL_FOR_TOP_CLASSES" value="false" />
<option name="SUGGEST_PRIVATE_FOR_INNERS" value="false" />
</inspection_tool>
</profile>
<option name="PROJECT_PROFILE" value="Project Default" />
<option name="USE_PROJECT_PROFILE" value="true" />
<version value="1.0" />
</component>
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/HttpStatus.iml" filepath="$PROJECT_DIR$/HttpStatus.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.8.x" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

27
LICENSE.txt Normal file
View file

@ -0,0 +1,27 @@
Copyright (c) 2015-2025, 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.

421
README.md
View file

@ -1,8 +1,37 @@
# HttpStatus JSP Tag Library
A simple JSP Tag Library to display the reason of [HTTP status codes](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) in JSP error pages.
[![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg?style=flat-square)](http://opensource.org/licenses/BSD-3-Clause)
[![Java](https://img.shields.io/badge/java-17%2B-blue)](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html)
[![bld](https://img.shields.io/badge/2.2.1-FA9052?label=bld&labelColor=2392FF)](https://rife2.com/bld)
[![Release](https://img.shields.io/github/release/ethauvin/httpstatus.svg)](https://github.com/ethauvin/httpstatus/releases/latest)
[![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/net.thauvin.erik.httpstatus/httpstatus.svg?label=sanpshot&server=https%3A%2F%2Foss.sonatype.org)](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/httpstatus/httpstatus/)
[![Maven Central](https://img.shields.io/maven-central/v/net.thauvin.erik.httpstatus/httpstatus.svg?color=blue)](https://central.sonatype.com/artifact/net.thauvin.erik.httpstatus/httpstatus)
----
[![Known Vulnerabilities](https://snyk.io/test/github/ethauvin/httpstatus/badge.svg?targetFile=pom.xml)](https://snyk.io/test/github/ethauvin/httpstatus?targetFile=pom.xml)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ethauvin_HttpStatus&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=ethauvin_HttpStatus)
[![GitHub CI](https://github.com/ethauvin/httpstatus/actions/workflows/bld.yml/badge.svg)](https://github.com/ethauvin/httpstatus/actions/workflows/bld.yml)
[![CircleCI](https://circleci.com/gh/ethauvin/HttpStatus/tree/master.svg?style=shield)](https://circleci.com/gh/ethauvin/HttpStatus/tree/master)
A simple [JSP](http://www.oracle.com/technetwork/java/javaee/jsp/index.html) Tag Library to display the [code](#hscode), [reason](#hsreason), [cause](#hscode) and/or [message](#hsmessage) for [HTTP status codes](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) in JSP error pages.
## Table of Contents
- [Examples](#examples)
- [Usage](#usage)
- [Gradle](#gradle)
- [bld](#bld)
- [Maven](#maven)
- [JSP Tags](#jsp-tags)
- [hs:cause](#hscause)
- [hs:code](#hscode)
- [hs:message](#hsmessage)
- [hs:reason](#hsreason)
- [StatusCode Bean](#statuscode-bean)
- [Reasons](#reasons)
- [Command Line Usage](#command-line-usage)
- [Contributing](#contributing)
## Examples
For example:
@ -14,6 +43,7 @@ For example:
</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>
...
```
@ -24,13 +54,53 @@ or
<%= Reasons.getReasonPhrase(pageContext.getErrorData().getStatusCode()) %>
```
would display on a [501 status code](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.2):
would display on a [501 status code](https://www.rfc-editor.org/rfc/rfc9110.html#name-501-not-implemented):
```console
Not Implemented
```
----
## Usage
## hs:cause
### [Gradle](https://gradle.org/)
Include the following in your `build.gradle` file:
```gradle
repositories {
mavenCentral()
}
dependencies {
implementation 'net.thauvin.erik.httpstatus:httpstatus:1.1.1'
}
```
### [bld](https://rife2.com/bld)
Include the following in your `bld` build file:
```java
scope(compile).include(
dependency("net.thauvin.erik.httpstatus","httpstatus", version(1, 1, 0))
);
```
### [Maven](http://maven.apache.org/)
As a `Maven` artifact:
```xml
<dependency>
<groupId>net.thauvin.erik.httpstatus</groupId>
<artifactId>httpstatus</artifactId>
<version>1.1.1</version>
</dependency>
```
## JSP Tags
### hs:cause
The `<hs:cause/>` tag displays the cause of current HTTP status code, if any. A shorthand for:
@ -40,107 +110,262 @@ The `<hs:cause/>` tag displays the cause of current HTTP status code, if any. A
Optional attributes are:
Attribute | Description
----------- | -------------------------------------------------------------------------------------------
`default` | The fallback value to output, if no cause is available.
`escapeXml` | Converts &lt;,&gt;,&amp;,'," to their corresponding [entity codes](http://dev.w3.org/html5/html-author/charref). Value is true by default.
| Attribute | Description |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `default` | The fallback value to output, if no cause is |
| `escapeXml` | Converts &lt;, &gt;, &amp;, ', " to their corresponding [entity codes](http://dev.w3.org/html5/html-author/charref). Value is `true` by default. |
### hs:code
## hs:code
The `<hs:code/>` tag displays the current HTTP status code, if any. A shorthand for:
```jsp
<%= pageContext.getErrorData().getStatusCode() %>
```
## hs:reason
### hs:message
The `<hs:reason/>` tag displays the reason for a HTTP status code, if any. Optional attributes are:
The `<hs:message/>` tag displays the current error message, if any. A shorthand for:
Attribute | Description
----------- | -------------------------------------------------------------------------------------------
`code` | The HTTP status error code. If not specified the current status code is used.
`default` | The fallback value to output, if no reason is available.
`escapeXml` | Converts &lt;,&gt;,&amp;,'," to their corresponding [entity codes](http://dev.w3.org/html5/html-author/charref). Value is true by default.
```jsp
<%= request.getAttribute("javax.servlet.error.message") %>
```
The reasons are defined in a [ResourceBundle](http://docs.oracle.com/javase/8/docs/api/java/util/ResourceBundle.html) properties as follows:
Optional attributes are:
Status Code | Reason
----------- | -------------------------------
`100` | Continue
`101` | Switching Protocols
`102` | Processing
`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
`300` | Multiple Choices
`301` | Moved Permanently
`302` | Moved Temporarily
`303` | See Other
`304` | Not Modified
`305` | Use Proxy
`306` | Switch Proxy
`307` | Temporary Redirect
`308` | Permanent Redirect
`400` | Bad Request
`401` | Unauthorized
`402` | Payment Required
`403` | Forbidden
`404` | Not Found
`405` | Method Not Allowed
`406` | Not Acceptable
`407` | Proxy Authentication Required
`408` | Request Timeout
`409` | Conflict
`410` | Gone
`411` | Length Required
`412` | Precondition Failed
`413` | Request Entity Too Large
`414` | Request-URI Too Long
`415` | Unsupported Media Type
`416` | Requested Range Not Satisfiable
`417` | Expectation Failed
`418` | I'm A Teapot
`419` | Insufficient Space on Resource
`420` | Method Failure
`421` | Misdirected Request
`422` | Unprocessable Entity
`423` | Locked
`424` | Failed Dependency
`426` | Upgrade Required
`428` | Precondition Required
`429` | Too Many Requests
`431` | Request Header Fields Too Large
`440` | Login Timeout
`444` | No Response
`449` | Retry With
`450` | Blocked by Windows Parental Controls
`451` | Unavailable For Legal Reasons
`494` | Request Header Too Large
`495` | Cert Error
`496` | No Cert
`497` | HTTP to HTTPS
`498` | Token Expired/Invalid
`499` | Client Closed Request
`500` | Internal Server Error
`501` | Not Implemented
`502` | Bad Gateway
`503` | Service Unavailable
`504` | Gateway Timeout
`505` | HTTP Version Not Supported
`506` | Variant Also Negotiates
`507` | Insufficient Storage
`508` | Loop Detected
`509` | Bandwidth Limit Exceeded
`510` | Not Extended
`511` | Network Authentication Required
`520` | Unknown Error
`522` | Origin Connection Time-out
`598` | Network Read Timeout Error
`599` | Network Connect Timeout Error
| Attribute | Description |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `default` | The fallback value to output, if no error message is available. |
| `escapeXml` | Converts &lt;, &gt;, &amp;, ', " to their corresponding [entity codes](http://dev.w3.org/html5/html-author/charref). Value is `true` by default. |
### hs:reason
The `<hs:reason/>` tag displays the reason for an HTTP status code, if any. Optional attributes are:
| Attribute | Description |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| `default` | The fallback value to output, if no reason is available. |
| `code` | The HTTP status error code. If not specified the current status code is used. |
| `escapeXml` | Converts &lt;, &gt;, &amp;, ', " 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" %>
<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()}">
An error occurred on your side. (<hs:reason/>)
</c:when>
<c:otherwise>
An error occurred on our side. (<hs:message/>)
</c:otherwise>
</c:choose>
```
or in a Servlet:
```java
import net.thauvin.erik.httpstatus.StatusCode;
public class ExampleServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) {
var statusCode = new StatusCode(
(Integer) request.getAttribute("javax.servlet.error.status_code"));
if (statusCode.isError()) {
if (statusCode.isServerError()) {
var 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](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/ResourceBundle.html) properties as follows:
| Status Code | Reason |
| ----------- | ---------------------------------------------------------- |
| `100` | Continue |
| `101` | Switching Protocols |
| `102` | Processing |
| `103` | Early Hints |
| `110` | Response is Stale |
| `111` | Revalidation Failed |
| `112` | Disconnected Operation |
| `113` | Heuristic Expiration |
| `199` | Miscellaneous Warning |
| `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 |
| `214` | Transformation Applied |
| `218` | This is fine |
| `226` | IM Used |
| `299` | Miscellaneous Persistent Warning |
| `300` | Multiple Choices |
| `301` | Moved Permanently |
| `302` | Found/Moved Temporarily |
| `303` | See Other |
| `304` | Not Modified |
| `305` | Use Proxy |
| `306` | Unused |
| `307` | Temporary Redirect |
| `308` | Permanent Redirect |
| `400` | Bad Request |
| `401` | Unauthorized |
| `402` | Payment Required |
| `403` | Forbidden |
| `404` | Not Found |
| `405` | Method Not Allowed |
| `406` | Not Acceptable |
| `407` | Proxy Authentication Required |
| `408` | Request Timeout |
| `409` | Conflict |
| `410` | Gone |
| `411` | Length Required |
| `412` | Precondition Failed |
| `413` | Payload Too Large |
| `414` | URI Too Long |
| `415` | Unsupported Media Type |
| `416` | Range Not Satisfiable |
| `417` | Expectation Failed |
| `418` | I'm A Teapot |
| `419` | Insufficient Space on Resource |
| `420` | Method Failure |
| `421` | Misdirected Request |
| `422` | Unprocessable Content |
| `423` | Locked |
| `424` | Failed Dependency |
| `425` | Too Early |
| `426` | Upgrade Required |
| `428` | Precondition Required |
| `429` | Too Many Requests |
| `430` | Request Header Fields Too Large |
| `431` | Request Header Fields Too Large |
| `440` | Login Timeout |
| `444` | No Response |
| `449` | Retry With |
| `450` | Blocked by Windows Parental Controls |
| `451` | Unavailable For Legal Reasons |
| `460` | Client Closed Connection Before Load Balancer Idle Timeout |
| `463` | X-Forwarded-For Header with More than 30 IP Addresses |
| `494` | Request Header Too Large |
| `495` | SSL Certificate Error |
| `496` | SSL Certificate Required |
| `497` | HTTP Request Sent to HTTPS Port |
| `498` | Token Expired/Invalid |
| `499` | Client Closed Request |
| `500` | Internal Server Error |
| `501` | Not Implemented |
| `502` | Bad Gateway |
| `503` | Service Unavailable |
| `504` | Gateway Timeout |
| `505` | HTTP Version Not Supported |
| `506` | Variant Also Negotiates |
| `507` | Insufficient Storage |
| `508` | Loop Detected |
| `509` | Bandwidth Limit Exceeded |
| `510` | Not Extended |
| `511` | Network Authentication Required |
| `520` | Unknown Error |
| `521` | Web Server Is Down |
| `522` | Connection Timed Out |
| `523` | Origin Is Unreachable |
| `524` | A Timeout Occurred |
| `525` | SSL Handshake Failed |
| `526` | Invalid SSL Certificate |
| `527` | Railgun Error |
| `529` | Site is overloaded |
| `530` | Site is frozen |
| `540` | Temporarily Disabled |
| `561` | Unauthorized |
| `598` | Network Read Timeout Error |
| `599` | Network Connect Timeout Error |
| `783` | Unexpected Token |
## Command Line Usage
You can query the reason phrase for status codes as follows:
```console
$ java -jar httpstatus-1.1.1.jar 404 500
404: Not Found
500: Internal Server Error
```
If no status code is specified, all will be printed:
```console
$ java -jar httpstatus-1.1.1.jar
100: Continue
101: Switching Protocols
102: Processing
103: Early Hints
110: Response is Stale
111: Revalidation Failed
112: Disconnected Operation
113: Heuristic Expiration
199: Miscellaneous Warning
200: OK
201: Created
202: Accepted
203: Non-Authoritative Information
...
```
You can also print status codes by [response classes](https://www.rfc-editor.org/rfc/rfc9110.html#name-status-codes):
```console
$ java -jar httpstatus-1.1.1.jar 2xx
200: OK
201: Created
202: Accepted
203: Non-Authoritative Information
...
```
## Contributing
If you want to contribute to this project, all you have to do is clone the GitHub
repository:
```console
git clone git@github.com:ethauvin/HttpStatus.git
```
Then use [bld](https://rife2.com/bld) to build:
```console
cd HttpStatus
./bld compile
```
The project has an [IntelliJ IDEA](https://www.jetbrains.com/idea/) project structure. You can just open it after all
the dependencies were downloaded and peruse the code.

2
bld Executable file
View file

@ -0,0 +1,2 @@
#!/usr/bin/env sh
java -jar "$(dirname "$0")/lib/bld/bld-wrapper.jar" "$0" --build net.thauvin.erik.httpstatus.HttpStatusBuild "$@"

4
bld.bat Normal file
View file

@ -0,0 +1,4 @@
@echo off
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
java -jar "%DIRNAME%/lib/bld/bld-wrapper.jar" "%0" --build net.thauvin.erik.httpstatus.HttpStatusBuild %*

View file

@ -1,84 +0,0 @@
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'
defaultTasks 'deploy'
version = '1.0'
def deployDir = 'deploy'
def buildProp = 'build'
def buildProps = 'buildnumber.properties'
def isRelease = 'release' in gradle.startParameter.taskNames
mainClassName = 'net.thauvin.erik.httpstatus.Reasons'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
repositories {
mavenCentral()
}
dependencies {
compile 'servletapi:servlet-api:+'
compile 'javax.servlet.jsp:jsp-api:+'
testCompile 'org.testng:testng:+'
}
compileJava {
doFirst {
if (isRelease)
{
ant.propertyfile(file: buildProps) {
entry(key: buildProp,
type: 'int',
default: '-1',
operation: '+')
}
}
}
//options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
jar {
def props = new Properties()
file(buildProps).withInputStream { stream -> props.load(stream) }
version = version + '.' + props.get(buildProp)
archiveName = archiveName.toLowerCase()
manifest.attributes('Main-Class': mainClassName)
}
clean {
delete deployDir
}
test {
useTestNG()
}
task wrapper(type: Wrapper) {
gradleVersion = gradle.gradleVersion
}
task copyToDeploy(type: Copy) {
from(configurations.runtime) {
exclude 'servlet-api-*.jar'
exclude 'jsp-api-*.jar'
}
from jar
into deployDir
}
task deploy(dependsOn: ['build', 'copyToDeploy']) {
description = "Copies all needed files to the ${deployDir} directory."
group = "Publishing"
outputs.dir deployDir
inputs.files copyToDeploy
mustRunAfter clean
}
task release(dependsOn: ['deploy', 'wrapper']) {
group = "Publishing"
description = "Releases new version."
}

View file

@ -1,2 +0,0 @@
#Wed, 02 Dec 2015 15:38:42 -0800
build=0

109
config/pmd.xml Normal file
View file

@ -0,0 +1,109 @@
<?xml version="1.0"?>
<ruleset name="erik"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>Erik's Ruleset</description>
<!-- BEST PRACTICES -->
<rule ref="category/java/bestpractices.xml">
<exclude name="AvoidPrintStackTrace"/>
<exclude name="GuardLogStatement"/>
<exclude name="UnitTestContainsTooManyAsserts"/>
<exclude name="UnitTestShouldUseTestAnnotation"/>
</rule>
<rule ref="category/java/bestpractices.xml/MissingOverride">
<properties>
<property name="violationSuppressXPath"
value="//MethodDeclaration[@Name='hashCode' or @Name='equals' or @Name='toString']"/>
</properties>
</rule>
<!-- CODE STYLE -->
<rule ref="category/java/codestyle.xml">
<exclude name="AtLeastOneConstructor"/>
<exclude name="ClassNamingConventions"/>
<exclude name="CommentDefaultAccessModifier"/>
<exclude name="ConfusingTernary"/>
<exclude name="FieldNamingConventions"/>
<exclude name="LocalVariableCouldBeFinal"/>
<exclude name="LongVariable"/>
<exclude name="MethodArgumentCouldBeFinal"/>
<exclude name="OnlyOneReturn"/>
<exclude name="PackageCase"/>
<exclude name="ShortClassName"/>
<exclude name="ShortMethodName"/>
<exclude name="ShortVariable"/>
<exclude name="UseExplicitTypes"/>
<exclude name="UseUnderscoresInNumericLiterals"/>
<exclude name="UselessParentheses"/>
</rule>
<rule ref="category/java/codestyle.xml/UnnecessaryImport">
<properties>
<property name="violationSuppressRegex" value="Unused (static|.*\.\*).*"/>
</properties>
</rule>
<!-- DESIGN -->
<rule ref="category/java/design.xml">
<exclude name="AvoidCatchingGenericException"/>
<exclude name="AvoidDeeplyNestedIfStmts"/>
<exclude name="AvoidUncheckedExceptionsInSignatures"/>
<exclude name="CognitiveComplexity"/>
<exclude name="CyclomaticComplexity"/>
<exclude name="ExcessiveParameterList"/>
<exclude name="ExcessivePublicCount"/>
<exclude name="GodClass"/>
<exclude name="LawOfDemeter"/>
<exclude name="LoosePackageCoupling"/>
<exclude name="NPathComplexity"/>
<exclude name="NcssCount"/>
<exclude name="TooManyFields"/>
<exclude name="TooManyMethods"/>
<exclude name="UseObjectForClearerAPI"/>
</rule>
<!-- DOCUMENTATION -->
<rule ref="category/java/documentation.xml">
<exclude name="CommentRequired"/>
<exclude name="CommentSize"/>
</rule>
<!-- ERROR PRONE -->
<rule ref="category/java/errorprone.xml">
<exclude name="AssignmentInOperand"/>
<exclude name="AvoidCatchingNPE"/>
<exclude name="AvoidDuplicateLiterals"/>
<exclude name="AvoidFieldNameMatchingMethodName"/>
<exclude name="AvoidFieldNameMatchingTypeName"/>
<exclude name="AvoidLiteralsInIfCondition"/>
<exclude name="NullAssignment"/>
</rule>
<rule ref="category/java/errorprone.xml/AssignmentInOperand">
<properties>
<property name="allowWhile" value="true"/>
<property name="allowFor" value="true"/>
<property name="allowIf" value="true"/>
</properties>
</rule>
<rule ref="category/java/errorprone.xml/AvoidDuplicateLiterals">
<properties>
<property name="skipAnnotations" value="true"/>
</properties>
</rule>
<!-- MULTITHREADING -->
<rule ref="category/java/multithreading.xml">
</rule>
<!-- PERFORMANCE -->
<rule ref="category/java/performance.xml">
</rule>
<!-- SECURITY -->
<rule ref="category/java/security.xml">
</rule>
</ruleset>

Binary file not shown.

View file

@ -1,6 +0,0 @@
#Wed Dec 02 13:19:10 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip

160
gradlew vendored
View file

@ -1,160 +0,0 @@
#!/usr/bin/env bash
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn ( ) {
echo "$*"
}
die ( ) {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
esac
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
function splitJvmOpts() {
JVM_OPTS=("$@")
}
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"

90
gradlew.bat vendored
View file

@ -1,90 +0,0 @@
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windowz variants
if not "%OS%" == "Windows_NT" goto win9xME_args
if "%@eval[2+2]" == "4" goto 4NT_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
goto execute
:4NT_args
@rem Get arguments from the 4NT Shell from JP Software
set CMD_LINE_ARGS=%$
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

BIN
lib/bld/bld-wrapper.jar Normal file

Binary file not shown.

View file

@ -0,0 +1,7 @@
bld.downloadExtensionJavadoc=false
bld.downloadExtensionSources=true
bld.downloadLocation=
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.10
bld.extension-pmd=com.uwyn.rife2:bld-pmd:1.2.3
bld.repositories=MAVEN_CENTRAL,RIFE2_RELEASES,MAVEN_LOCAL,RIFE2_SNAPSHOTS
bld.version=2.2.1

50
pom.xml Normal file
View file

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>net.thauvin.erik.httpstatus</groupId>
<artifactId>httpstatus</artifactId>
<version>1.1.2-SNAPSHOT</version>
<name>HttpStatus</name>
<description>Tag library to display the code, reason, cause and/or message for HTTP status codes in JSP error pages</description>
<url>https://github.com/ethauvin/HttpStatus</url>
<licenses>
<license>
<name>The BSD 3-Clause License</name>
<url>https://opensource.org/licenses/BSD-3-Clause</url>
</license>
</licenses>
<dependencies>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jakarta.servlet.jsp</groupId>
<artifactId>jakarta.servlet.jsp-api</artifactId>
<version>4.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>jakarta.el</groupId>
<artifactId>jakarta.el-api</artifactId>
<version>6.0.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<developers>
<developer>
<id>ethauvin</id>
<name>Erik C. Thauvin</name>
<email>erik@thauvin.net</email>
<url>https://erik.thauvin.net/</url>
</developer>
</developers>
<scm>
<connection>scm:git:https://github.com/ethauvin/HttpStatus.git</connection>
<developerConnection>scm:git:git@github.com:ethauvin/HttpStatus.git</developerConnection>
<url>https://github.com/ethauvin/HttpStatus</url>
</scm>
</project>

View file

@ -1,19 +0,0 @@
/*
* This settings file was auto generated by the Gradle buildInit task
* by 'erik' at '12/2/15 1:19 PM' with Gradle 2.9
*
* The settings file is used to specify which projects to include in your build.
* In a single project build this file can be empty or even removed.
*
* Detailed information about configuring a multi-project build in Gradle can be found
* in the user guide at https://docs.gradle.org/2.9/userguide/multi_project_builds.html
*/
/*
// To declare projects as part of a multi-project build use the 'include' method
include 'shared'
include 'api'
include 'services:webservice'
*/
rootProject.name = 'HttpStatus'

7
sonar-project.properties Normal file
View file

@ -0,0 +1,7 @@
sonar.organization=ethauvin-github
sonar.projectKey=ethauvin_HttpStatus
sonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/test/jacocoTestReport.xml
sonar.sources=src/main/java/
sonar.tests=src/test/java/
sonar.java.binaries=build/main,build/test
sonar.java.libraries=lib/compile/*.jar

View file

@ -0,0 +1,157 @@
/*
* HttpStatusBuild.java
*
* Copyright 2015-2025 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 rife.bld.BuildCommand;
import rife.bld.Project;
import rife.bld.extension.JacocoReportOperation;
import rife.bld.extension.PmdOperation;
import rife.bld.publish.*;
import rife.tools.exceptions.FileUtilsErrorException;
import java.io.File;
import java.util.List;
import java.util.jar.Attributes;
import static rife.bld.dependencies.Repository.*;
import static rife.bld.dependencies.Scope.compile;
import static rife.bld.dependencies.Scope.test;
import static rife.bld.operations.JavadocOptions.DocLinkOption.NO_MISSING;
public class HttpStatusBuild extends Project {
final PmdOperation pmdOp = new PmdOperation()
.fromProject(this)
.failOnViolation(true)
.ruleSets("config/pmd.xml");
public HttpStatusBuild() {
pkg = "net.thauvin.erik.httpstatus";
name = "HttpStatus";
version = version(1, 1, 2, "SNAPSHOT");
var description = "Tag library to display the code, reason, cause and/or message for HTTP status codes in JSP error pages";
var url = "https://github.com/ethauvin/HttpStatus";
mainClass = "net.thauvin.erik.httpstatus.Reasons";
javaRelease = 17;
downloadSources = true;
autoDownloadPurge = true;
repositories = List.of(MAVEN_CENTRAL, SONATYPE_SNAPSHOTS);
scope(compile)
.include(dependency("jakarta.servlet", "jakarta.servlet-api", version(6, 1, 0)))
.include(dependency("jakarta.servlet.jsp", "jakarta.servlet.jsp-api", version(4, 0, 0)))
.include(dependency("jakarta.el", "jakarta.el-api", version(6, 0, 1)));
scope(test)
.include(dependency("org.assertj", "assertj-core", version(3, 27, 3)))
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 12, 2)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 12, 2)));
jarOperation().manifestAttribute(Attributes.Name.MAIN_CLASS, pkg + '.' + "Reasons");
javadocOperation().javadocOptions()
.docTitle(description + ' ' + version.toString())
.docLint(NO_MISSING)
.link("https://jakarta.ee/specifications/platform/9/apidocs/");
publishOperation()
.repository(version.isSnapshot() ? repository(SONATYPE_SNAPSHOTS_LEGACY.location())
.withCredentials(property("sonatype.user"), property("sonatype.password"))
: repository(SONATYPE_RELEASES_LEGACY.location())
.withCredentials(property("sonatype.user"), property("sonatype.password")))
.repository(repository("github"))
.info(new PublishInfo()
.groupId(pkg)
.artifactId(name.toLowerCase())
.name(name)
.version(version)
.description(description)
.url(url)
.developer(new PublishDeveloper()
.id("ethauvin")
.name("Erik C. Thauvin")
.email("erik@thauvin.net")
.url("https://erik.thauvin.net/")
)
.license(new PublishLicense()
.name("The BSD 3-Clause License")
.url("https://opensource.org/licenses/BSD-3-Clause")
)
.scm(new PublishScm()
.connection("scm:git:" + url + ".git")
.developerConnection("scm:git:git@github.com:ethauvin/" + name + ".git")
.url(url))
.signKey(property("sign.key"))
.signPassphrase(property("sign.passphrase")));
}
public static void main(String[] args) {
new HttpStatusBuild().start(args);
}
@BuildCommand(summary = "Generates JaCoCo Reports")
public void jacoco() throws Exception {
new JacocoReportOperation()
.fromProject(this)
.execute();
}
@BuildCommand(summary = "Runs PMD analysis")
public void pmd() throws Exception {
pmdOp.execute();
}
@BuildCommand(value = "pmd-cli", summary = "Runs PMD analysis (CLI)")
public void pmdCli() throws Exception {
pmdOp.includeLineNumber(false).execute();
}
private void pomRoot() throws FileUtilsErrorException {
PomBuilder.generateInto(publishOperation().fromProject(this).info(), dependencies(),
new File(workDirectory, "pom.xml"));
}
@Override
public void publish() throws Exception {
super.publish();
pomRoot();
}
@Override
public void publishLocal() throws Exception {
super.publishLocal();
pomRoot();
}
}

View file

@ -1,102 +1,122 @@
/*
* Reasons.java
*
* Copyright (c) 2015, Erik C. Thauvin (erik@thauvin.net)
* Copyright 2015-2025 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:
* 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 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 the author nor the names of its contributors may be
* 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 OWNER 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.
* 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.util.Map;
import java.util.ResourceBundle;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
/**
* The <code>Reasons</code> class.
* Populates the {@link #REASON_PHRASES reason phrases} map from {@link #BUNDLE_BASENAME bundle properties}, and
* implements accessor methods.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @created 2015-12-02
* @since 1.0
*/
public class Reasons
{
public final class Reasons {
/**
* The resource bundle base name.
*/
static final String BUNDLE_BASENAME = "net.thauvin.erik.httpstatus.reasons";
/**
* The reason phrases map.
*/
private static final Map<String, String> REASON_PHRASES = new TreeMap<String, String>();
private static final Map<String, String> REASON_PHRASES = new ConcurrentHashMap<>();
// Initializes the reason phrases map.
static {
var bundle = ResourceBundle.getBundle(BUNDLE_BASENAME);
for (var key : bundle.keySet()) {
REASON_PHRASES.put(key, bundle.getString(key));
}
}
/**
* Gets the reason phrase for the specified status code.
* Disables the default constructor.
*/
private Reasons() {
throw new UnsupportedOperationException("Illegal constructor call.");
}
/**
* Returns the reason phrase for the specified status code.
*
* @param statusCode The status code.
*
* @return The reason phrase, or <code>null</code>.
*/
public static String getReasonPhrase(int statusCode)
{
public static String getReasonPhrase(int statusCode) {
return getReasonPhrase(Integer.toString(statusCode));
}
/**
* Gets the reason phrase for the specified status code.
* Returns the reason phrase for the specified status code.
*
* @param statusCode The status code.
*
* @return The reason phrase, or <code>null</code>.
*/
public static String getReasonPhrase(String statusCode)
{
public static String getReasonPhrase(String statusCode) {
return REASON_PHRASES.get(statusCode);
}
/**
* Outputs the status codes and reason phrases.
* Prints the reason phrase for the given status code(s).
*
* @param args The command line arguments.
* @param args The status code(s) or response class(es), prints all if none.
*/
public static void main(String[] args)
{
for (final Map.Entry<String, String> entry : REASON_PHRASES.entrySet())
{
System.out.println(entry.getKey() + ": " + entry.getValue());
@SuppressWarnings("PMD.SystemPrintln")
public static void main(String... args) {
var keys = new TreeSet<>(REASON_PHRASES.keySet());
if (args.length >= 1) {
for (var arg : args) {
if (arg.endsWith("xx")) { // e.g.: 2xx
var responseClass = arg.charAt(0);
keys.forEach(k -> {
if (k.charAt(0) == responseClass) {
System.out.println(k + ": " + REASON_PHRASES.get(k));
}
}
/**
* Initializes the reason phrases map.
*/
static
{
final ResourceBundle bundle = ResourceBundle.getBundle("net.thauvin.erik.httpstatus.reasons");
for (final String key : bundle.keySet())
{
REASON_PHRASES.put(key, bundle.getString(key));
});
} else { // e.g.: 404
var value = REASON_PHRASES.get(arg);
if (value != null) {
System.out.println(arg + ": " + value);
}
}
}
} else { // Print all
keys.forEach(k -> System.out.println(k + ": " + REASON_PHRASES.get(k)));
System.out.println("Total: " + REASON_PHRASES.size());
}
}
}

View file

@ -0,0 +1,153 @@
/*
* StatusCode.java
*
* Copyright 2015-2025 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.Serial;
import java.io.Serializable;
/**
* The <code>StatusCode</code> bean implements methods to check the class of an HTTP status code.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @since 1.1.0
*/
public class StatusCode implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private int code;
/**
* Creates a new StatusCode object.
*/
public StatusCode() {
// Default constructor.
}
/**
* Creates a new StatusCode object.
*
* @param code The status code.
*/
public StatusCode(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 <code>null</code>.
* @see Reasons#getReasonPhrase(int)
*/
public String getReason() {
return Reasons.getReasonPhrase(code);
}
/**
* Checks if the status code is a client error. (eg: <code>Internal Server Error</code>)
*
* @return <code>true</code> if the status code is a client error, <code>false</code> otherwise.
*/
public boolean isClientError() {
return code >= 400 && code < 500;
}
/**
* Checks if the status code is a client or server error.
*
* @return <code>true</code> if the status code is an error, <code>false</code> otherwise.
*/
public boolean isError() {
return code >= 400 && code < 600;
}
/**
* Checks if the status code is informational.
*
* @return <code>true</code> if the status code is informational, <code>false</code> otherwise.
*/
public boolean isInfo() {
return code >= 100 && code < 200;
}
/**
* Checks if the status code is a redirect.
*
* @return <code>true</code> if the status code is a redirect, <code>false</code> otherwise.
*/
public boolean isRedirect() {
return code >= 300 && code < 400;
}
/**
* Checks if the status code is a server error.
*
* @return <code>true</code> if the status code is a server error, <code>false</code> otherwise.
*/
public boolean isServerError() {
return code >= 500 && code < 600;
}
/**
* Checks if the status code is a (<code>OK</code>) success.
*
* @return <code>true</code> if the status code is a success, <code>false</code> otherwise.
*/
public boolean isSuccess() {
return code >= 200 && code < 300;
}
/**
* Checks if the status code is valid.
*
* @return <code>true</code> if the status code is valid, <code>false</code> otherwise.
*/
public boolean isValid() {
return code == 783 || (code >= 100 && code < 600);
}
/**
* Sets the status code.
*
* @param code The HTTP status code.
*/
public void setCode(int code) {
this.code = code;
}
}

View file

@ -1,134 +1,97 @@
/*
* Utils.java
*
* Copyright (c) 2015, Erik C. Thauvin (erik@thauvin.net)
* Copyright 2015-2025 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:
* 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 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 the author nor the names of its contributors may be
* 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 OWNER 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.
* 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.IOException;
import java.io.Writer;
/**
* The <code>Utils</code> class.
* The <code>Utils</code> class implements a collection of utility methods used throughout this project.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @created 2015-12-03
* @since 1.0
*/
public class Utils
{
public final class Utils {
/**
* Disables the default constructor.
*
* @throws UnsupportedOperationException if an error occurred. if the constructor is called.
* @throws UnsupportedOperationException If the constructor is called.
*/
private Utils()
throws UnsupportedOperationException
{
private Utils() {
throw new UnsupportedOperationException("Illegal constructor call.");
}
/**
* Writes a string value.
* Converts <code>&lt;</code>, <code>&gt;</code>, <code>&amp;</code>, <code>'</code>, <code>"</code>
* to their corresponding entity codes.
*
* @param out The writer to output the value to.
* @param value The string value.
* @param defaultValue The default value.
* @param xml The xml flag.
* @param value The string value to convert.
* @return The converted string value.
*/
public static void outWrite(Writer out, String value, String defaultValue, boolean xml)
throws IOException
{
if (xml)
{
if (value != null)
{
out.write(escapeXml(value));
}
else if (defaultValue != null)
{
out.write(escapeXml(defaultValue));
}
}
else
{
if (value != null)
{
out.write(value);
}
else if (defaultValue != null)
{
out.write(defaultValue);
}
}
}
public static String escapeXml(String value) {
var escaped = new StringBuilder();
/**
* Escapes a string value.
*
* @param value The string value to escape.
*
* @return The escaped string value.
*/
public static String escapeXml(String value)
{
final StringBuilder escaped = new StringBuilder();
for (int i = 0; i < value.length(); i++)
{
final char c = value.charAt(i);
switch (c)
{
case '<':
escaped.append("&lt;");
break;
case '>':
escaped.append("&gt;");
break;
case '&':
escaped.append("&amp;");
break;
case '\'':
escaped.append("&#039;");
break;
case '"':
escaped.append("&#034;");
break;
default:
escaped.append(c);
break;
for (var i = 0; i < value.length(); i++) {
var c = value.charAt(i);
switch (c) {
case '<' -> escaped.append("&lt;");
case '>' -> escaped.append("&gt;");
case '&' -> escaped.append("&amp;");
case '\'' -> escaped.append("&apos;");
case '"' -> escaped.append("&quot;");
default -> escaped.append(c);
}
}
return escaped.toString();
}
/**
* Writes a string value to the specified writer. The default value is used when the actual value is null.
*
* @param out The writer to output the value to.
* @param value The string value.
* @param defaultValue The default value.
* @param xml The {@link #escapeXml(String) xml} flag.
* @throws IOException If an I/O error occurs.
*/
public static void outWrite(Writer out, String value, String defaultValue, boolean xml)
throws IOException {
if (value != null) {
out.write(xml ? escapeXml(value) : value);
} else if (defaultValue != null) {
out.write(xml ? escapeXml(defaultValue) : defaultValue);
}
}
}

View file

@ -0,0 +1,11 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML LANG="en">
<HEAD>
<TITLE>HttpStatus JSP Tag Library</TITLE>
</HEAD>
<BODY>
A simple JSP Tag Library to display the code, reason and/or cause for HTTP status codes in JSP error pages.
@since 1.0
</BODY>
</HTML>

View file

@ -1,72 +1,78 @@
/*
* CauseTag.java
*
* Copyright (c) 2015, Erik C. Thauvin (erik@thauvin.net)
* Copyright 2015-2025 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:
* 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 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 the author nor the names of its contributors may be
* 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 OWNER 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.
* 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.taglibs;
import jakarta.servlet.jsp.JspWriter;
import jakarta.servlet.jsp.PageContext;
import net.thauvin.erik.httpstatus.Utils;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import java.io.IOException;
/**
* The <code>CauseTag</code> class.
* The <code>&lt;hs:cause&gt;</code> tag returns the cause (if any) for the current HTTP Status Error Code.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @created 2015-12-03
* @since 1.0
*/
public class CauseTag extends XmlSupport
{
public class CauseTag extends XmlSupport {
/**
* Prints the cause (if any) for the current HTTP Status Error Code.
*
* @throws IOException If an error occurs while writing the output.
*/
@Override
public void doTag()
throws JspException, IOException
{
final PageContext pageContext = (PageContext) getJspContext();
final JspWriter out = pageContext.getOut();
public void doTag() throws IOException {
PageContext pageContext = (PageContext) getJspContext();
JspWriter out = pageContext.getOut();
String cause;
Throwable cause = pageContext.getErrorData().getThrowable().getCause();
try
{
cause = pageContext.getErrorData().getThrowable().getCause().getLocalizedMessage();
}
catch (NullPointerException ignore)
{
cause = defaultValue;
Utils.outWrite(out, getCause(cause), defaultValue, escapeXml);
}
Utils.outWrite(out, cause, defaultValue, escapeXml);
/**
* Returns the cause's localized message or default value.
*
* @param cause The cause.
* @return The cause or {@code null}.
*/
public String getCause(Throwable cause) {
if (cause != null && cause.getLocalizedMessage() != null) {
return cause.getLocalizedMessage();
} else {
return null;
}
}
}

View file

@ -1,59 +1,60 @@
/*
* CodeTag.java
*
* Copyright (c) 2015, Erik C. Thauvin (erik@thauvin.net)
* Copyright 2015-2025 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:
* 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 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 the author nor the names of its contributors may be
* 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 OWNER 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.
* 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.taglibs;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import jakarta.servlet.jsp.JspWriter;
import jakarta.servlet.jsp.PageContext;
import jakarta.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
/**
* The <code>CodeTag</code> class.
* The <code>&lt;hs:code&gt;</code> tag returns the HTTP Status Error Code.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @created 2015-12-03
* @since 1.0
*/
public class CodeTag extends SimpleTagSupport
{
public class CodeTag extends SimpleTagSupport {
/**
* Writes the HTTP Status Error Code to the current JspWriter.
*
* @throws IOException If an I/O error occurs.
*/
@Override
public void doTag()
throws JspException, IOException
{
final PageContext pageContext = (PageContext) getJspContext();
final JspWriter out = pageContext.getOut();
public void doTag() throws IOException {
PageContext pageContext = (PageContext) getJspContext();
JspWriter out = pageContext.getOut();
out.write(String.valueOf(pageContext.getErrorData().getStatusCode()));
}

View file

@ -0,0 +1,64 @@
/*
* MessageTag.java
*
* Copyright 2015-2025 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.taglibs;
import jakarta.servlet.jsp.JspWriter;
import jakarta.servlet.jsp.PageContext;
import net.thauvin.erik.httpstatus.Utils;
import java.io.IOException;
/**
* The <code>&lt;hs:message&gt;</code> tag returns the message (if any) for the current error.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @created 2022-03-16
* @since 1.0.5
*/
public class MessageTag extends XmlSupport {
/**
* Writes the error message associated with the current HTTP Status Error Code.
*
* @throws IOException If an I/O error occurs.
*/
@Override
public void doTag() throws IOException {
PageContext pageContext = (PageContext) getJspContext();
JspWriter out = pageContext.getOut();
String message = (String) pageContext.getRequest().getAttribute(
jakarta.servlet.RequestDispatcher.ERROR_MESSAGE);
Utils.outWrite(out, message, defaultValue, escapeXml);
}
}

View file

@ -1,80 +1,71 @@
/*
* ReasonTag.java
*
* Copyright (c) 2015, Erik C. Thauvin (erik@thauvin.net)
* Copyright 2015-2025 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:
* 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 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 the author nor the names of its contributors may be
* 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 OWNER 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.
* 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.taglibs;
import jakarta.servlet.jsp.JspWriter;
import jakarta.servlet.jsp.PageContext;
import net.thauvin.erik.httpstatus.Reasons;
import net.thauvin.erik.httpstatus.Utils;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import java.io.IOException;
/**
* The <code>ReasonTag</code> class.
* The <code>&lt;hs:reason&gt;</code> tag returns the Reason Phrase for the current (or specified) HTTP Status Error
* Code.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @created 2015-12-02
* @since 1.0
*/
public class ReasonTag extends XmlSupport
{
private int statusCode;
public class ReasonTag extends XmlSupport {
private int statusCode = -1;
/**
* Writes the Reason Phrase for the current (or specified) HTTP Status Error Code.
*/
@Override
public void doTag()
throws JspException, IOException
{
final PageContext pageContext = (PageContext) getJspContext();
final JspWriter out = pageContext.getOut();
public void doTag() {
PageContext pageContext = (PageContext) getJspContext();
JspWriter out = pageContext.getOut();
try
{
if (statusCode > 0)
{
try {
if (statusCode > -1) {
Utils.outWrite(out, Reasons.getReasonPhrase(statusCode), defaultValue, escapeXml);
}
else
{
Utils.outWrite(out,
Reasons.getReasonPhrase(pageContext.getErrorData().getStatusCode()),
defaultValue,
} else {
Utils.outWrite(out, Reasons.getReasonPhrase(pageContext.getErrorData().getStatusCode()), defaultValue,
escapeXml);
}
}
catch (IOException ignore)
{
} catch (IOException ignored) {
// Ignore.
}
}
@ -84,11 +75,7 @@ public class ReasonTag extends XmlSupport
*
* @param statusCode The status code.
*/
@SuppressWarnings("unused")
public void setCode(int statusCode)
{
public void setCode(int statusCode) {
this.statusCode = statusCode;
}
}

View file

@ -1,52 +1,56 @@
/*
* XmlSupport.java
*
* Copyright (c) 2015, Erik C. Thauvin (erik@thauvin.net)
* Copyright 2015-2025 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:
* 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 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 the author nor the names of its contributors may be
* 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 OWNER 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.
* 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.taglibs;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import jakarta.servlet.jsp.tagext.SimpleTagSupport;
/**
* The <code>XmlSupport</code> class.
* Adds support for the <code>default</code> and <code>escapeXml</code> tag attributes.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @created 2015-12-03
* @since 1.0
*/
public abstract class XmlSupport extends SimpleTagSupport
{
protected String defaultValue;
public abstract class XmlSupport extends SimpleTagSupport {
/**
* Default value string.
*/
String defaultValue;
protected boolean escapeXml = true;
/**
* Escape XML flag.
*/
boolean escapeXml = true;
/**
* Sets the default value.
@ -54,19 +58,17 @@ public abstract class XmlSupport extends SimpleTagSupport
* @param defaultValue The default value.
*/
@SuppressWarnings("unused")
public void setDefault(String defaultValue)
{
public void setDefault(String defaultValue) {
this.defaultValue = defaultValue;
}
/**
* Sets the escapeXMl flag.
* Sets the {@link net.thauvin.erik.httpstatus.Utils#escapeXml(String) xml} flag.
*
* @param escapeXml <code>true</code> or <code>false</code>
*/
@SuppressWarnings("unused")
public void setEscapeXml(boolean escapeXml)
{
public void setEscapeXml(boolean escapeXml) {
this.escapeXml = escapeXml;
}
}

View file

@ -0,0 +1,11 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML LANG="en">
<HEAD>
<TITLE>HttpStatus JSP Tag Library</TITLE>
</HEAD>
<BODY>
This package contains the JSP tags used to display the code, reason and/or cause for HTTP status codes.
@since 1.0
</BODY>
</HTML>

View file

@ -1,45 +1,43 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
httpstatus.tld
Copyright (c) 2015, 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 the author 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 OWNER 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.
~ httpstatus.tld
~
~ Copyright 2015-2025 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.
-->
<taglib xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<taglib xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"
version="2.1">
<description>HttpStatus JSP Tag Library</description>
<display-name>HttpStatus JSP Tags</display-name>
<tlib-version>1.0</tlib-version>
<tlib-version>1.1.1</tlib-version>
<short-name>hs</short-name>
<uri>http://erik.thauvin.net/taglibs/httpstatus</uri>
@ -70,13 +68,38 @@
<tag>
<description>
Outputs the HTTP Status Error Code.
Returns the HTTP Status Error Code.
</description>
<name>code</name>
<tag-class>net.thauvin.erik.httpstatus.taglibs.CodeTag</tag-class>
<body-content>empty</body-content>
</tag>
<tag>
<description>
Returns the message (if any) for the current error.
</description>
<name>message</name>
<tag-class>net.thauvin.erik.httpstatus.taglibs.MessageTag</tag-class>
<body-content>empty</body-content>
<attribute>
<description>
Default value if the resulting error message is null.
</description>
<name>default</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<description>
Converts &lt;, &gt; ,&amp; ,' ," to their corresponding entity codes. Value is true by default.
</description>
<name>escapeXml</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
<tag>
<description>
Returns the Reason Phrase for the current (or specified) HTTP Status Error Code.
@ -109,5 +132,4 @@
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>

View file

@ -1,6 +1,44 @@
#
# reasons.properties
#
# Copyright 2015-2025 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.
#
100=Continue
101=Switching Protocols
102=Processing
103=Early Hints
110=Response is Stale
111=Revalidation Failed
112=Disconnected Operation
113=Heuristic Expiration
199=Miscellaneous Warning
200=OK
201=Created
202=Accepted
@ -10,14 +48,17 @@
206=Partial Content
207=Multi-Status
208=Already Reported
214=Transformation Applied
218=This is fine
226=IM Used
299=Miscellaneous Persistent Warning
300=Multiple Choices
301=Moved Permanently
302=Moved Temporarily
302=Found/Moved Temporarily
303=See Other
304=Not Modified
305=Use Proxy
306=Switch Proxy
306=Unused
307=Temporary Redirect
308=Permanent Redirect
400=Bad Request
@ -33,31 +74,35 @@
410=Gone
411=Length Required
412=Precondition Failed
413=Request Entity Too Large
414=Request-URI Too Long
413=Payload Too Large
414=URI Too Long
415=Unsupported Media Type
416=Requested Range Not Satisfiable
416=Range Not Satisfiable
417=Expectation Failed
418=I'm A Teapot
419=Insufficient Space on Resource
420=Method Failure
421=Misdirected Request
422=Unprocessable Entity
422=Unprocessable Content
423=Locked
424=Failed Dependency
425=Too Early
426=Upgrade Required
428=Precondition Required
429=Too Many Requests
430=Request Header Fields Too Large
431=Request Header Fields Too Large
440=Login Timeout
444=No Response
449=Retry With
450=Blocked by Windows Parental Controls
451=Unavailable For Legal Reasons
460=Client Closed Connection Before Load Balancer Idle Timeout
463=X-Forwarded-For Header with More than 30 IP Addresses
494=Request Header Too Large
495=Cert Error
496=No Cert
497=HTTP to HTTPS
495=SSL Certificate Error
496=SSL Certificate Required
497=HTTP Request Sent to HTTPS Port
498=Token Expired/Invalid
499=Client Closed Request
500=Internal Server Error
@ -73,6 +118,17 @@
510=Not Extended
511=Network Authentication Required
520=Unknown Error
522=Origin Connection Time-out
521=Web Server Is Down
522=Connection Timed Out
523=Origin Is Unreachable
524=A Timeout Occurred
525=SSL Handshake Failed
526=Invalid SSL Certificate
527=Railgun Error
529=Site is overloaded
530=Site is frozen
540=Temporarily Disabled
561=Unauthorized
598=Network Read Timeout Error
599=Network Connect Timeout Error
783=Unexpected Token

View file

@ -0,0 +1,58 @@
/*
* CauseTagTest.java
*
* Copyright 2015-2025 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 net.thauvin.erik.httpstatus.taglibs.CauseTag;
import org.assertj.core.api.AutoCloseableSoftAssertions;
import org.junit.jupiter.api.Test;
/**
* Implements the CauseTagTest class.
*
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 1.1.0
*/
class CauseTagTest {
@Test
void causeTest() {
var message = "This is the cause";
var tag = new CauseTag();
try (var softly = new AutoCloseableSoftAssertions()) {
softly.assertThat(tag.getCause(new Exception(message))).as("has cause").isEqualTo(message);
softly.assertThat(tag.getCause(new Exception())).as("no cause").isNull();
softly.assertThat(tag.getCause(null)).as("null").isNull();
softly.assertThat(tag.getCause(new Exception(""))).as("empty").isEmpty();
}
}
}

View file

@ -0,0 +1,104 @@
/*
* ReasonsMainTest.java
*
* Copyright 2015-2025 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 org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Main Class Tests.
*
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @created 2019-05-06
* @since 1.0
*/
class ReasonsMainTest {
private static final ByteArrayOutputStream OUTPUT_STREAM = new ByteArrayOutputStream();
private static final PrintStream SYSTEM_OUT = System.out;
@AfterAll
public static void restoreStreams() {
System.setOut(SYSTEM_OUT);
}
@BeforeAll
public static void setUpStreams() {
System.setOut(new PrintStream(OUTPUT_STREAM));
}
@BeforeEach
public void resetStreams() {
OUTPUT_STREAM.reset();
}
@Test
void testMain() {
Reasons.main("401");
assertThat(OUTPUT_STREAM.toString()).contains(Reasons.getReasonPhrase("401")).as("401");
assertThat(OUTPUT_STREAM.toString()).doesNotContain("500").as("401 no 500");
}
@Test
void testMainAll() {
Reasons.main();
assertThat(OUTPUT_STREAM.toString()).contains(Reasons.getReasonPhrase(301)).as("301");
assertThat(OUTPUT_STREAM.toString()).contains(Reasons.getReasonPhrase(404)).as("404");
}
@Test
void testMainArgs() {
Reasons.main("500", "302");
assertThat(OUTPUT_STREAM.toString()).contains(Reasons.getReasonPhrase("500")).as("500 (302)");
assertThat(OUTPUT_STREAM.toString()).contains(Reasons.getReasonPhrase("302")).as("(500) 302");
assertThat(OUTPUT_STREAM.toString()).doesNotContain("404").as("500/302 not 404");
}
@Test
void testMainArgsClass() {
Reasons.main("2xx");
assertThat(OUTPUT_STREAM.toString()).contains(Reasons.getReasonPhrase("200")).as("2xx");
}
@Test
void testMainInvalid() {
Reasons.main("aaa");
assertThat(OUTPUT_STREAM.toString()).as("invalid argument: aaa").isEmpty();
}
}

View file

@ -1,73 +1,59 @@
/*
* ReasonsTest.java
*
* Copyright (c) 2015, Erik C. Thauvin (erik@thauvin.net)
* Copyright 2015-2025 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:
* 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 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 the author nor the names of its contributors may be
* 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 OWNER 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.
* 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 org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;
import java.util.ResourceBundle;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The <code>ReasonsTest</code> class.
* Reasons Tests.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @created 2015-12-03
* @since 1.0
*/
@SuppressWarnings("unused")
public class ReasonsTest
{
@DataProvider(name = "reasons")
public Object[][] reasons()
{
final ResourceBundle bundle = ResourceBundle.getBundle("net.thauvin.erik.httpstatus.reasons");
final Object[][] reasons = new String[bundle.keySet().size()][2];
int i = 0;
for (final String key : bundle.keySet())
{
reasons[i][0] = key;
reasons[i][1] = bundle.getString(key);
i++;
}
return reasons;
class ReasonsTest {
@Test
void testGetReasonPhrase() {
var bundle = ResourceBundle.getBundle(Reasons.BUNDLE_BASENAME);
for (var key : bundle.keySet()) {
assertThat(Reasons.getReasonPhrase(key)).as("getReasonPhrase(%s)", key).isEqualTo(bundle.getString(key));
assertThat(Reasons.getReasonPhrase(Integer.parseInt(key))).as("getReasonPhrase(%s)", key)
.isEqualTo(bundle.getString(key));
}
@Test(dataProvider = "reasons")
public void testGetReasonPhrase(String code, String reason)
throws Exception
{
Assert.assertEquals(reason, Reasons.getReasonPhrase(code));
}
}

View file

@ -0,0 +1,96 @@
/*
* StatusCodeTest.java
*
* Copyright 2015-2025 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 org.assertj.core.api.AutoCloseableSoftAssertions;
import org.junit.jupiter.api.Test;
import java.util.ResourceBundle;
import static org.assertj.core.api.Assertions.assertThat;
/**
* StatusCode Tests.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @since 1.1.0
*/
class StatusCodeTest {
@Test
void testStatusCode() {
var bundle = ResourceBundle.getBundle(Reasons.BUNDLE_BASENAME);
var statusCode = new StatusCode();
try (var softly = new AutoCloseableSoftAssertions()) {
for (var key : bundle.keySet()) {
int code = Integer.parseInt(key);
statusCode.setCode(code);
softly.assertThat(statusCode.getCode()).as("is not %s", code).isEqualTo(code);
softly.assertThat(statusCode.isInfo()).as("%s is info", code).isEqualTo(code >= 100 && code < 200);
softly.assertThat(statusCode.isSuccess()).as("%s is ok", code).isEqualTo(code >= 200 && code < 300);
softly.assertThat(statusCode.isRedirect()).as("%s is redirect", code)
.isEqualTo(code >= 300 && code < 400);
softly.assertThat(statusCode.isClientError()).as("%s is client error", code)
.isEqualTo(code >= 400 && code < 500);
softly.assertThat(statusCode.isServerError()).as("%s is server error", code)
.isEqualTo(code >= 500 && code < 600);
softly.assertThat(statusCode.isError()).as("%s is error", code).isEqualTo(code >= 400 && code < 600);
softly.assertThat(statusCode.isValid()).as("%s is valid", code).isTrue();
softly.assertThat(statusCode.getReason()).as("%s reason phrase is not valid", code)
.isEqualTo(Reasons.getReasonPhrase(code));
}
}
try (var softly = new AutoCloseableSoftAssertions()) {
int[] unknowns = {0, 99, 600};
for (var code : unknowns) {
statusCode.setCode(code);
softly.assertThat(statusCode.getCode()).as("is not %s", code).isEqualTo(code);
softly.assertThat(statusCode.isInfo()).as("%s is info", code).isFalse();
softly.assertThat(statusCode.isSuccess()).as("%s is ok", code).isFalse();
softly.assertThat(statusCode.isRedirect()).as("%s is redirect", code).isFalse();
softly.assertThat(statusCode.isClientError()).as("%s is client error", code).isFalse();
softly.assertThat(statusCode.isServerError()).as("%s is server error", code).isFalse();
softly.assertThat(statusCode.isError()).as("%s is error", code).isFalse();
softly.assertThat(statusCode.isValid()).as("%s is invalid", code).isFalse();
softly.assertThat(statusCode.getReason()).as("%s reason phrase is not null.", code).isNull();
}
}
statusCode = new StatusCode(900);
assertThat(statusCode.getCode()).as("is not %s", statusCode.getCode()).isEqualTo(900);
}
}

View file

@ -1,58 +1,100 @@
/*
* UtilsTest.java
*
* Copyright (c) 2015, Erik C. Thauvin (erik@thauvin.net)
* Copyright 2015-2025 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:
* 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 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 the author nor the names of its contributors may be
* 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 OWNER 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.
* 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 org.testng.Assert;
import org.testng.annotations.Test;
import org.assertj.core.api.AutoCloseableSoftAssertions;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.StringWriter;
import static org.assertj.core.api.Assertions.assertThat;
/**
* The <code>UtilsTest</code> class.
* Utils Tests.
*
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
* @created 2015-12-03
* @since 1.0
*/
@SuppressWarnings("unused")
public class UtilsTest
{
class UtilsTest {
@Test
public void testEscapeXml()
throws Exception
{
Assert.assertEquals(
"This is a test. We wan&#039;t to make sure that everything is &lt;encoded&gt; according the &#034;encoding&#034; parameter &amp; value.",
Utils.escapeXml(
"This is a test. We wan't to make sure that everything is <encoded> according the \"encoding\" parameter & value."));
void testEscapeXml() {
assertThat(Utils.escapeXml(
"This is a test. We wan't to make sure that everything is <encoded> according the \"encoding\" "
+ "parameter & value."))
.isEqualTo("This is a test. We wan&apos;t to make sure that everything is &lt;encoded&gt; " +
"according the &quot;encoding&quot; parameter &amp; value.");
}
@Test
void testOutWrite() throws IOException {
try (var sw = new StringWriter(); var softly = new AutoCloseableSoftAssertions()) {
var defaultValue = "default";
Utils.outWrite(sw, null, defaultValue, false);
softly.assertThat(sw.toString()).as("outWrite(default)").isEqualTo(defaultValue);
sw.getBuffer().setLength(0);
Utils.outWrite(sw, "", defaultValue, false);
softly.assertThat(sw.toString()).as("outWrite(value empty)").isEmpty();
sw.getBuffer().setLength(0);
Utils.outWrite(sw, null, null, true);
softly.assertThat(sw.toString()).as("outWrite(null)").isEmpty();
sw.getBuffer().setLength(0);
Utils.outWrite(sw, "value", defaultValue, false);
softly.assertThat(sw.toString()).as("outWrite(value)").isEqualTo("value");
sw.getBuffer().setLength(0);
Utils.outWrite(sw, "wan't", defaultValue, true);
softly.assertThat(sw.toString()).as("outWrite(wan't)").isEqualTo("wan&apos;t");
sw.getBuffer().setLength(0);
Utils.outWrite(sw, null, "1 & 1", true);
softly.assertThat(sw.toString()).as("outWrite(1 & 1)").isEqualTo("1 &amp; 1");
sw.getBuffer().setLength(0);
Utils.outWrite(sw, "", defaultValue, true);
softly.assertThat(sw.toString()).as("outWrite(value empty).as(xml)").isEmpty();
sw.getBuffer().setLength(0);
Utils.outWrite(sw, null, "", true);
softly.assertThat(sw.toString()).as("outWrite(default empty)").isEmpty();
sw.getBuffer().setLength(0);
Utils.outWrite(sw, null, null, true);
softly.assertThat(sw.toString()).as("outWrite(null).as(xml)").isEmpty();
}
}
}