Jump to content
Changes to the Jaspersoft community edition download ×

How to fill a report from java call using the webservice adapter


Recommended Posts

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!



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]


Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...