BIRT Web Services Data Source

458 views
Skip to first unread message

Paul Bappoo

unread,
Sep 3, 2010, 4:51:52 AM9/3/10
to Paul Bappoo
The full version of this report, including screen shots and source
code, in full colour pdf is available for free download at
http://www.BIRTReporting.com

One of the most frequent questions I have been asked through my work
with the BIRT User Group UK and BIRTReporting.com is “how can you use
web services as data sources within BIRT”.
This seems to stem from the fact that one of the data source options
within the BIRT designer is the Web Service data source, but there
seems to be little information out there on the net to really walk
people through how to create an actual example.
This project, which you can follow step by step, aims to correct that.
In this example we are going to create a report which reads a list of
email addresses from a source database. So this might be your customer
or prospects database and you may be using a report like this to
periodically “clean” the list of invalid email addresses.
For each email address that we read we want to use an online web
service to check that the email address is valid and return a
graphical result. The web service we are going to use actually returns
a textual result, so whilst this would have been good enough, I wanted
to go one step further and include the additional principle of dynamic
images just to add a little spice to the mix!

THE BASIC REPORT

If you have been following my previous guides you will already know
how to create a basic listing report. If you don’t then this guide is
probably not the best place to start!
The underlying table I am using for this is a SQL Server Express 2008
R2 hosted table which contains just 2 columns, a name and an email
address. I created the table manually and populated it with some real
email addresses and some made up ones.

Note that I have based many previous guides on full SQL server or
Oracle, but recently readers mentioned to me that they didn’t have
full copies of either and asked if I had some examples that work over
MySQL. Well in short I don’t, but the express versions of SQL server
are available for free download from Microsoft, so if you want to
follow these guides to the letter then go get one of those. If not you
could always adapt and have a go at doing this over any database of
your choice.

Here is a screenshot of the finished report, but we will get on to the
good stuff in a moment. For now just create the basic report that
lists the names and email addresses from the database.
Naturally you can use grids and headings as you see fit to make the
report look nice.

ADDING A WEB SERVICE DATA SOURCE

OK now for the good bit. We are going to add a publically available
web service as a data source to our report.
Do the usual and right click on data sources, selecting New Data
Source and this time look for the Web Services Data Source option –
click it, name it and click Next.

Next use the following two entries in the WSDL URL or Location field
and the SOAP End Point field.
http://www.webservicex.net/ValidateEmail.asmx?wsdl
http://www.webservicex.net/ValidateEmail.asmx
If you don’t know what these terms mean then take a look at the
following article on Wikipedia which provides a good introduction to
web services.
http://en.wikipedia.org/wiki/Web_Services_Description_Language
http://en.wikipedia.org/wiki/SOAP

ADDING A WEB SERVICE DATA SET

Now create another data set in the usual manner. Select the Web
services data source as the data source and give your data sent an
appropriate name.

On the next screen expand the options till you find the IsValidEmail
method, under the ValidateEmailSoap section.

Each web service (where appropriate) will come supplied with
parameters. In this case there is only a single parameter, the email
address, which needs to be supplied so that the web service can go and
validate it. It will be selected by default in the next screen.

In the next screen you get to edit the SOAP request. This is the XML
payload that will be sent to the web service and if you look really
carefully you can see that it contains the “Email” parameter. I’ve
highlighted it in the image below...

If you want to edit this parameter you can do so by clicking on the
Edit Parameter button. For now, hit that button and you will see the
following screen:

Highlight the parameter line and click Edit. Now enter your email
address as a test example. We will remove this later as we want the
parameter to be provided dynamically for each line of the report, but
for now we just want to test if we can get this thing working!

OK your way back to the main wizard screen and click next. The
following screen will be displayed. You don’t need to make any changes
to the default settings.

Next we need to tell BIRT how to interpret the data that comes back
from the web service. In our example it’s pretty straightforward as
the service only returns a single field saying True or False. But some
web service can return full data sets involving rows and columns, so
this is where we define what the returned XML will contain.

