Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status Code and Message Mismatch in WebApplicationException #22765

Closed
cdhermann opened this issue Jan 10, 2022 · 4 comments · Fixed by #22767
Closed

Status Code and Message Mismatch in WebApplicationException #22765

cdhermann opened this issue Jan 10, 2022 · 4 comments · Fixed by #22767
Labels
Milestone

Comments

@cdhermann
Copy link
Contributor

Describe the bug

When using the RESTEasy Reactive Client the HTTP status message doesn't match the HTTP status code.

Expected behavior

The HTTP status message is expected to match the status code

Actual behavior

 @Test
    void testWebApplicationException() {
        assertEquals("HTTP 428 Precondition required", new WebApplicationException(428).getMessage());
        // HTTP 428 Expectation Failed
        // should be: HTTP 428 Precondition required

        assertEquals("HTTP 429 Too Many Requests", new WebApplicationException(429).getMessage());
        // HTTP 429 Precondition Required
        // should be: HTTP 429 Too Many Requests

        assertEquals("431 Request Header Fields Too Large", new WebApplicationException(431).getMessage());
        // HTTP 431 Too Many Requests
        // should be: HTTP 431 Request Header Fields Too Large
    }

            // taken from Response.class
        //
        //    REQUESTED_RANGE_NOT_SATISFIABLE(416, "Requested Range Not Satisfiable"),
        //    /**
        //     * 417 Expectation Failed, see {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.18">HTTP/1.1 documentation</a>}.
        //     *
        //     * @since 2.0
        //     */
        //    EXPECTATION_FAILED(417, "Expectation Failed"),
        //    /**
        //     * 428 Precondition required, see {@link <a href="https://tools.ietf.org/html/rfc6585#section-3">RFC 6585: Additional HTTP Status Codes</a>}.
        //     *
        //     * @since 2.1
        //     */
        //    PRECONDITION_REQUIRED(428, "Precondition Required"),
        //    /**
        //     * 429 Too Many Requests, see {@link <a href="https://tools.ietf.org/html/rfc6585#section-4">RFC 6585: Additional HTTP Status Codes</a>}.
        //     *
        //     * @since 2.1
        //     */
        //    TOO_MANY_REQUESTS(429, "Too Many Requests"),
        //    /**
        //     * 431 Request Header Fields Too Large, see {@link <a href="https://tools.ietf.org/html/rfc6585#section-5">RFC 6585: Additional HTTP Status Codes</a>}.
        //     *
        //     * @since 2.1
        //     */
        //    REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large"),

How to Reproduce?

run the JBang script:

///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVAC_OPTIONS -parameters
//JAVA_OPTIONS -Djava.util.logging.manager=org.jboss.logmanager.LogManager

//DEPS io.quarkus:quarkus-rest-client-reactive:2.6.1.Final
//DEPS io.quarkus:quarkus-arc:2.6.1.Final

import static java.lang.System.*;

import io.quarkus.runtime.annotations.QuarkusMain;
import io.quarkus.runtime.Quarkus;
import javax.inject.Inject;
import org.jboss.logging.Logger;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;

@QuarkusMain
public class webapplicationexception {

    public static void main(String... args) {
        System.out.println("Expected: " + Response.Status.PRECONDITION_REQUIRED.getStatusCode() + " " + Response.Status.PRECONDITION_REQUIRED.getReasonPhrase());
        System.out.println("Got: " + new WebApplicationException(428).getMessage());
        System.out.println();

        System.out.println("Expected: " + Response.Status.TOO_MANY_REQUESTS.getStatusCode() + " " + Response.Status.TOO_MANY_REQUESTS.getReasonPhrase());
        System.out.println("Got: " + new WebApplicationException(429).getMessage());
        System.out.println();

        System.out.println("Expected: " + Response.Status.REQUEST_HEADER_FIELDS_TOO_LARGE.getStatusCode() + " " + Response.Status.REQUEST_HEADER_FIELDS_TOO_LARGE.getReasonPhrase());
        System.out.println("Got: " + new WebApplicationException(431).getMessage());
    }

    // taken from public enum Status implements StatusType in Response.class
    //
    //    REQUESTED_RANGE_NOT_SATISFIABLE(416, "Requested Range Not Satisfiable"),
    //    /**
    //     * 417 Expectation Failed, see {@link <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.18">HTTP/1.1 documentation</a>}.
    //     *
    //     * @since 2.0
    //     */
    //    EXPECTATION_FAILED(417, "Expectation Failed"),
    //    /**
    //     * 428 Precondition required, see {@link <a href="https://tools.ietf.org/html/rfc6585#section-3">RFC 6585: Additional HTTP Status Codes</a>}.
    //     *
    //     * @since 2.1
    //     */
    //    PRECONDITION_REQUIRED(428, "Precondition Required"),
    //    /**
    //     * 429 Too Many Requests, see {@link <a href="https://tools.ietf.org/html/rfc6585#section-4">RFC 6585: Additional HTTP Status Codes</a>}.
    //     *
    //     * @since 2.1
    //     */
    //    TOO_MANY_REQUESTS(429, "Too Many Requests"),
    //    /**
    //     * 431 Request Header Fields Too Large, see {@link <a href="https://tools.ietf.org/html/rfc6585#section-5">RFC 6585: Additional HTTP Status Codes</a>}.
    //     *
    //     * @since 2.1
    //     */
    //    REQUEST_HEADER_FIELDS_TOO_LARGE(431, "Request Header Fields Too Large"),

}

Output of uname -a or ver

Darwin cdh.localdomain 21.2.0 Darwin Kernel Version 21.2.0: Sun Nov 28 20:29:10 PST 2021; root:xnu-8019.61.5~1/RELEASE_ARM64_T8101 arm64

Output of java -version

java version "17" 2021-09-14 LTS Java(TM) SE Runtime Environment (build 17+35-LTS-2724) Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

No response

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d) Maven home: ~/.m2/wrapper/dists/apache-maven-3.8.1-bin/2l5mhf2pq2clrde7f7qp1rdt5m/apache-maven-3.8.1 Java version: 17, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home Default locale: de_AT, platform encoding: UTF-8 OS name: "mac os x", version: "12.1", arch: "aarch64", family: "mac"

Additional information

No response

@cdhermann cdhermann added the kind/bug Something isn't working label Jan 10, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Jan 10, 2022

/cc @maxandersen, @quarkusio/devtools

@quarkus-bot quarkus-bot bot added the area/jbang Issues related to when using jbang.dev with Quarkus label Jan 10, 2022
@gsmet gsmet added area/rest-client area/rest and removed area/jbang Issues related to when using jbang.dev with Quarkus labels Jan 10, 2022
@gsmet
Copy link
Member

gsmet commented Jan 10, 2022

@michalszynkiewicz could you have a look at this one?

cdhermann added a commit to cdhermann/quarkus that referenced this issue Jan 10, 2022
Update status code to message mapping based on https://developer.mozilla.org/de/docs/Web/HTTP/Status
cdhermann added a commit to cdhermann/quarkus that referenced this issue Jan 10, 2022
Update status code to message mapping based on https://developer.mozilla.org/de/docs/Web/HTTP/Status
@quarkus-bot quarkus-bot bot added this to the 2.7 - main milestone Jan 10, 2022
@michalszynkiewicz
Copy link
Member

Thanks @gastaldi !

@gsmet gsmet modified the milestones: 2.7 - main, 2.6.3.Final Jan 15, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue Jan 15, 2022
Update status code to message mapping based on https://developer.mozilla.org/de/docs/Web/HTTP/Status

(cherry picked from commit 4716194)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants