Skip to content

Commit c5ee49e

Browse files
author
TanyaEf
committed
Updated readme.md (Configuration section)
1 parent 121a8fb commit c5ee49e

File tree

2 files changed

+38
-39
lines changed

2 files changed

+38
-39
lines changed

README.md

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Table of Contents
1111
* [Creation of manual configuration](#creation-of-manual-configuration).
1212
* [HTTPS configuration](#https-configuration).
1313
* [X-HTTP-Method override](#x-http-method-override).
14+
* [Exception handling](#exception-handling).
1415
* [Client instantiation](#client-instantiation).
1516
3. [Authentication](#authentication).
1617
* [Anonymous session](#anonymous-session).
@@ -111,14 +112,13 @@ Table of Contents
111112
13. [Query executor service](#queryexecutor-service).
112113
14. [REST Server Information](#rest-server-information).
113114
15. [Bundles service](#bundles-service).
114-
16. [Exception handling](#exception-handling).
115-
17. [Asynchronous API](#asynchronous-api).
116-
18. [Getting serialized content from response](#getting-serialized-content-from-response).
117-
19. [Switching between JSON and XML](#switching-between-json-and-xml).
118-
20. [Logging](#logging).
119-
21. [Possible issues](#possible-issues).
120-
22. [Maven dependency to add jasperserver-rest-client to your app](#maven-dependency-to-add-jasperserver-rest-client-to-your-app).
121-
23. [License](#license).
115+
16. [Asynchronous API](#asynchronous-api).
116+
17. [Getting serialized content from response](#getting-serialized-content-from-response).
117+
18. [Switching between JSON and XML](#switching-between-json-and-xml).
118+
19. [Logging](#logging).
119+
20. [Possible issues](#possible-issues).
120+
21. [Maven dependency to add jasperserver-rest-client to your app](#maven-dependency-to-add-jasperserver-rest-client-to-your-app).
121+
22. [License](#license).
122122

123123
Introduction
124124
-------------
@@ -145,6 +145,7 @@ authenticationType=REST
145145
logHttp=true
146146
logHttpEntity=false
147147
restrictedHttpMethods=false
148+
handleErrors=true
148149
contentMimeType=JSON
149150
acceptMimeType=JSON
150151
```
@@ -153,11 +154,7 @@ File must contain at least URL which is entry point to your server's REST servic
153154
To configure `JasperserverRestClient` manually, use the constructor of `RestClientConfiguration` and properties:
154155
```java
155156
RestClientConfiguration configuration = new RestClientConfiguration("http://localhost:8080/jasperserver");
156-
configuration.setAcceptMimeType(MimeType.JSON);
157-
configuration.setContentMimeType(MimeType.JSON);
158-
configuration.setJrsVersion(JRSVersion.v6_0_0);
159-
configuration.setLogHttp(true);
160-
configuration.setLogHttpEntity(true);
157+
configuration.setAcceptMimeType(MimeType.JSON).setContentMimeType(MimeType.JSON).setJrsVersion(JRSVersion.v6_0_0).setLogHttp(true);
161158
```
162159
####HTTPS configuration
163160
<strong>To use HTTPS you need:</strong>
@@ -179,6 +176,33 @@ To avoid situation, when your proxies or web services do not support arbitrary H
179176
session.getStorage().getConfiguration().setRestrictedHttpMethods(true);
180177
```
181178
If you do not use the "restricted mode", POST or GET methods and server returns the response with 411 error code, `JaperserverRestClient` resend this request through POST method with the X-HTTP-Method-Override header automatically.
179+
180+
###Exception handling
181+
You can choose strategy of errors that are specified by status code of server response:
182+
1. handling of errors directly. This is allied by default.
183+
2. getting operation result in any case with null entity and handling error after calling `getEntity()` method:
184+
```java
185+
OperationResult<InputStream> result = session
186+
.thumbnailsService()
187+
.thumbnail()
188+
.report("/")
189+
.get(); // response status is 406, but exception won't be thrown
190+
result.getEntity(); // the error will be handled and an exception will be thrown
191+
```
192+
To apply the second strategy set `handleErrors` property of `RestCleintConfiguration` to `false`:
193+
```java
194+
configuration.setHandleErrors(false);
195+
```
196+
or specify this property in configuration file (for details, read section [Configuration](https://github.com/Jaspersoft/jrs-rest-java-client/blob/master/README.md#configuration)).
197+
198+
You can customize exception handling for each endpoint. To do this you need to pass `com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.ErrorHandler` implementation to `JerseyRequestBuilder.buildRequest()` factory method.
199+
200+
JRS REST client exception handling system is based on `com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.ErrorHandler` interface. Its `void handleError(Response response)` method is responsible for all error handling logic. You can use existed handlers, define your own handlers or extend existed handlers.
201+
202+
1. Existed handlers:
203+
* `com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.DefaultExceptionHandler` - this implementation is suitable for most of the JRS errors, but sometimes you can meet some not standart errors and here such implementations as `com.jaspersoft.jasperserver.jaxrs.client.apiadapters.jobs.JobValidationErrorHandler`, `com.jaspersoft.jasperserver.jaxrs.client.apiadapters.reporting.RunReportErrorHandler`, etc. take responsibility.
204+
2. You can create your own handler by implementing `com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.ErrorHandler`.
205+
3. You can extend `com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.DefaultExceptionHandler` or any other handler and override its methods `void handleBodyError(Response response)` and/or `void handleStatusCodeError(Response response, String overridingMessage)`.
182206
####Client instantiation:
183207
Here everything is easy, you need just to pass `configuration` to `JasperserverRestClient` constructor.
184208
```java
@@ -1727,32 +1751,6 @@ final Map<String, String> bundle = session
17271751
.bundle("jasperserver_messages")
17281752
.getEntity();
17291753
```
1730-
###Exception handling
1731-
You can choose strategy of errors that are specified by status code of server response:
1732-
1. handling of errors directly. This is allied by default.
1733-
2. getting operation result in any case with null entity and handling error after calling `getEntity()` method:
1734-
```java
1735-
OperationResult<InputStream> result = session
1736-
.thumbnailsService()
1737-
.thumbnail()
1738-
.report("/")
1739-
.get(); // response status is 406, but exception won't be thrown
1740-
result.getEntity(); // the error will be handled and an exception will be thrown
1741-
```
1742-
To apply the second strategy set `handleErrors` property of `RestCleintConfiguration` to `false`:
1743-
```java
1744-
configuration.setHandleErrors(false);
1745-
```
1746-
or specify this property in configuration file (for details, read section [Configuration](https://github.com/Jaspersoft/jrs-rest-java-client/blob/master/README.md#configuration)).
1747-
1748-
You can customize exception handling for each endpoint. To do this you need to pass `com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.ErrorHandler` implementation to `JerseyRequestBuilder.buildRequest()` factory method.
1749-
1750-
JRS REST client exception handling system is based on `com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.ErrorHandler` interface. Its `void handleError(Response response)` method is responsible for all error handling logic. You can use existed handlers, define your own handlers or extend existed handlers.
1751-
1752-
1. Existed handlers:
1753-
* `com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.DefaultExceptionHandler` - this implementation is suitable for most of the JRS errors, but sometimes you can meet some not standart errors and here such implementations as `com.jaspersoft.jasperserver.jaxrs.client.apiadapters.jobs.JobValidationErrorHandler`, `com.jaspersoft.jasperserver.jaxrs.client.apiadapters.reporting.RunReportErrorHandler`, etc. take responsibility.
1754-
2. You can create your own handler by implementing `com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.ErrorHandler`.
1755-
3. You can extend `com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.DefaultExceptionHandler` or any other handler and override its methods `void handleBodyError(Response response)` and/or `void handleStatusCodeError(Response response, String overridingMessage)`.
17561754
17571755
###Asynchronous API
17581756
Each operation which requests server has its asynchronous brother which has same name with `async` prefix, e. g. `get() -> asyncGet()`. Each of these operations take a `com.jaspersoft.jasperserver.jaxrs.client.core.Callback` implementation with `execute()` method implemented. `execute()` takes an `OperationResult` instance as a parameter. The `execute` method is called when the response from server came.

src/main/resources/config.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ authenticationType=SPRING
77
logHttp=true
88
logHttpEntity=true
99
restrictedHttpMethods=false
10+
handleErrors=true
1011
contentMimeType=JSON
1112
acceptMimeType=JSON

0 commit comments

Comments
 (0)