简体   繁体   中英

How to make a subreport that uses web service as the data source work in Jasper Reports

Can someone post a working example of how to define a subreport using web service as the datasource?

I am reading this:

http://community.jaspersoft.com/project/web-service-data-source

Under the section "SubReport and Additional Datasets", I need to cater the scenario for (2):

you have a main resultset that you wish to loop, and for each row you want to execute a new query (webservice call)

In the subreport configuration (or the dataset) specify not to use any connection at all (leave blank both the connection expression and the datasource expression. The only thing we'll have to do is passing some mandatory parameters for internal webservice datasource to work properly:

  • uriKeyauth
  • TypeKey
  • authParametersKey
  • languageKey
  • verbKey

I am not able to understand what to do here based on the above statements. These parameters are defined in the web service subreport. Am I supposed to pass them back to the main report? If so how am I supposed to do it in Jaspersoft Studio? I am using version 6.2. Even after I define these parameters in the main report, when I run preview, I get the error:

Caused by: net.sf.jasperreports.engine.JRException: Verb should be POST or GET . is not a valid verb

After struggling with this for quite a while, I found the following.

In my case, the default data adapter in the main report is JDBC. For each row returns from the SQL query, one particular column value is used as a GET parameter for the web service data adapter or WebServiceQuery.

I cannot make this work with subreport. However, I can get this to work with a dataset associated with a table.

A dataset using the web service data adapter has to be created. Parameters that are required for the GET parameters need to be defined in the dataset.

After the dataset is created, create a table or other elements using this dataset. Under the dataset tab in the table properties, define the parameters which should have the relevant field values (eg, $F{field1}).

The web service dataset also needs to connect to the main dataset. All this does is define the web service parameters: uriKey, authTypeKey, authParametersKey, languageKey, verbKey in the main report.

Once this is done, previewing the main report will also render the table with results obtained from the web service data adapter.

The steps to I use in Jasper Studio 6.3 are:

  1. Create web service data adapter that your subreport will use.
  2. Using the context menu, export the data adapter to a file in your workspace.
  3. In the properties of the report used as the subreport, set the default data adapter to the exported file.
  4. Pass the appropriate parameters from the master report to the subreport.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM