Skip to content

Commit 042a564

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

File tree

1 file changed

+81
-61
lines changed

1 file changed

+81
-61
lines changed

README.md

Lines changed: 81 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ 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+
* [Switching authentication type](#switching-authentication-type).
1415
* [Exception handling](#exception-handling).
16+
* [Logging](#logging).
17+
* [Switching between JSON and XML](#switching-between-json-and-xml).
1518
* [Client instantiation](#client-instantiation).
1619
3. [Authentication](#authentication).
1720
* [Anonymous session](#anonymous-session).
@@ -114,8 +117,8 @@ Table of Contents
114117
15. [Bundles service](#bundles-service).
115118
16. [Asynchronous API](#asynchronous-api).
116119
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).
120+
18.
121+
19.
119122
20. [Possible issues](#possible-issues).
120123
21. [Maven dependency to add jasperserver-rest-client to your app](#maven-dependency-to-add-jasperserver-rest-client-to-your-app).
121124
22. [License](#license).
@@ -131,37 +134,42 @@ Configuration
131134
-------------
132135
To start working with the library you should firstly configure one ore more instances of `JasperserverRestClient`.
133136
To do this you should create instance of `RestClientConfiguration`. It can be done in two ways:
137+
- loading configuration from file;
138+
- creation of manual configuration in java code.
134139
####Loading configuration from file:
135140
```java
136-
RestClientConfiguration configuration = RestClientConfiguration.loadConfiguration("url.properties");
141+
RestClientConfiguration configuration = RestClientConfiguration.loadConfiguration("configuration.properties");
137142
```
138143
Here is example of `configuration.properties` file:
139144
```java
140-
url=http://localhost:4444/jasperserver-pro
141-
connectionTimeout=100
145+
// required content
146+
url=http://localhost:8080/jasperserver-pro
147+
// optional content
148+
connectionTimeout=20
142149
readTimeout=20
143150
jasperserverVersion=v6_0_0
144-
authenticationType=REST
151+
authenticationType=SPRING
145152
logHttp=true
146-
logHttpEntity=false
153+
logHttpEntity=true
147154
restrictedHttpMethods=false
148155
handleErrors=true
149156
contentMimeType=JSON
150157
acceptMimeType=JSON
151158
```
152159
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}`.
160+
Please notice, configuration settings may be changed after loading manually in java code.
153161
####Creation of manual configuration
154162
To configure `JasperserverRestClient` manually, use the constructor of `RestClientConfiguration` and properties:
155163
```java
156164
RestClientConfiguration configuration = new RestClientConfiguration("http://localhost:8080/jasperserver");
157165
configuration.setAcceptMimeType(MimeType.JSON).setContentMimeType(MimeType.JSON).setJrsVersion(JRSVersion.v6_0_0).setLogHttp(true);
158166
```
159167
####HTTPS configuration
160-
<strong>To use HTTPS you need:</strong>
161-
1. Configure your server to support HTTPS
162-
2. Download [InstallCert](http://miteff.com/files/InstallCert-bin.zip) util and follow [InstallCert-Guide](http://www.mkyong.com/webservices/jax-ws/suncertpathbuilderexception-unable-to-find-valid-certification-path-to-requested-target/) instructions.
163-
3. Set HTTPS as your protocol in server URL, e.g. `https://localhost:8443/jasperserver`
164-
4. Configure trusted certificates if needed
168+
**To use HTTPS you need:**
169+
1. Configure your server to support HTTPS
170+
2. Download [InstallCert](http://miteff.com/files/InstallCert-bin.zip) util and follow [InstallCert-Guide](http://www.mkyong.com/webservices/jax-ws/suncertpathbuilderexception-unable-to-find-valid-certification-path-to-requested-target/) instructions.
171+
3. Set HTTPS as your protocol in server URL, e.g. `https://localhost:8443/jasperserver`
172+
4. Configure trusted certificates if needed
165173

166174
```java
167175
RestClientConfiguration configuration = new RestClientConfiguration("https://localhost:8443/jasperserver");
@@ -173,13 +181,31 @@ configuration.setTrustManagers(trustManagers);
173181
####X-HTTP-Method override
174182
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`:
175183
```java
176-
session.getStorage().getConfiguration().setRestrictedHttpMethods(true);
184+
configuration.setRestrictedHttpMethods(true);
177185
```
186+
Or in configuration file:
187+
```java
188+
restrictedHttpMethods=false
189+
````
178190
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
191+
####Switching authentication type
192+
`JasperserverRestClient` supports two authentication types: SPRING and BASIC.
193+
`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.
194+
In the `BASIC` mode `JasperserverRestClient` uses basic authentication (sends encrypted credentials with each request).
195+
Client uses `SPRING` authentication by default but you can specify authentication type in RestClientConfiguration instance:
196+
```java
197+
configuration.setAuthenticationType(AuthenticationType.SPRING);
198+
```
199+
Or set authentication type in configuration file:
200+
```java
201+
authenticationType=SPRING
202+
or
203+
authenticationType=BASIC
204+
```
205+
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)).
206+
####Exception handling
181207
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.
208+
1. handling of errors directly. This mode is allowed by default.
183209
2. getting operation result in any case with null entity and handling error after calling `getEntity()` method:
184210
```java
185211
OperationResult<InputStream> result = session
@@ -193,18 +219,50 @@ To apply the second strategy set `handleErrors` property of `RestCleintConfigura
193219
```java
194220
configuration.setHandleErrors(false);
195221
```
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-
222+
or specify this property in configuration file:
223+
```java
224+
handleErrors=true
225+
```
198226
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.
199227

200228
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.
201229

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)`.
230+
1. Existed handlers:
231+
* `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.
232+
2. You can create your own handler by implementing `com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.ErrorHandler`.
233+
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)`.
234+
235+
####Logging
236+
It is possible to log outgoing requests and incoming responses using `logHttp` property of `RestCleintConfiguration`:
237+
```java
238+
config.setLogHttp(true);
239+
```
240+
Also, you are able to log entities using `logHttpEntity` option:
241+
```java
242+
config.setLogHttpEntity(true).
243+
```
244+
In configuration file:
245+
```java
246+
logHttp=true
247+
logHttpEntity=true
248+
249+
####Switching between JSON and XML
250+
You can configure a client to make request either with JSON or XML content.
251+
```java
252+
RestClientConfiguration configuration = new RestClientConfiguration("http://localhost:4444/jasperserver");
253+
configuration.setContentMimeType(MimeType.XML);
254+
configuration.setAcceptMimeType(MimeType.XML);
255+
```
256+
Or in configuration.properties:
257+
```
258+
contentMimeType=JSON
259+
acceptMimeType=JSON
260+
or
261+
contentMimeType=XML
262+
acceptMimeType=XML
263+
```
206264
####Client instantiation:
207-
Here everything is easy, you need just to pass `configuration` to `JasperserverRestClient` constructor.
265+
After configuration you need just to pass `configuration` instance to `JasperserverRestClient` constructor.
208266
```java
209267
JasperserverRestClient client = new JasperserverRestClient(configuration);
210268
```
@@ -217,15 +275,6 @@ Session session = client.authenticate("jasperadmin", "jasperadmin");
217275
//authentication with multitenancy enabled
218276
Session session = client.authenticate("jasperadmin|organization_1", "jasperadmin");
219277
```
220-
`JasperserverRestClient` supports two authentication types: SPRING and BASIC.
221-
`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.
222-
In the `BASIC` mode `JasperserverRestClient` uses basic authentication (sends encrypted credentials with each request).
223-
Client uses `SPRING` authentication by default but you can specify authentication type in RestClientConfiguration instance:
224-
```java
225-
config.setAuthenticationType(AuthenticationType.SPRING);
226-
```
227-
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)).
228-
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)).
229278
###Anonymous session
230279
For some Jasperserver services authentication is not required (for example, settings service, bundles service or server info service), so you can use anonymous session:
231280
```java
@@ -1778,35 +1827,6 @@ OperationResult<UsersListWrapper> result = ...
17781827
result.getSerializedContent();
17791828
```
17801829
1781-
###Switching between JSON and XML
1782-
You can configure a client to make request either with JSON or XML content.
1783-
```java
1784-
RestClientConfiguration configuration = new RestClientConfiguration("http://localhost:4444/jasperserver");
1785-
configuration.setContentMimeType(MimeType.XML);
1786-
configuration.setAcceptMimeType(MimeType.XML);
1787-
```
1788-
or you can externilize configuration
1789-
```
1790-
url=http://localhost:4444/jasperserver/
1791-
contentMimeType=JSON
1792-
acceptMimeType=JSON
1793-
#contentMimeType=XML
1794-
#acceptMimeType=XML
1795-
```
1796-
```java
1797-
RestClientConfiguration configuration = RestClientConfiguration.loadConfiguration("jrs-client-config.properties");
1798-
```
1799-
1800-
###Logging
1801-
It is possible to log outgoing requests and incoming responses using `logHttp` property of `RestCleintConfiguration`:
1802-
```java
1803-
config.setLogHttp(true);
1804-
```
1805-
Also, you are able to log entities using `logHttpEntity` option:
1806-
```java
1807-
config.setLogHttpEntity(true).
1808-
```
1809-
18101830
###Possible issues
18111831
1. <strong>Deploying jrs-rest-client within web app to any Appplication Server, e.g. JBoss, Glassfish, WebSphere etc.</strong>
18121832
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

Comments
 (0)