forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
eugenp
committed
Jan 5, 2014
1 parent
c0cc59e
commit 1af3eb4
Showing
6 changed files
with
115 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...urity-rest-full/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.baeldung.web.exception; | ||
|
||
public final class MyResourceNotFoundException extends RuntimeException { | ||
|
||
public MyResourceNotFoundException() { | ||
super(); | ||
} | ||
|
||
public MyResourceNotFoundException(final String message, final Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public MyResourceNotFoundException(final String message) { | ||
super(message); | ||
} | ||
|
||
public MyResourceNotFoundException(final Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
spring-security-rest-full/src/main/java/org/baeldung/web/util/RestPreconditions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.baeldung.web.util; | ||
|
||
import org.baeldung.web.exception.MyResourceNotFoundException; | ||
import org.springframework.http.HttpStatus; | ||
|
||
/** | ||
* Simple static methods to be called at the start of your own methods to verify correct arguments and state. If the Precondition fails, an {@link HttpStatus} code is thrown | ||
*/ | ||
public final class RestPreconditions { | ||
|
||
private RestPreconditions() { | ||
throw new AssertionError(); | ||
} | ||
|
||
// API | ||
|
||
/** | ||
* Check if some value was found, otherwise throw exception. | ||
* | ||
* @param expression | ||
* has value true if found, otherwise false | ||
* @throws MyResourceNotFoundException | ||
* if expression is false, means value not found. | ||
*/ | ||
public static void checkFound(final boolean expression) { | ||
if (!expression) { | ||
throw new MyResourceNotFoundException(); | ||
} | ||
} | ||
|
||
/** | ||
* Check if some value was found, otherwise throw exception. | ||
* | ||
* @param expression | ||
* has value true if found, otherwise false | ||
* @throws MyResourceNotFoundException | ||
* if expression is false, means value not found. | ||
*/ | ||
public static <T> T checkFound(final T resource) { | ||
if (resource == null) { | ||
throw new MyResourceNotFoundException(); | ||
} | ||
|
||
return resource; | ||
} | ||
|
||
} |