-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor HttpException and RequestException to common HTTP module. Add ErrorHandlers (without actual implementation) to Nima. Use HttpException in Nima where appropriate
- Loading branch information
1 parent
7f641f5
commit 2d57383
Showing
49 changed files
with
531 additions
and
413 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
.../main/archetype/se/custom/files/src/main/java/__pkg__/FileStorage.java.multipart.mustache
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
42 changes: 42 additions & 0 deletions
42
common/http/src/main/java/io/helidon/common/http/ForbiddenException.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,42 @@ | ||
/* | ||
* Copyright (c) 2017, 2022 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.helidon.common.http; | ||
|
||
/** | ||
* A runtime exception indicating a {@link io.helidon.common.http.Http.Status#FORBIDDEN_403 not found}. | ||
*/ | ||
public class ForbiddenException extends HttpException { | ||
|
||
/** | ||
* Creates {@link io.helidon.common.http.ForbiddenException}. | ||
* | ||
* @param message the message | ||
*/ | ||
public ForbiddenException(String message) { | ||
super(message, Http.Status.FORBIDDEN_403, null, true); | ||
} | ||
|
||
/** | ||
* Creates {@link io.helidon.common.http.ForbiddenException}. | ||
* | ||
* @param message the message | ||
* @param cause the cause of this exception | ||
*/ | ||
public ForbiddenException(String message, Throwable cause) { | ||
super(message, Http.Status.FORBIDDEN_403, cause, true); | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
common/http/src/main/java/io/helidon/common/http/InternalServerException.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,43 @@ | ||
/* | ||
* Copyright (c) 2017, 2022 Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.helidon.common.http; | ||
|
||
/** | ||
* A runtime exception indicating a {@link io.helidon.common.http.Http.Status#INTERNAL_SERVER_ERROR_500 internal server error}. | ||
*/ | ||
public class InternalServerException extends HttpException { | ||
/** | ||
* Creates {@link io.helidon.common.http.InternalServerException}. | ||
* | ||
* @param message the message | ||
* @param cause the cause of this exception | ||
*/ | ||
public InternalServerException(String message, Throwable cause) { | ||
super(message, Http.Status.INTERNAL_SERVER_ERROR_500, cause); | ||
} | ||
|
||
/** | ||
* Creates {@link io.helidon.common.http.InternalServerException}. | ||
* | ||
* @param message the message | ||
* @param cause the cause of this exception | ||
* @param keepAlive whether to keep the connection alive (if keep alives are enabled) | ||
*/ | ||
public InternalServerException(String message, Throwable cause, boolean keepAlive) { | ||
super(message, Http.Status.INTERNAL_SERVER_ERROR_500, cause, keepAlive); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
HTTP Exception Handling | ||
--- | ||
|
||
# WebServer | ||
|
||
The request may fail in three locations: | ||
1. In Helidon server processing code (internal, unexpected error caused by a bug). Such a case will be logged into the server log in | ||
Severe/Error log level and the connection will be terminated. | ||
2. In request processing code, before ServerRequest and ServerResponse are created. Such errors (such as when request cannot be parsed) | ||
are handled by `DirectHandler`, and the server provides as much information as possible to the handler. | ||
3. Exceptions thrown from user routing code, and most server exceptions thrown after `ServerRequest` and `ServerResponse` are created, are handled using error handlers of routing. The exception is `BadRequestException` which is always handled by `DirectHandler` (we may discover lazily that a header does not adhere to specification and thrown this exception) | ||
|
||
The exception class hierarchy that is used (these exceptions should not be caught by user code, unless you want to handle everything on your own): | ||
- `RequestException` - used for case 2 - this is the only exception (final class) used when we need to explicitly throw an exception | ||
to be handled by Helidon server code in a `DirectHandler`. | ||
- `HttpException` - used for case 3 - this is the top level exception class for exceptions that provide a status code and message, and | ||
that can be handled by error handlers. If Error handles do not handle them, they will create a response with the expected error | ||
code, and will send the exception message as entity | ||
- `CloseConnectionException` - this exception can be thrown to terminate current connection | ||
- `UncheckedIOException` - this exception is NOT handled and will cause the connection to be closed (we expect this to be problems such as socket closed etc.) | ||
|
||
|
||
# WebClient | ||
|
||
! we need to discuss this first! | ||
Web client will use `HttpException` and its subclasses (such as `NotFoundException`) in case the entity is read directly | ||
(e.g. the user skips `WebClientResponse`, and uses `as(Class)` to read entity) and the status code returned does not provide | ||
an expected entity (such as any error) | ||
|
||
# HttpException reference | ||
The following HTTP status codes have a specific exception class: | ||
|
||
- 403 - `ForbiddenException` | ||
- 404 - `NotFoundException` | ||
- 400 - `BadRequestException` - ALWAYS handled by `DirectHandler` | ||
- 500 - `InternalServerException` - the error handler will be first attempted for the cause, then for this exception |
Oops, something went wrong.