Jump to content
We've recently updated our Privacy Statement, available here ×

jblaisure

Members
  • Posts

    1
  • Joined

  • Last visited

jblaisure's Achievements

Newbie

Newbie (1/14)

  • Week One Done
  • One Month Later
  • One Year In
  • First Post Rare
  • Conversation Starter Rare

Recent Badges

0

Reputation

  1. Hello all! Is there an example on how to use java to call a report using the web service adapter? I was referencing this post https://community.jaspersoft.com/questions/1032761/web-service-ds-jasperreports-sample-using-plain-old-java I am getting the error: incompatible types: SimpleJasperReportsContext cannot be converted to ParameterContributorContext What should I be using in place of this? Any help would be very much appreciated! Code: public class JasperReportsGenerator { public static void main(String[] args) { // Instantiate Web Service Data Source Data Adapter WebServiceDataAdapterImpl wsDataAdapter = new WebServiceDataAdapterImpl(); wsDataAdapter.setName("WS DS NAME"); wsDataAdapter.setWsUri("http://localhost:8090/some/service"); wsDataAdapter.setVerb(VerbType.GET.toString()); wsDataAdapter.setLanguage(LanguageType.JSON); wsDataAdapter.setAuthType(AuthType.NONE); SimpleJasperReportsContext jasperReportsContext = new SimpleJasperReportsContext(); jasperReportsContext.setProperty("webservice", "com.jaspersoft.webservice.data.query.WebServiceQueryExecuterFactory"); jasperReportsContext.setProperty("WebServiceQuery", "com.jaspersoft.webservice.data.query.WebServiceQueryExecuterFactory"); WebServiceDataAdapterServiceFactory factory = WebServiceDataAdapterServiceFactory .getInstance(); WebServiceDataAdapterService dataAdapterService = (WebServiceDataAdapterService) factory .getDataAdapterService(jasperReportsContext, wsDataAdapter); dataAdapterService.dispose(); // Instantiate report properties map (REPORT_PARAMETERS) Map<String, Object> reportParams = new HashMap<String, Object>(); try { dataAdapterService.contributeParameters(reportParams); System.out.println("Filling Reports..."); long start = System.currentTimeMillis(); JasperFillManager.fillReportToFile("reports/SampleReport.jasper", reportParams); System.out.println("Filling time: " + (System.currentTimeMillis() - start)); System.out.println("Exporting to PDFs..."); start = System.currentTimeMillis(); File sourceFile = new File("reports/SampleReport.jrprint"); JasperPrint jasperPrint = (JasperPrint) JRLoader.loadObject(sourceFile); File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".pdf"); JRPdfExporter exporter = new JRPdfExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile)); SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration(); exporter.setConfiguration(configuration); exporter.exportReport(); System.out.println("Exporting time: " + (System.currentTimeMillis() - start)); } catch (JRException | IOException e) { System.err.println("Error in executiong the reports!"); System.err.println(e); } }}[/code]
×
×
  • Create New...