If you expand the tree on the left, you will eventually come across an
element called IsValidEmailResult. Highlight it and click on the
little right pointing arrow in the middle.
Press OK on the next screen that appears:

And notice how your selection has been returned as a long string of
characters. This is called an XPath and tells BIRT how to find the
selected element in the XML response file.
/SOAP-ENV:Envelope/SOAP-ENV:Body/IsValidEmailResponse/
IsValidEmailResult

Click Next to see the following screen where we define which elements
of the XML make up the columns of our data set. As mentioned
previously we only have one column, so again select the
IsValidEmailResult element. Nudge it across to the right using the
arrow and as before accept the defaults that pop up.

Click the Show Sample Data button and if you have got everything right
so far, the default email address that you entered earlier will be
passed to the web service and the response will be displayed in a
table like this:

Now click finish to get everything saved and you will see the data set
edit screen:

Now we know the data set is working well, we can go and remove the
parameter value. Click on Parameters, highlight the single entry that
appears and click Edit. DON’T click Remove because all we want to do
here is remove the default parameter value, not the parameter itself!

Delete the default value that you provided earlier

ADDING THE WEB SERVICE RESULT TO THE REPORT

In your standard listing report, add a column and within the detail
row it add a table. Make this table just 2 columns by 1 row and
associate it with the email validator data set. So now you should have
a report, with a master table which pulls its data from your database
of name and email addresses and a sub table in the last column which
pulls its data from the email validation web service.
Drag the IsEmailValidResult node from the data set to the first column
of your sub-table.

Click on the Data Set Parameter Binding button in the lower portion of
the screen. Highlight the row that exists, click edit and launch the
Java function editor using the fx button.

Navigate your way through Available Column Bindings, Table and finally
Email.

The eagle eyed amongst you will have noticed that these values are
being provided by the master table and not the sub-table, thus
applying a value (the email address) as a parameter to the sub-table
result set.
When you preview your report you will see that you get a true or false
value generated dynamically by the web service, for each entry in your
database.

ADDING THE DYNAMIC GRAPHIC

What we need to do now is add a splash of colour to our report to make
it more visually appealing to our users. We will achieve this by
adding a red cross or a green tick in place of the true/false text,
depending on the value. Start by getting hold of a couple of small
graphics files that you will use for your tick and cross. Some
suitable files are supplied with this guide, copy these into the
report source directory.
Drop an image field into the report layout in place of the true/false
text field and select the option Image File in shared resources.

Launch the Java function editor and coy in the following code:
if (row["IsValidEmailResult"]== "true") {
"tick.jpg"
} else {
"cross.jpg"

Now when you run your report you should see the ticks and crosses
appropriately.

The full version of this report, including screen shots and source
code, in full colour pdf is available for free download at
http://www.BIRTReporting.com

ABOUT THE AUTHOR

Paul Bappoo is the author of BIRT for Beginners (which is available in
paperback from BIRTReporting.com, Amazon and Barnes and Noble) and has
been an international technical software consultant and involved with
computers for over 30 years. Paul has an interest in BIRT reporting,
enterprise application integration, automated software testing,
computer based training and enterprise system implementation. Paul
runs the BIRT User Group UK and is a member of the BIRT-Exchange
Advisory Council. He would be delighted to hear from you with your
tips, tricks and stories about your usage of BIRT. If you have a
question, a need for training or consulting or great tip to share with
the community then drop him a line.

Tashi Wangchuk

unread,
Mar 26, 2018, 9:54:44 PM3/26/18
to Paul Bappoo
Helpful article.

However, for me, I am given just the endpoint(eg. http://10.0.0.31:8001/api/countries/). When I put http://10.0.0.31:8001/api/countries?wsdl in the wsdl url it can't connect.
Because we don't have the person who developed the webservice anymore, I was wondering whether we can create the datasource just from the endpoint instead of using wsdl.

Thank you
Reply all
Reply to author
Forward
0 new messages