diff --git a/.idea/misc.xml b/.idea/misc.xml index 9963c9f..05fa3d9 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,6 @@ - diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e632d1..5a59454 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,27 +1,17 @@ # Changelog -## [1.1.0](https://github.com/ethauvin/httpstatus/tree/1.1.0) (2023-09-29) +## [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.5...1.1.0) - -**Implemented enhancements:** - -- 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) +[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) +## [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) +[Full Changelog](https://github.com/ethauvin/HttpStatus/compare/1.0.3...1.0.4) **Implemented enhancements:** @@ -31,21 +21,21 @@ - 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) +## [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) +[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) +## [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) +[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) +## [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) +[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) +## [1.0](https://github.com/ethauvin/HttpStatus/tree/1.0) (2015-12-04) -[Full Changelog](https://github.com/ethauvin/httpstatus/compare/ad982eff1b27c31b54df4abae00ac2d4065543d6...1.0) +[Full Changelog](https://github.com/ethauvin/HttpStatus/compare/ad982eff1b27c31b54df4abae00ac2d4065543d6...1.0) diff --git a/README.md b/README.md index 883723b..b844171 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,17 @@ -# HttpStatus JSP Tag Library +# HttpStatus JSP Tag Library [](http://opensource.org/licenses/BSD-3-Clause) [](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) [](https://rife2.com/bld) [](https://github.com/ethauvin/httpstatus/releases/latest) -[](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/httpstatus/httpstatus/) -[](https://central.sonatype.com/artifact/net.thauvin.erik.httpstatus/httpstatus) - +[](https://search.maven.org/search?q=g:%22net.thauvin.erik.httpstatus%22%20AND%20a:%22httpstatus%22) +[](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/httpstatus/httpstatus/) [](https://snyk.io/test/github/ethauvin/httpstatus?targetFile=pom.xml) [](https://sonarcloud.io/summary/new_code?id=ethauvin_HttpStatus) [](https://github.com/ethauvin/httpstatus/actions/workflows/bld.yml) [](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. For example: @@ -35,14 +35,11 @@ or <%= Reasons.getReasonPhrase(pageContext.getErrorData().getStatusCode()) %> ``` -would display on a [501 status code](https://www.rfc-editor.org/rfc/rfc9110.html#name-501-not-implemented): +would display on a [501 status code](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.5.2): -```plain -Not Implemented -``` - -## Usage with [Gradle](https://gradle.org/), [Maven](http://maven.apache.org/) or [bld](https://rife2.com/bld) + Not Implemented +## Usage with [Gradle](https://gradle.org/) or [Maven](http://maven.apache.org/) Include the following in your `build.gradle` file: ```gradle @@ -51,28 +48,20 @@ repositories { } dependencies { - implementation 'net.thauvin.erik.httpstatus:httpstatus:1.1.0' + implementation 'net.thauvin.erik.httpstatus:httpstatus:1.0.5' } ``` -or as a `Maven` artifact: +or as a Maven artifact: ```xml net.thauvin.erik.httpstatus httpstatus - 1.1.0 + 1.0.5 ``` -or in a `bld` build file: - -```java -scope(compile).include( - dependency("net.thauvin.erik.httpstatus","httpstatus", version(1, 1, 0)) -); -``` - ## hs:cause The `` tag displays the cause of current HTTP status code, if any. A shorthand for: @@ -89,7 +78,6 @@ Optional attributes are: | `escapeXml` | Converts <, >, &, ', " to their corresponding [entity codes](http://dev.w3.org/html5/html-author/charref). Value is `true` by default. | ## hs:code - The `` tag displays the current HTTP status code, if any. A shorthand for: ```jsp @@ -273,7 +261,6 @@ The reasons are defined in a [ResourceBundle](https://docs.oracle.com/en/java/ja | `599` | Network Connect Timeout Error | ## Command Line Usage - You can query the reason phrase for status codes as follows: ```sh @@ -302,14 +289,3 @@ $ java -jar httpstatus-1.1.0.jar 226: IM Used ... ``` -You can also print status codes by [response classes](https://www.rfc-editor.org/rfc/rfc9110.html#name-status-codes): - -```sh -$ java -jar httpstatus-1.1.0.jar 2xx -200: OK -201: Created -202: Accepted -203: Non-Authoritative Information -204: No Content -... -``` \ No newline at end of file diff --git a/lib/bld/bld-wrapper.properties b/lib/bld/bld-wrapper.properties index a508afe..6786d8e 100644 --- a/lib/bld/bld-wrapper.properties +++ b/lib/bld/bld-wrapper.properties @@ -1,7 +1,7 @@ bld.downloadExtensionJavadoc=false bld.downloadExtensionSources=true bld.extension-pmd=com.uwyn.rife2:bld-pmd:0.9.2 -bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.1-SNAPSHOT -bld.repositories=MAVEN_LOCAL, RIFE2_SNAPSHOTS,RIFE2_RELEASES,MAVEN_CENTRAL +bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.0 +bld.repositories=RIFE2_SNAPSHOTS,RIFE2_RELEASES,MAVEN_CENTRAL bld.downloadLocation= bld.version=1.7.2 diff --git a/pom.xml b/pom.xml index 22b2d96..9a3ab33 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ httpstatus 1.1.0-SNAPSHOT HttpStatus - Tag library to display the code, reason, cause and/or message for HTTP status codes in JSP error pages + HttpStatus JSP Tag Library https://github.com/ethauvin/HttpStatus diff --git a/src/bld/java/net/thauvin/erik/httpstatus/HttpStatusBuild.java b/src/bld/java/net/thauvin/erik/httpstatus/HttpStatusBuild.java index 32c24d9..04f598f 100644 --- a/src/bld/java/net/thauvin/erik/httpstatus/HttpStatusBuild.java +++ b/src/bld/java/net/thauvin/erik/httpstatus/HttpStatusBuild.java @@ -42,7 +42,6 @@ import rife.tools.exceptions.FileUtilsErrorException; import java.io.IOException; import java.nio.file.Path; import java.util.List; -import java.util.jar.Attributes; import static rife.bld.dependencies.Repository.*; import static rife.bld.dependencies.Scope.compile; @@ -55,7 +54,7 @@ public class HttpStatusBuild extends Project { name = "HttpStatus"; version = version(1, 1, 0, "SNAPSHOT"); - var description = "Tag library to display the code, reason, cause and/or message for HTTP status codes in JSP error pages"; + var description = "HttpStatus JSP Tag Library"; var url = "https://github.com/ethauvin/HttpStatus"; mainClass = "net.thauvin.erik.httpstatus.Reasons"; @@ -70,12 +69,10 @@ public class HttpStatusBuild extends Project { .include(dependency("jakarta.servlet.jsp", "jakarta.servlet.jsp-api", version(3, 1, 1))) .include(dependency("jakarta.el", "jakarta.el-api", version(5, 0, 1))); scope(test) - .include(dependency("org.assertj", "assertj-core", version(3, 24, 2))) + .include(dependency("org.assertj", "assertj-joda-time", version(2, 2, 0))) .include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 0))) .include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 0))); - jarOperation().manifestAttribute(Attributes.Name.MAIN_CLASS, pkg + '.' + "Reasons"); - javadocOperation().javadocOptions() .docTitle(description + ' ' + version.toString()) .docLint(NO_MISSING) @@ -86,6 +83,7 @@ public class HttpStatusBuild extends Project { .withCredentials(property("sonatype.user"), property("sonatype.password")) : repository(SONATYPE_RELEASES.location()) .withCredentials(property("sonatype.user"), property("sonatype.password"))) + .repository(MAVEN_LOCAL) .info(new PublishInfo() .groupId(pkg) .artifactId(name.toLowerCase()) @@ -140,4 +138,4 @@ public class HttpStatusBuild extends Project { PomBuilder.generateInto(publishOperation().info(), publishOperation().dependencies(), Path.of(workDirectory.getPath(), "pom.xml").toFile()); } -} +} \ No newline at end of file diff --git a/src/main/java/net/thauvin/erik/httpstatus/Reasons.java b/src/main/java/net/thauvin/erik/httpstatus/Reasons.java index e863ac5..66491df 100644 --- a/src/main/java/net/thauvin/erik/httpstatus/Reasons.java +++ b/src/main/java/net/thauvin/erik/httpstatus/Reasons.java @@ -100,18 +100,9 @@ public final class Reasons { public static void main(final String... args) { if (args.length >= 1) { for (final String key : args) { - if (key.endsWith("xx")) { - var cat = key.charAt(0); - REASON_PHRASES.forEach((k, v) -> { - if (k.charAt(0) == cat) { - System.out.println(k + ": " + v); - } - }); - } else { - final String value = REASON_PHRASES.get(key); - if (value != null) { - System.out.println(key + ": " + value); - } + final String value = REASON_PHRASES.get(key); + if (value != null) { + System.out.println(key + ": " + value); } } } else { diff --git a/src/main/java/net/thauvin/erik/httpstatus/StatusCode.java b/src/main/java/net/thauvin/erik/httpstatus/StatusCode.java index 1982200..98c751e 100644 --- a/src/main/java/net/thauvin/erik/httpstatus/StatusCode.java +++ b/src/main/java/net/thauvin/erik/httpstatus/StatusCode.java @@ -39,7 +39,6 @@ import java.io.Serializable; * The StatusCode bean implements methods to check the class of an HTTP status code. * * @author Erik C. Thauvin - * @since 1.1.0 */ public class StatusCode implements Serializable { @Serial diff --git a/src/main/java/net/thauvin/erik/httpstatus/Utils.java b/src/main/java/net/thauvin/erik/httpstatus/Utils.java index 35422f3..062c69e 100644 --- a/src/main/java/net/thauvin/erik/httpstatus/Utils.java +++ b/src/main/java/net/thauvin/erik/httpstatus/Utils.java @@ -43,6 +43,7 @@ import java.io.Writer; * @since 1.0 */ public final class Utils { + /** * Disables the default constructor. * diff --git a/src/main/java/net/thauvin/erik/httpstatus/taglibs/XmlSupport.java b/src/main/java/net/thauvin/erik/httpstatus/taglibs/XmlSupport.java index 5fec8d7..6fc2801 100644 --- a/src/main/java/net/thauvin/erik/httpstatus/taglibs/XmlSupport.java +++ b/src/main/java/net/thauvin/erik/httpstatus/taglibs/XmlSupport.java @@ -57,7 +57,6 @@ public abstract class XmlSupport extends SimpleTagSupport { * * @param defaultValue The default value. */ - @SuppressWarnings("unused") public void setDefault(final String defaultValue) { this.defaultValue = defaultValue; } @@ -67,7 +66,6 @@ public abstract class XmlSupport extends SimpleTagSupport { * * @param escapeXml true or false */ - @SuppressWarnings("unused") public void setEscapeXml(final boolean escapeXml) { this.escapeXml = escapeXml; } diff --git a/src/main/resources/META-INF/httpstatus.tld b/src/main/resources/META-INF/httpstatus.tld index 0766792..272763c 100644 --- a/src/main/resources/META-INF/httpstatus.tld +++ b/src/main/resources/META-INF/httpstatus.tld @@ -37,7 +37,7 @@ HttpStatus JSP Tag Library HttpStatus JSP Tags - 1.1.0 + 1.0.5 hs http://erik.thauvin.net/taglibs/httpstatus diff --git a/src/main/resources/net/thauvin/erik/httpstatus/reasons.properties b/src/main/resources/net/thauvin/erik/httpstatus/reasons.properties index c690ea9..916bc49 100644 --- a/src/main/resources/net/thauvin/erik/httpstatus/reasons.properties +++ b/src/main/resources/net/thauvin/erik/httpstatus/reasons.properties @@ -1,3 +1,35 @@ +# +# reasons.properties +# +# Copyright 2015-2023 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 diff --git a/src/test/java/net/thauvin/erik/httpstatus/CauseTagTest.java b/src/test/java/net/thauvin/erik/httpstatus/CauseTagTest.java index a71958b..0e10df2 100644 --- a/src/test/java/net/thauvin/erik/httpstatus/CauseTagTest.java +++ b/src/test/java/net/thauvin/erik/httpstatus/CauseTagTest.java @@ -41,7 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat; * Implements the CauseTagTest class. * * @author Erik C. Thauvin - * @since 1.1.0 + * @since 1.0 */ class CauseTagTest { @Test diff --git a/src/test/java/net/thauvin/erik/httpstatus/ReasonsMainTest.java b/src/test/java/net/thauvin/erik/httpstatus/ReasonsMainTest.java index 859b65f..fac29f9 100644 --- a/src/test/java/net/thauvin/erik/httpstatus/ReasonsMainTest.java +++ b/src/test/java/net/thauvin/erik/httpstatus/ReasonsMainTest.java @@ -71,34 +71,28 @@ class ReasonsMainTest { @Test void testMain() { Reasons.main("401"); - assertThat(outContent.toString()).contains(Reasons.getReasonPhrase("401")).as("401"); - assertThat(outContent.toString()).doesNotContain("500").as("401 no 500"); + assertThat(outContent.toString().contains(Reasons.getReasonPhrase("401"))).as("401").isTrue(); + assertThat(outContent.toString().contains("500")).as("401 no 500").isFalse(); } @Test void testMainAll() { Reasons.main(); - assertThat(outContent.toString()).contains(Reasons.getReasonPhrase(301)).as("301"); - assertThat(outContent.toString()).contains(Reasons.getReasonPhrase(404)).as("404"); + assertThat(outContent.toString().contains(Reasons.getReasonPhrase(301))).as("301").isTrue(); + assertThat(outContent.toString().contains(Reasons.getReasonPhrase(404))).as("404").isTrue(); } @Test void testMainArgs() { Reasons.main("500", "302"); - assertThat(outContent.toString()).contains(Reasons.getReasonPhrase("500")).as("500 (302)"); - assertThat(outContent.toString()).contains(Reasons.getReasonPhrase("302")).as("(500) 302"); - assertThat(outContent.toString()).doesNotContain("404").as("500/302 not 404"); - } - - @Test - void testMainArgsClass() { - Reasons.main("2xx"); - assertThat(outContent.toString()).contains(Reasons.getReasonPhrase("200")).as("2xx"); + assertThat(outContent.toString().contains(Reasons.getReasonPhrase("500"))).as("500 (302)").isTrue(); + assertThat(outContent.toString().contains(Reasons.getReasonPhrase("302"))).as("(500) 302").isTrue(); + assertThat(outContent.toString().contains("404")).as("500/302 not 404").isFalse(); } @Test void testMainInvalid() { Reasons.main("aaa"); - assertThat(outContent.toString()).as("invalid argument: aaa").isEmpty(); + assertThat(outContent.toString().isEmpty()).as("invalid argument: aaa").isTrue(); } } diff --git a/src/test/java/net/thauvin/erik/httpstatus/ReasonsTest.java b/src/test/java/net/thauvin/erik/httpstatus/ReasonsTest.java index f60c957..90288a6 100644 --- a/src/test/java/net/thauvin/erik/httpstatus/ReasonsTest.java +++ b/src/test/java/net/thauvin/erik/httpstatus/ReasonsTest.java @@ -38,6 +38,7 @@ import java.util.ResourceBundle; import static org.assertj.core.api.Assertions.assertThat; + /** * Reasons Tests. * diff --git a/src/test/java/net/thauvin/erik/httpstatus/StatusCodeTest.java b/src/test/java/net/thauvin/erik/httpstatus/StatusCodeTest.java index 7ecd692..9eb2f8a 100644 --- a/src/test/java/net/thauvin/erik/httpstatus/StatusCodeTest.java +++ b/src/test/java/net/thauvin/erik/httpstatus/StatusCodeTest.java @@ -42,7 +42,6 @@ import static org.assertj.core.api.Assertions.assertThat; * StatusCode Tests. * * @author Erik C. Thauvin - * @since 1.1.0 */ class StatusCodeTest { @Test diff --git a/src/test/java/net/thauvin/erik/httpstatus/UtilsTest.java b/src/test/java/net/thauvin/erik/httpstatus/UtilsTest.java index 53f974b..d941f07 100644 --- a/src/test/java/net/thauvin/erik/httpstatus/UtilsTest.java +++ b/src/test/java/net/thauvin/erik/httpstatus/UtilsTest.java @@ -39,6 +39,7 @@ import java.io.StringWriter; import static org.assertj.core.api.Assertions.assertThat; + /** * Utils Tests. *
StatusCode
true
false