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
Here is example of `configuration.properties` file:
139
143
```java
140
-
url=http://localhost:4444/jasperserver-pro
141
-
connectionTimeout=100
144
+
// required content
145
+
url=http://localhost:8080/jasperserver-pro
146
+
// optional content
147
+
connectionTimeout=20
142
148
readTimeout=20
143
149
jasperserverVersion=v6_0_0
144
-
authenticationType=REST
150
+
authenticationType=SPRING
145
151
logHttp=true
146
-
logHttpEntity=false
152
+
logHttpEntity=true
147
153
restrictedHttpMethods=false
154
+
handleErrors=true
148
155
contentMimeType=JSON
149
156
acceptMimeType=JSON
150
157
```
151
158
File must contain at least URL which is entry point to your server's REST services and it is needed to URL corresponds to this pattern `{protocol}://{host}:{port}/{contextPath}`.
159
+
Please notice, configuration settings may be changed after loading manually in java code.
152
160
####Creation of manual configuration
153
161
To configure `JasperserverRestClient` manually, use the constructor of `RestClientConfiguration` and properties:
To avoid situation, when your proxies or web services do not support arbitrary HTTP methods or newer HTTP methods, you can use “restricted mode”. In this mode `JaperserverRestClient` sends requests through POST method and set the `X-HTTP-Method-Override` header with value of intended HTTP method. To use this mode you should set flag `RestrictedHttpMethods`:
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.
190
+
####Switching authentication type
191
+
`JasperserverRestClient` supports two authentication types:SPRING and BASIC.
192
+
`SPRING` type of authentication means that your credentials are sent as a form to `/j_security_check directly/` uri. Using these types you obtain JSESSIONID cookie of authenticated session after sending credentials.
193
+
In the `BASIC` mode `JasperserverRestClient` uses basic authentication (sends encrypted credentials with each request).
194
+
Client uses `SPRING` authentication by default but you can specify authentication type in RestClientConfiguration instance:
Please notice, the basic authentication is not stateless and it is valid till method logout() is called or the application is restarted and you can not use this authentication type for Report Service, because all operations must be executed in the same session (for details, read section [Report services](https://github.com/Jaspersoft/jrs-rest-java-client/blob/master/README.md#report-services)).
205
+
####Exception handling
206
+
You can choose strategy of errors that are specified by status code of server response:
207
+
1. handling of errors directly. This mode is allowed by default.
208
+
2. getting operation result in any case with null entity and handling error after calling `getEntity()` method:
209
+
```java
210
+
OperationResult<InputStream> result = session
211
+
.thumbnailsService()
212
+
.thumbnail()
213
+
.report("/")
214
+
.get(); // response status is 406, but exception won't be thrown
215
+
result.getEntity(); // the error will be handled and an exception will be thrown
216
+
```
217
+
To apply the second strategy set `handleErrors` property of `RestCleintConfiguration` to `false`:
218
+
```java
219
+
configuration.setHandleErrors(false);
220
+
```
221
+
or specify this property in configuration file:
222
+
```java
223
+
handleErrors=false
224
+
```
225
+
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.
226
+
227
+
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.
228
+
229
+
1. Existed handlers:
230
+
*`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.
231
+
2. You can create your own handler by implementing `com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.ErrorHandler`.
232
+
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)`.
233
+
234
+
####Logging
235
+
It is possible to log outgoing requests and incoming responses using `logHttp` property of `RestCleintConfiguration`:
236
+
```java
237
+
config.setLogHttp(true);
238
+
```
239
+
Also, you are able to log entities using `logHttpEntity` option:
240
+
```java
241
+
config.setLogHttpEntity(true).
242
+
```
243
+
In configuration file:
244
+
```java
245
+
logHttp=true
246
+
logHttpEntity=true
247
+
```
248
+
####Switching between JSON and XML
249
+
You can configure a client to make request either with JSON or XML content.
`JasperserverRestClient` supports two authentication types: SPRING and BASIC.
197
-
`SPRING` type of authentication means that your credentials are sent as a form to `/j_security_check directly/` uri. Using these types you obtain JSESSIONID cookie of authenticated session after sending credentials.
198
-
In the `BASIC` mode `JasperserverRestClient` uses basic authentication (sends encrypted credentials with each request).
199
-
Client uses `SPRING` authentication by default but you can specify authentication type in RestClientConfiguration instance:
Or set authentication type in configuration file (for details, read section [Configuration](https://github.com/Jaspersoft/jrs-rest-java-client/blob/master/README.md#configuration)).
204
-
Please notice, the basic authentication is not stateless and it is valid till method logout() is called or the application is restarted and you can not use this authentication type for Report Service, because all operations must be executed in the same session (for details, read section [Report services](https://github.com/Jaspersoft/jrs-rest-java-client/blob/master/README.md#report-services)).
205
277
###Anonymous session
206
278
For some Jasperserver services authentication is not required (for example, settings service, bundles service or server info service), so you can use anonymous session:
207
279
```java
@@ -1727,32 +1799,6 @@ final Map<String, String> bundle = session
1727
1799
.bundle("jasperserver_messages")
1728
1800
.getEntity();
1729
1801
```
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. Todothis you need to pass `com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.ErrorHandler` implementation to `JerseyRequestBuilder.buildRequest()` factory method.
1749
-
1750
-
JRSREST 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)`.
1756
1802
1757
1803
###Asynchronous API
1758
1804
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.
@@ -1780,35 +1826,6 @@ OperationResult<UsersListWrapper> result = ...
1780
1826
result.getSerializedContent();
1781
1827
```
1782
1828
1783
-
###Switching between JSON and XML
1784
-
You can configure a client to make request either with JSON or XML content.
It is possible to log outgoing requests and incoming responses using `logHttp` property of `RestCleintConfiguration`:
1804
-
```java
1805
-
config.setLogHttp(true);
1806
-
```
1807
-
Also, you are able to log entities using `logHttpEntity` option:
1808
-
```java
1809
-
config.setLogHttpEntity(true).
1810
-
```
1811
-
1812
1829
###Possible issues
1813
1830
1. <strong>Deploying jrs-rest-client within web app to any Appplication Server, e.g. JBoss, Glassfish, WebSphere etc.</strong>
1814
1831
jrs-rest-client uses the implementation of JAX-RS API of version 2.0 and if your application server does not support this version you will get an error. To solve this problem you need to add to your application a deployment configuration specific for your AS where you need to exclude modules with old JAX-RS API version. Example of such descriptor for JBoss AS you can find below:
0 commit comments