0

I am trying to use a custom HTTP Status Code (450) but I get an error "org.springframework.http.HttpStatus doesn't have any enum constant '450' defined". I tried searching the other threads, but I wasn't able to find a suitable reply to my situation. Any help is greatly appreciated. Thanks!

Please find below my code:

<http:inbound-gateway supported-methods="POST"
        request-channel="headerEnricher"
        error-channel="errorHandlerRouterChannel"
        reply-channel="responseChannel" header-mapper="headerMapper"
        path="/testApi/1.0" request-payload-type="java.lang.String" />

Error handler method:

private Message<String> createErrorResponse() {
        Map<String, String> respHeader = new HashMap<String, String>();
        respHeader.put(HttpHeaders.STATUS_CODE, "450");
        return MessageBuilder.withPayload("Validation Error")
                .copyHeaders(respHeader).build();
}

Error Exception:

HTTP Status 500 - Request processing failed; nested exception is java.lang.IllegalArgumentException: No matching constant for [450]
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: No matching constant for [450]
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
root cause: java.lang.IllegalArgumentException: No matching constant for [450]
    org.springframework.http.HttpStatus.valueOf(HttpStatus.java:426)
    org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport.resolveHttpStatusFromHeaders(HttpRequestHandlingEndpointSupport.java:549)
    org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport.setupResponseAndConvertReply(HttpRequestHandlingEndpointSupport.java:443)
    org.springframework.integration.http.inbound.HttpRequestHandlingMessagingGateway.handleRequest(HttpRequestHandlingMessagingGateway.java:103)
    org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:49)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:595)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
4
  • What situation is that? I would tend to avoid a custom http status code in most cases I can think of. Commented May 4, 2016 at 22:07
  • 1
    have a look here: stackoverflow.com/questions/22150176/… Commented May 4, 2016 at 22:13
  • Hi Aldanux, thanks for the reply. But please have a look at my code. Please let me know how to handle this situation. Thanks! Commented May 4, 2016 at 22:51
  • Here I am trying to create a Message Response using Message Builder. And our requirement is not to use the generic Business Validation Status Code 400 and use the customized code 450. But using a 450 is throwing an error as shown above. Commented May 5, 2016 at 0:14

1 Answer 1

1

a) I would argue that Spring is buggy when it only supports a hard-wired set of status codes; these are an extension point in HTTP and thus the set of status code is open-ended (well, until the range 100..599 has been filled up).

b) With respect to your use case -- maybe you could just use status code 422 instead (https://greenbytes.de/tech/webdav/rfc4918.html#STATUS_422)?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.