Skip to content

Commit 4d780e9

Browse files
Merge pull request #103 from TanyaEf/master
Anonymous session and sessings service documentation.
2 parents 4729c93 + 1d8d87f commit 4d780e9

29 files changed

+680
-136
lines changed

README.md

Lines changed: 77 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ Table of Contents
1010
* [Loading configuration from file](#loading-configuration-from-file).
1111
* [Creation of manual configuration](#creation-of-manual-configuration).
1212
* [HTTPS configuration](#https-configuration).
13+
* [X-HTTP-Method override](#x-http-method-override).
1314
* [Client instantiation](#client-instantiation).
1415
3. [Authentication](#authentication).
16+
* [Anonymous session](#anonymous-session).
1517
* [Invalidating session](#invalidating-session).
1618
4. [Report services](#report-services).
1719
* [Running a report](#running-a-report).
@@ -58,7 +60,7 @@ Table of Contents
5860
* [Setting Role Membership](#setting-role-membership).
5961
* [Deleting a Role](#deleting-a-role).
6062
5. [The Settings Service](#settings-service).
61-
* [Getting server specific settings](#getting-settings).
63+
* [Getting server specific settings](#getting-server-specific-settings).
6264
7. [Repository Services](#repository-services).
6365
1. [Resources Service](#resources-service).
6466
* [Searching the Repository](#searching-the-repository).
@@ -149,6 +151,12 @@ TrustManager[] trustManagers = new TrustManager[1];
149151
trustManagers[0] = x509TrustManager;
150152
configuration.setTrustManagers(trustManagers);
151153
```
154+
####X-HTTP-Method override
155+
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`:
156+
```java
157+
session.getStorage().getConfiguration().setRestrictedHttpMethods(true);
158+
```
159+
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.
152160
####Client instantiation:
153161
Here everything is easy, you need just to pass `configuration` to `JasperserverRestClient` constructor.
154162
```java
@@ -163,6 +171,11 @@ Session session = client.authenticate("jasperadmin", "jasperadmin");
163171
//authentication with multitenancy enabled
164172
Session session = client.authenticate("jasperadmin|organization_1", "jasperadmin");
165173
```
174+
###Anonymous session
175+
For some Jasperserver services authentication is not required (for example, settings service and server info service), so you can use anonymous session:
176+
```java
177+
AnonymousSession session = client.getAnonymousSession();
178+
```
166179
####Invalidating session
167180
Not to store session on server you can invalidate it with `logout()` method.
168181
```java
@@ -190,6 +203,19 @@ OperationResult<InputStream> result = client
190203
.run();
191204
InputStream report = result.getEntity();
192205
```
206+
Also you can use this method to run report with several values for the same parameter. In this case new values of the parameter are added to the previous ones (new values do not replace previous values of the parameter):
207+
```java
208+
OperationResult<InputStream> result = client
209+
.authenticate("superuser", "superuser")
210+
.reportingService()
211+
.report("/reports/samples/Cascading_multi_select_report")
212+
.prepareForRun(ReportOutputFormat.PDF, 1)
213+
.parameter("Cascading_state_multi_select", "CA")
214+
.parameter("Cascading_state_multi_select", "OR", "WA")
215+
.parameter("Cascading_name_single_select", "Adams-Steen Transportation Holdings")
216+
.parameter("Country_multi_select", "USA")
217+
.run();
218+
```
193219
In this mode you don't need to work in one session. In the above code we specified report URI, format in which we want to get a report and some report parameters. As we a result we got `InputStream` instance. In synchronous mode as a response you get a report itself while in asynchronous you get just a descriptor with report ID which you can use to download report afer it will be ready.
194220

195221
In order to run a report in asynchronous mode, you need firstly build `ReportExecutionRequest` instance and specify all the parameters needed to launch a report. The response from the server is the `ReportExecutionDescriptor` instance which contains the request ID needed to track the execution until completion and others report parameters. Here's the code to run a report:
@@ -390,7 +416,8 @@ To create an organization, put all information in an organization descriptor, an
390416
```java
391417
Organization organization = new Organization();
392418
organization.setAlias("myOrg1");
393-
419+
```
420+
``java
394421
OperationResult<Organization> result = session
395422
.organizationsService()
396423
.organizations()
@@ -830,18 +857,25 @@ Settings Service
830857

831858
It provides method that allow you to get server specific settings, required by UI to work with the server in sync. There can be formats and patterns, modes for some modules etc.
832859

833-
####Getting settings
834-
To get settings, use the `getEntity()` method and specify the group of settings in the `group()` method. The method `getEntity()` returns map of settings where the keys in the map are names of the settings and values can be any objects.
835-
860+
####Getting server specific settings
861+
To get settings, use the `getEntity()` method and specify the group of settings in the `group()` method and class of entity as shown below. The method `getEntity()` returns instance of specified class:
836862
```java
837863
final Map settings = session
838864
.settingsService()
839865
.settings()
840-
.group(group)
866+
.group(group, Map.class)
841867
.getEntity();
842868

843869
```
844-
Supported groups are:
870+
Please notice, you can get settings of user’s time zones in this way as List only:
871+
```java
872+
final List settings = session
873+
.settingsService()
874+
.settings()
875+
.group("userTimeZones", List.class)
876+
.getEntity();
877+
```
878+
Supported groups of settings are:
845879

846880
1. “request”. Settings related to current AJAX request configuration. Returned settings are: maxInactiveInterval, contextPath;
847881

@@ -865,6 +899,42 @@ Supported groups are:
865899

866900
11. “adhocview”. Different configuration dictionary values and lists for ad hoc. Configuration of settings depends on configuration of Jaspersoft server.
867901

902+
There is another way to get settings using specified methods for groups of settings that return specific object of settings:
903+
```java
904+
Final RequestSettings settings = session
905+
.settingsService()
906+
.settings()
907+
.ofRequestGroup()
908+
.getEntity();
909+
```
910+
Pleace notice, you should use List interface to get user’s time zones setting in this way:
911+
```java
912+
final List<UserTimeZone> settings = session
913+
.settingsService()
914+
.settings()
915+
.ofUserTimeZonesGroup()
916+
.getEntity();
917+
```
918+
Or you can get List of specified DTO for user’s time zones using GenericType class:
919+
```java
920+
final List<UserTimeZone> settings = session
921+
.settingsService()
922+
.settings()
923+
.group("userTimeZones", new GenericType<List<UserTimeZone>>() {})
924+
.getEntity();
925+
```
926+
Supported specified methods are:
927+
```java
928+
OperationResult<RequestSettings> ofRequestGroup();
929+
OperationResult<DataSourcePatternsSettings> ofDataSourcePatternsGroup();
930+
OperationResult<List<UserTimeZone>> ofUserTimeZonesGroup();
931+
OperationResult<AwsSettings> ofAwsGroup();
932+
OperationResult<DecimalFormatSymbolsSettings> ofDecimalFormatSymbolsGroup();
933+
OperationResult<DashboardSettings> ofDashboardGroup();
934+
OperationResult<GlobalConfigurationSettings> ofGlobalConfigurationGroup();
935+
OperationResult<DateTimeSettings> ofDateTimeGroup();
936+
OperationResult<InputControlsSettings> ofInputControlsGroup();
937+
```
868938

869939
Repository Services
870940
=====================

src/integration-test/java/com/jaspersoft/jasperserver/jaxrs/client/apiadapters/authority/users/UsersServiceIT.java

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,60 @@
44
import com.jaspersoft.jasperserver.jaxrs.client.core.JasperserverRestClient;
55
import com.jaspersoft.jasperserver.jaxrs.client.core.RestClientConfiguration;
66
import com.jaspersoft.jasperserver.jaxrs.client.core.Session;
7-
import junit.framework.Assert;
7+
import java.util.List;
8+
import org.testng.Assert;
89
import org.testng.annotations.AfterMethod;
910
import org.testng.annotations.BeforeMethod;
1011
import org.testng.annotations.Test;
1112

12-
import java.util.List;
13-
1413
/**
1514
* @author Alexander Krasnyanskiy
1615
*/
1716
public class UsersServiceIT {
1817

18+
private RestClientConfiguration config;
19+
private JasperserverRestClient client;
1920
private Session session;
2021

2122
@BeforeMethod
2223
public void before() {
24+
2325
RestClientConfiguration cfg = new RestClientConfiguration("http://localhost:4444/jasperserver-pro");
2426
JasperserverRestClient client = new JasperserverRestClient(cfg);
27+
2528
session = client.authenticate("superuser", "superuser");
2629
}
2730

2831
@Test
2932
public void shouldReturnAllUsers() {
3033

31-
// When
34+
35+
//When
36+
37+
List<ClientUser> users = session
38+
.usersService()
39+
.allUsers()
40+
.get()
41+
.getEntity()
42+
.getUserList();
43+
44+
//Then
45+
Assert.assertTrue(users.size() > 3);
46+
}
47+
48+
@Test
49+
public void should_return_list_users_by_role() {
50+
51+
//When
3252
List<ClientUser> users = session
3353
.usersService()
3454
.allUsers()
3555
.get()
3656
.getEntity()
3757
.getUserList();
3858

39-
// Then
59+
//Then
60+
4061
Assert.assertTrue(users.size() > 3);
4162
}
4263

src/integration-test/java/com/jaspersoft/jasperserver/jaxrs/client/apiadapters/reporting/ReportingServiceIT.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
import com.jaspersoft.jasperserver.jaxrs.client.core.JasperserverRestClient;
44
import com.jaspersoft.jasperserver.jaxrs.client.core.RestClientConfiguration;
55
import com.jaspersoft.jasperserver.jaxrs.client.core.operationresult.OperationResult;
6+
import java.io.InputStream;
67
import junit.framework.Assert;
78
import org.testng.annotations.AfterMethod;
89
import org.testng.annotations.BeforeMethod;
910
import org.testng.annotations.Test;
1011

11-
import java.io.InputStream;
12-
12+
/**
13+
* @author Alex Krasnyanskiy
14+
* @author Tetiana Iefimenko
15+
*/
1316
public class ReportingServiceIT {
1417

1518
private RestClientConfiguration configuration;
@@ -28,14 +31,18 @@ public void should_return_proper_entity_if_pass_jrprint_report_output_format() {
2831
OperationResult<InputStream> result = client
2932
.authenticate("superuser", "superuser")
3033
.reportingService()
31-
.report("/public/Samples/Reports/08g.UnitSalesDetailReport")
32-
.prepareForRun(ReportOutputFormat.JRPRINT, 1)
34+
.report("/organizations/organization_1/adhoc/topics/Cascading_multi_select_topic")
35+
.prepareForRun(ReportOutputFormat.PDF, 1)
36+
.parameter("Cascading_state_multi_select", "CA")
37+
.parameter("Cascading_state_multi_select", "OR", "WA")
38+
.parameter("Cascading_name_single_select", "Adams-Steen Transportation Holdings")
39+
.parameter("Country_multi_select", "USA")
3340
.run();
3441

3542
InputStream entity = result.getEntity();
36-
3743
/** Then **/
3844
Assert.assertNotNull(entity);
45+
3946
}
4047

4148
@AfterMethod

src/integration-test/java/com/jaspersoft/jasperserver/jaxrs/client/apiadapters/resources/ResourcesServiceIT.java

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,36 @@
11
package com.jaspersoft.jasperserver.jaxrs.client.apiadapters.resources;
22

3-
import com.jaspersoft.jasperserver.dto.resources.ClientFolder;
4-
import com.jaspersoft.jasperserver.dto.resources.ClientResource;
3+
import com.jaspersoft.jasperserver.jaxrs.client.core.JRSVersion;
54
import com.jaspersoft.jasperserver.jaxrs.client.core.JasperserverRestClient;
5+
import com.jaspersoft.jasperserver.jaxrs.client.core.MimeType;
66
import com.jaspersoft.jasperserver.jaxrs.client.core.RestClientConfiguration;
77
import com.jaspersoft.jasperserver.jaxrs.client.core.Session;
8+
import java.io.ByteArrayInputStream;
9+
import java.util.concurrent.TimeUnit;
10+
import javax.ws.rs.core.Response;
811
import org.testng.Assert;
912
import org.testng.annotations.AfterMethod;
1013
import org.testng.annotations.BeforeMethod;
1114
import org.testng.annotations.Test;
1215

13-
import javax.ws.rs.core.Response;
14-
import java.io.ByteArrayInputStream;
15-
import java.util.concurrent.TimeUnit;
16-
1716
/**
1817
* @author Alexander Krasnyanskiy
18+
* @author tetiana Iefimenko
1919
*/
2020
public class ResourcesServiceIT {
2121

22+
private RestClientConfiguration config;
23+
private JasperserverRestClient client;
2224
private Session session;
2325

2426
@BeforeMethod
2527
public void before() {
26-
RestClientConfiguration cfg = new RestClientConfiguration("http://localhost:8085");
27-
JasperserverRestClient client = new JasperserverRestClient(cfg);
28-
session = client.authenticate("jasperadmin", "jasperadmin");
29-
30-
ClientFolder folder = new ClientFolder()
31-
.setUri("/reports/testFolder")
32-
.setLabel("Test Folder")
33-
.setDescription("Test folder description");
34-
35-
ClientResource result = session.resourcesService()
36-
.resource("/reports/testFolder")
37-
.createNew(folder)
38-
.getEntity();
39-
28+
config = new RestClientConfiguration("http://localhost:4444/jasperserver-pro");
29+
config.setAcceptMimeType(MimeType.JSON);
30+
config.setContentMimeType(MimeType.JSON);
31+
config.setJrsVersion(JRSVersion.v6_0_1);
32+
client = new JasperserverRestClient(config);
33+
session = client.authenticate("superuser", "superuser");
4034
}
4135

4236

src/integration-test/java/com/jaspersoft/jasperserver/jaxrs/client/apiadapters/settings/SettingsServiceIT.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,40 @@
11
package com.jaspersoft.jasperserver.jaxrs.client.apiadapters.settings;
22

3+
import com.jaspersoft.jasperserver.jaxrs.client.core.AnonymousSession;
34
import com.jaspersoft.jasperserver.jaxrs.client.core.JRSVersion;
45
import com.jaspersoft.jasperserver.jaxrs.client.core.JasperserverRestClient;
56
import com.jaspersoft.jasperserver.jaxrs.client.core.MimeType;
67
import com.jaspersoft.jasperserver.jaxrs.client.core.RestClientConfiguration;
7-
import com.jaspersoft.jasperserver.jaxrs.client.core.Session;
8-
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.*;
8+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.AwsSettings;
9+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.DashboardSettings;
10+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.DataSourcePatternsSettings;
11+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.DateTimeSettings;
12+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.DecimalFormatSymbolsSettings;
13+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.GlobalConfigurationSettings;
14+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.InputControlsSettings;
15+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.RequestSettings;
16+
import com.jaspersoft.jasperserver.jaxrs.client.dto.settings.UserTimeZone;
17+
import java.util.List;
18+
import java.util.Map;
19+
import javax.ws.rs.core.GenericType;
920
import org.testng.annotations.AfterMethod;
1021
import org.testng.annotations.BeforeMethod;
1122
import org.testng.annotations.Test;
1223

13-
import javax.ws.rs.core.GenericType;
14-
import java.util.List;
15-
import java.util.Map;
16-
1724
import static junit.framework.Assert.assertFalse;
1825
import static junit.framework.Assert.assertNotNull;
1926
import static junit.framework.Assert.assertSame;
2027
import static junit.framework.Assert.assertTrue;
2128

29+
/**
30+
* @author
31+
* @author Tetiana Iefimenko
32+
* */
2233
public class SettingsServiceIT {
2334

2435
private RestClientConfiguration config;
2536
private JasperserverRestClient client;
26-
private Session session;
37+
private AnonymousSession session;
2738

2839
@BeforeMethod
2940
public void before() {
@@ -32,7 +43,7 @@ public void before() {
3243
config.setContentMimeType(MimeType.JSON);
3344
config.setJrsVersion(JRSVersion.v6_0_0);
3445
client = new JasperserverRestClient(config);
35-
session = client.authenticate("superuser", "superuser");
46+
session = client.getAnonymousSession();
3647
}
3748

3849
@Test
@@ -231,7 +242,8 @@ public void should_return_list_of_userTimeZone_dto_by_genericType() {
231242
final List<UserTimeZone> settings = session
232243
.settingsService()
233244
.settings()
234-
.group("userTimeZones", new GenericType<List<UserTimeZone>>(){})
245+
.group("userTimeZones", new GenericType<List<UserTimeZone>>() {
246+
})
235247
.getEntity();
236248

237249
// Then

0 commit comments

Comments
 (0)