You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21-10Lines changed: 21 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -219,6 +219,27 @@ If a service method returns `null`, an HTTP 404 (not found) response will be ret
219
219
220
220
Although return values are encoded as JSON by default, subclasses can override the `encodeResult()` method of the `WebService` class to support alternative representations. See the method documentation for more information.
221
221
222
+
### Exceptions
223
+
If an exception is thrown by a service method and the response has not yet been committed, the exception message (if any) will be returned as plain text in the response body. Error status is determined as follows:
224
+
225
+
*`IllegalArgumentException` or `UnsupportedOperationException` - HTTP 403 (forbidden)
226
+
*`NoSuchElementException` - HTTP 404 (not found)
227
+
*`IllegalStateException` - HTTP 409 (conflict)
228
+
* Any other exception - HTTP 500 (internal server error)
229
+
230
+
Subclasses can override the `reportError()` method to perform custom error handling.
231
+
232
+
### Database Connectivity
233
+
For services that require database connectivity, the following method can be used to obtain a JDBC connection object associated with the current invocation:
234
+
235
+
```java
236
+
protectedstaticConnection getConnection() { ... }
237
+
```
238
+
239
+
The connection is opened via a data source identified by `getDataSourceName()`, which returns `null` by default. Service classes must override this method to provide the name of a valid data source.
240
+
241
+
Auto-commit is disabled so an entire request will be processed within a single transaction. If the request completes successfully, the transaction is committed. Otherwise, it is rolled back.
242
+
222
243
### Request and Repsonse Properties
223
244
The following methods provide access to the request and response objects associated with the current invocation:
224
245
@@ -231,16 +252,6 @@ For example, a service might use the request to read directly from the input str
231
252
232
253
The response object can also be used to produce a custom result. If a service method commits the response by writing to the output stream, the method's return value (if any) will be ignored by `WebService`. This allows a service to return content that cannot be easily represented as JSON, such as image data.
233
254
234
-
### Exceptions
235
-
If an exception is thrown by a service method and the response has not yet been committed, the exception message (if any) will be returned as plain text in the response body. Error status is determined as follows:
236
-
237
-
*`IllegalArgumentException` or `UnsupportedOperationException` - HTTP 403 (forbidden)
238
-
*`NoSuchElementException` - HTTP 404 (not found)
239
-
*`IllegalStateException` - HTTP 409 (conflict)
240
-
* Any other exception - HTTP 500 (internal server error)
241
-
242
-
Subclasses can override the `reportError()` method to perform custom error handling.
243
-
244
255
### Inter-Service Communication
245
256
A reference to any active service can be obtained via the `getInstance()` method of the `WebService` class. This can be useful when the implementation of one service depends on functionality provided by another service, for example.
0 commit comments