change datasource via rest service

Hi there,
I'm trying to change a report datasource via REST Services, but my HTTP request does not seem to overwrite the report data source which has been deployed on Jasper Server. I guess there is something wrong with my resource descriptor. This is the java code I'm using: 

HttpRequestBase httpReq = new HttpPut();
     BasicHttpEntity reqEntity = new BasicHttpEntity();
     String requestXml="<resourceDescriptor name='TestUdc1' wsType='reportUnit' " +
                       "uriString='/reports/test/TestUdc' isNew='false'>" +
                       " <label>Bar Unit</label> " +
                       "<description>This is a test</description> " ;
 
     String requestXml2="<resourceDescriptor name='' wsType='datasource' uriString='/reports/test/TestUdc' isNew='false'>"+
                        "<label> Test </label>"+
                        "<resourceProperty name='PROP_REFERENCE_URI'>"+
                        "<value>/datasources/PilocDS</value>"+
                        "</resourceProperty>"+
                        "<resourceProperty name='PROP_IS_REFERENCE'>"+
                        "<value>true</value>"+
                        "</resourceProperty>"+
                        "</resourceDescriptor>"+
                        "</resourceDescriptor>";
 
     requestXml=requestXml+requestXml2;
     reqEntity.setContent(new ByteArrayInputStream(requestXml.getBytes()));
     ((HttpEntityEnclosingRequestBase) httpReq).setEntity(reqEntity);
 
     URI uri = createURI("/report/reports/test/TestUdc?RUN_OUTPUT_FORMAT=HTML", null, false);            
     httpReq.setURI(uri);
     httpRes = httpClient.execute(httpReq, httpContext);
     System.out.println("Response status line:"+httpRes.getStatusLine());
 
     String responseReportRD = EntityUtils.toString(httpRes.getEntity());
 
     DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
     DocumentBuilder builder = domFactory.newDocumentBuilder();
     StringReader sr = new StringReader(responseReportRD);
     InputSource is = new InputSource(sr);
     Document xmlDoc = builder.parse(is);
 
     //Extracting the report's UUID
     NodeList nodes = xmlDoc.getElementsByTagName("uuid");
     String reportUuid = nodes.item(0).getTextContent();
     System.out.println("-----ReportUUid:"+reportUuid);

Any suggestion would be appreciated.

Thanks,

Alessandro

marascoalessandro's picture
Joined: Jul 26 2013 - 8:39am
Last seen: 10 years 2 months ago

2 Answers:

Sorry for reviving this dead post, but was never answered and the title is perfect.

Is it possible to change the datasource in the rest call? This is what I'm trying:

http://localhost:8080/jasperserver/rest_v2/reports/unik/ReporteDiario.pdf?REPORT_DATA_SOURCE=resource_id

Replace the resource_id with any REPORT_DATA_SOURCE ID. But it doesn't work.

If it isn't possible, what is the motive? Where I can read about it?

Thank you! Luciano.

lgraziani2712's picture
Joined: Jul 20 2018 - 7:00am
Last seen: 4 years 9 months ago

I found a solution! Is not through the REST API but with environment variables! (Even better)

Doc: https://community.jaspersoft.com/documentation/tibco-jasperreports-serve...

Short answer: configure one data source with environment variables, and then set those variables on the server, role or user.

Luciano.

lgraziani2712's picture
Joined: Jul 20 2018 - 7:00am
Last seen: 4 years 9 months ago
Feedback
randomness