Pass paramaters using jasperserver API to a datasource invoked by a report


Hi all,

At the moment I'm not sure how to proceed  since I have created  a custom datasource that connects with a RESTful service that provides a JSON document that is parsed and displayed on the report. The service needs to send some parameters to obtain the document wanted. I find no way of extracting these parameters, getting and using their value.

Here is my datasource code:

package dataSources;
import com.eqb.utilities.HttpRestClient;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;import org.apache.commons.lang.ArrayUtils;
import org.json.JSONException;
import org.json.JSONObject;import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
import net.sf.jasperreports.engine.JasperReport;
public class AnnualStatementDataSource implements JRDataSource {
    private Integer counter = -1;
    private String jsonText = "";    
    public boolean next() throws JRException {
        if(counter < 0)
            return true;
        return false;
    public Object getFieldValue(JRField jrField) throws JRException {
        HttpRestClient http = new HttpRestClient();
        String fieldValue = "";
        jsonText = http.sendPostRequest("some_url", "jasper_parameter");
        fieldValue = getFieldValueFromJson(jsonText,jrField.getName());
        return fieldValue;
    public static JRDataSource StatementDataSource(){
        return new StatementDataSource();

IMPORTANT NOTE: The report instantiates this datasource using a data adapter that invokes this datasource.

If anyone could point me into the right direction, thank you and please.

ramonc's picture
Joined: Jun 13 2017 - 8:33am
Last seen: 1 day 15 min ago

0 Answers:

No answers yet