Jump to content
JasperReports 7.0 is now available ×

Web Service DS in JasperReports Sample (using Plain Old Java)


Recommended Posts

Hi there!

The WebService Data Source works like a charme inside the Jaspersoft Studio and in the JasperReports Server Pro.
Now I try to ceate a basic Java Class which should create the report using the API.

And here is my problem at all - is there any example available for generating a PDF file out of a report which uses the Web Service Data Source?

I struggle with the Fill Manager...

JasperFillManager.fillReportToFile("reports/SampleReport.jasper", reportParams,
                <And What goes here?>);
I tried the WSEmptyDatasource, but this seems to be the wrong one.
I used the 
WebServiceDataAdapterServiceFactory to contribute the Report Parameters Map and this seems to be working.
I feel close to a solution but I cannot see one actually :)
 
Thank you very much!

Best regards,
Kevin
 
Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

With this I'll get a NPE at com.jaspersoft.webservice.data.query.WebServiceQueryExecuter.getInternalQE(WebServiceQueryExecuter.java:243)

complete sample:

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

  • 2 months later...

I have the same problem.

I try to write code for my servlet, but i didn't find docs.

I have created jrxml from jasper studio and work great, but i do not have example to use it in my java code.

I try with kavinb code without success. Can someone share docs or code?

Best regards.

Marcello 

Link to comment
Share on other sites

  • 4 months later...
  • 3 weeks later...

Seconding Edwin L, is there a working example of running a report from java? My reports run just fine from within JaspersoftStudio, but am getting the same NPE as described above by Kevin.

Any help would be appreciated,

Howard

Here's some additional info,

 - I was able to trace the NPE to be in the WebServiceQueryExecuter.class, it tries to connect to the web service providing the data for the report. Based on the debugger, all of the urls and parameters for the web service are being pulled in correctly from the report file (.jasper).

 - To do the connection, it uses the method 'callWS' from the WebServiceConnector.class. This method returns a null, which then causes the exception quoted in the issue 'com.jaspersoft.webservice.data.query.WebServiceQueryExecuter.getInternalQE(WebServiceQueryExecuter.java:243)'.

Here is the full stack trace, if that helps,

SEVERE: Servlet.service() for servlet [PDFViewer] in context with path [/PCAReportViewer] threw exception
java.lang.NullPointerException
at com.jaspersoft.webservice.data.query.WebServiceQueryExecuter.getInternalQE(WebServiceQueryExecuter.java:243)
at com.jaspersoft.webservice.data.query.WebServiceQueryExecuter.close(WebServiceQueryExecuter.java:200)
at net.sf.jasperreports.engine.fill.JRFillDataset.closeQueryExecuter(JRFillDataset.java:1322)
at net.sf.jasperreports.engine.fill.JRFillDataset.closeDatasource(JRFillDataset.java:1303)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:608)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:163)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:474)
at net.sf.jasperreports.engine.JasperFillManager.fillToFile(JasperFillManager.java:259)
at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:746)
at PDFViewer.doGet(PDFViewer.java:89)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
 
Also, as a reference, here are the jar files that I've pulled into my servlet:
commons-beanutils-1.9.0
commons-collections-3.2.2
commons-digester-2.1
commons-logging-1.1.1
customDatasource_WebService_JRS_wrapper
groovy-all_2.4.5
httpcore-4.3.3
iText-2.1.7.js2
jackson-annotations-2.4.3
jackson-core-2.4.3
jackson-databind-2.4.3
jasperreports-6.3.1
WebServiceDataAdapter

 

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...

Whew, that was a dilly of a problem. As it turns out the Web Service DataSource is notoriously bad at letting you know what's going on. As it turned out, once I added httpclient-4.3.6.jar to my build path, it worked!!

So, the final list of jars that I added to the build path are:

commons-beanutils-1.9.0
commons-collections-3.2.2
commons-digester-2.1
commons-logging-1.1.1
customDatasource_WebService_JRS_wrapper
ElasticSearchConnector
groovy-all_2.4.5
httpclient-4.3.6
httpcore-4.3.3
iText-2.1.7.js2
jackson-annotations-2.4.3
jackson-core-2.4.3
jackson-databind-2.4.3
jasperreports-6.3.1
WebServiceDataAdapter
xalan-2.7.1
 
I hope this helps.

 

Link to comment
Share on other sites

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...