Scheduling a report that has default parameter values throws BAD Request error

0

I have a report with some required parameters(paramA="default_a", paramB="default_b") with default values, it works as expected when I run it from jasper server UI or by using jasper rest client (https://github.com/Jaspersoft/jrs-rest-java-client). While scheduling this report I am supplying the parameters (paramA="2012", paramB="xyz") using the rest client  like below :

    Job job = new Job();

        JobSource s = new JobSource();
        Map<String, Object> reportParamsMap = new HashMap<String, Object>();     
        reportParamsMap.put("paramA", "2012");
        reportParamsMap.put("paramB", "xyz");
        s.setParameters(reportParamsMap); 
        job.setSource(s);

..... set other job fileds (label, description, outputforamts etc ).  

OperationResult<Job> result = session.jobsService().scheduleReport(job);

and my json that was sent  to http://localhost:8080/jasperserver/rest_v2/jobs is 

{  
   "id":null,
   "version":null,
   "username":null,
   "label":"MyReport",
   "description":"Scheduling my report to run daily",
   "creationDate":null,
   "baseOutputFilename":"MyReport_UserID_1546020148418",
   "outputLocale":null,
   "repositoryDestination":{  
      "folderURI":"/reports/Test",
      "id":null,
      "outputDescription":null,
      "overwriteFiles":null,
      "sequentialFilenames":null,
      "version":null,
      "timestampPattern":null,
      "saveToRepository":null,
      "defaultReportOutputFolderURI":null,
      "usingDefaultReportOutputFolderURI":null,
      "outputLocalFolder":"/reports/Test",
      "outputFTPInfo":null
   },
   "source":{  
      "reportUnitURI":"/reports/Test/MyReport",
      "parameters":{  
         "parameterValues":{  
            "paramA":"2012",
            "paramB":"xyz"        
         }
      }
   },
   "outputFormats":{  
      "outputFormat":[  
         "PDF"
      ]
   },
   "trigger":{  
      "simpleTrigger":{  
         "id":null,
         "version":null,
         "timezone":null,
         "calendarName":null,
         "startType":2,
         "startDate":"2018-12-28 12:02",
         "endDate":null,
         "misfireInstruction":null,
         "occurrenceCount":1,
         "recurrenceInterval":0,
         "recurrenceIntervalUnit":"DAY"
      }
   },
   "outputTimeZone":null
}

And I get :

2 < 400
2 < Connection: close
2 < Content-Length: 279
2 < Content-Type: application/errorDescriptor+json
2 < Date: Fri, 28 Dec 2018 19:37:39 GMT
2 < P3P: CP="ALL"
2 < X-XSS-Protection: 1; mode=block
{"message":"There was an error on the server. Try again or contact site administrators. (Error UID: 145f1d97-8204-4a99-a1c7-1912c44a7597)","errorCode":"serialization.error","errorUid":"145f1d97-8204-4a99-a1c7-1912c44a7597","parameters":["source.parameters.parameterValues",null]}

After this statement System.out.println(result.getEntity());

com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.BadRequestException: Bad Request
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.DefaultErrorHandler.handleStatusCodeError(DefaultErrorHandler.java:111)
    at com.jaspersoft.jasperserver.jaxrs.client.core.exceptions.handling.DefaultErrorHandler.handleError(DefaultErrorHandler.java:68)
    at com.jaspersoft.jasperserver.jaxrs.client.core.operationresult.NullEntityOperationResult.getEntity(NullEntityOperationResult.java:53)

....

When I do not set the parameters to the job source like (  s.setParameters(reportParamsMap); ), the scheduler creates the job but with the default parameters which is pointless in my case.

Question: How to send report parameters dynamically while scheduling a job. 

UPDATE-1: Jasper server versin 7.1.0. produced above errors 

UPDATE-2: Jasper server versin 6.4.0 does not  produce the above error but it schedules the report with default parameters. 

 

 

 

kothany's picture
Joined: Nov 16 2018 - 1:46pm
Last seen: 1 month 3 weeks ago

1 Answer:

0

Ok.It was my mistake while creating the report parameter map. So by changing the follwing code from :

 reportParamsMap.put("paramA", "2012");

 reportParamsMap.put("paramB", "xyz");

to 

 reportParamsMap.put("paramA", new String[]{"2012"});

 reportParamsMap.put("paramB", new String[]{"xyz"}); // you can set list of strings too

resolved my problem.

kothany's picture
Joined: Nov 16 2018 - 1:46pm
Last seen: 1 month 3 weeks ago
Feedback
randomness