Permalink
Browse files

Add HTTP series check shortcut methods to HttpStatus

Issue: SPR-11424
  • Loading branch information...
1 parent 6a4a2ec commit 6b31074e4a7b8e8b883d304e962af1c2b9b4c03d @rstoyanchev rstoyanchev committed Mar 12, 2014
Showing with 47 additions and 1 deletion.
  1. +47 −1 spring-web/src/main/java/org/springframework/http/HttpStatus.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -389,6 +389,52 @@ public String getReasonPhrase() {
return reasonPhrase;
}
+ /**
+ * Whether this status code is in the HTTP series
+ * {@link org.springframework.http.HttpStatus.Series#INFORMATIONAL}.
+ * This is a shortcut for checking the value of {@link #series()}.
+ */
+ public boolean is1xxInformational() {
+ return (Series.INFORMATIONAL.equals(series()));
+ }
+
+ /**
+ * Whether this status code is in the HTTP series
+ * {@link org.springframework.http.HttpStatus.Series#SUCCESSFUL}.
+ * This is a shortcut for checking the value of {@link #series()}.
+ */
+ public boolean is2xxSuccessful() {
+ return (Series.SUCCESSFUL.equals(series()));
+ }
+
+ /**
+ * Whether this status code is in the HTTP series
+ * {@link org.springframework.http.HttpStatus.Series#REDIRECTION}.
+ * This is a shortcut for checking the value of {@link #series()}.
+ */
+ public boolean is3xxRedirection() {
+ return (Series.REDIRECTION.equals(series()));
+ }
+
+
+ /**
+ * Whether this status code is in the HTTP series
+ * {@link org.springframework.http.HttpStatus.Series#CLIENT_ERROR}.
+ * This is a shortcut for checking the value of {@link #series()}.
+ */
+ public boolean is4xxClientError() {
+ return (Series.CLIENT_ERROR.equals(series()));
+ }
+
+ /**
+ * Whether this status code is in the HTTP series
+ * {@link org.springframework.http.HttpStatus.Series#SERVER_ERROR}.
+ * This is a shortcut for checking the value of {@link #series()}.
+ */
+ public boolean is5xxServerError() {
+ return (Series.SERVER_ERROR.equals(series()));
+ }
+
/**
* Returns the HTTP status series of this status code.
* @see HttpStatus.Series

0 comments on commit 6b31074

Please sign in to comment.