tags:

views:

554

answers:

5

I'm wondering if there is an enum type in some standard Java class library that defines symbolic constants for all of the valid HTTP response codes. It should support conversion to/from the corresponding integer values.

I'm debugging some Java code that uses javax.ws.rs.core.Response.Status. It works, but it only defines about half of the valid HTTP response codes.

+2  A: 

Well, there are static constants of the exact integer values in the HttpURLConnection class

Mystic
+7  A: 

I don't think there's one that's complete in the standard Java classes; HttpURLConnection is missing quite a few codes, like HTTP 100/Continue. There's a complete list in the Apache Commons, though: org.apache.commons.HttpClient.HttpStatus.

John Feminella
+2  A: 

The Interface javax.servlet.http.HttpServletResponse from the servlet API has all the response codes in the for of int constants names SC_<description>. See http://java.sun.com/javaee/5/docs/api/javax/servlet/http/HttpServletResponse.html

David Rabinowitz
Depends on how you define "all".
Julian Reschke
HttpServletResponse supports the RFC1945 and part of RFC2616 standards, but it's missing all of RFC2518. If you need a complete list, see HttpStatus as I mentioned.
John Feminella
+1  A: 

Also check out the Restlet Status class:

http://www.restlet.org/documentation/1.1/api/org/restlet/data/Status.html

Greg Noe
Again; status codes are extensible, so there can't be a "complete" list, unless it's revised everytime a new status code is added to the IANA registry (http://www.iana.org/assignments/http-status-codes)
Julian Reschke
+1  A: 

If you're using Spring, the 3.x release has what your looking for: http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/http/HttpStatus.html

Ed J