rest_v2 report input control services on JasperReports Server Pro

Hi,

I am having a hard time figuring out a pressing issue related to setting input controls via JasperReports Server Web Services. I want to use the web service accessible by http://<host>:<port>/jasperserver[-pro]/rest_v2/reports/path/to/report/inputControls/<ic1>;<ic2>;.../values/ , and I wrote some code closely following the specification of the service (from JasperReports Server Web Services Guide, Release 5.6, pg. 86).

I use Java with Jersey client, and have the following code:

    public static Client login( String username,
                                String password ) {
 
        Client client = ClientBuilder.newClient();
 
        //Now setup authentication
        HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(username,
                                                                             password);
        client.register(feature);
 
        return client;
    }
 
    public static String setInputControls( Client client,
                                            String report,
                                            String[]... args ) throws Exception {        
 
        //Target JasperReports Server, our report
        String api_link = "http://localhost:8091/jasperserver-pro/rest_v2/reports/"
                        + report + "/inputControls/";
 
        for (String[] arg : args) {
            api_link = api_link + arg[0] + ";";
        }    
        api_link = api_link.substring(0, api_link.length() - 1) + "/values/";
 
        WebTarget target = client.target(api_link);
 
        String json_param = "{\n";
 
        for (String[] arg : args) {
            json_param = json_param + "\"" + arg[0] + "\": [";
 
            for (int i = 1; i < arg.length; i++) {
                json_param = json_param + "\"" + arg[i] + "\", ";
            }
            json_param = json_param.substring(0, json_param.length() - 2) + "],\n";
        }
        json_param = json_param + "}";
 
         Response response =
                  target.request().post(Entity.entity(json_param, MediaType.APPLICATION_JSON));
 
        return "HTTP STATUS: " + response.getStatus() +
               "<br><br>" + response.readEntity(String.class);
    } 

to run the program as follows

Client client = login("jasperadmin", "jasperadmin");
 
return setInputControls( client, report, new String[] {"week_1", "9", "15", "27",
                                                                 "11"},
                                         new String[] {"day_name_1", "friday "} )

The code seems to do exactly what it is supposed to do, but when I download the report I tried to change the input control values of, I always get the same old version with the default input control values. Even though my query always returns HTTP status 200 and a renewed JSON of input control values, exactly as it should on success.

What did I do wrong? I have spent almost a day trying to figure it out, but the code seems to do what it should...

tadaskrisciunas's picture
Joined: Jul 2 2014 - 2:43am
Last seen: 9 years 1 week ago

1 Answer:

marianol's picture
17626
Joined: Sep 13 2011 - 8:04am
Last seen: 4 years 11 months ago
Feedback