I was using JAX-RS 2.1 and I found the Response
class enum is missing the 423
error code.
Can anybody explain to me why?
I searched on the internet but not found any relevant thread.
From the Response.Status
documentation:
Commonly used status codes defined by HTTP, see HTTP/1.1 documentation for the complete list. Additional status codes can be added by applications by creating an implementation of
Response.StatusType
.
The 423
status code is defined as part of WebDAV in the RFC 4918, which is an extension of the HTTP protocol.
Once 423
is registered in IANA, it can be considered a standard status code, but it's not defined in any of the documents that currently define the HTTP/1.1 protocol:
There's a number of ways to return 423
though. The simplest one is:
return Response.status(423).build();
Alternatively, you could implement Response.StatusType
, as suggested in the Response.Status
documentation:
public static class LockedStatusType implements Response.StatusType {
@Override
public int getStatusCode() {
return 423;
}
@Override
public String getReasonPhrase() {
return "Locked";
}
@Override
public Response.Status.Family getFamily() {
return Response.Status.Family.CLIENT_ERROR;
}
}
And then return it:
return Response.status(new LockedStatusType()).build();