When you use WebService as the data source for your project, you want the report to call this WebService data source directly instead of defining the database table for the data connection call, so how do you do that?
Access the WebService app service in your program, convert the data returned by WebService to the program dataset, and then call it in the designer.
Taking the webservice of axis1.4 as an example, it introduces the procedure of how to take the number and convert the data to the WebService program data set.
WebService Application Services
As in the Axis project under Tomcat, a WebService application service Testws2tdclient.jws is published in JWA mode, returning an array of data, as follows:
public class Testws2tdclient {
Public string[][] Gettd () {
String[][] A = {{"City", "Salesperson", "Sales"},{"Jiangsu", "Anna", "230"},{"Jiangsu", "Alex", "190"},{"Jiangsu", "Jack", "320"},{"Jiangsu", "Apple", "210 "},{" Zhejiang "," Faye "," 150 "},{" Zhejiang "," Sammi "," 280 "};
return A;
}
}
Publish WebService in JWs: Rename the written Testws2tdclient.java file Testws2tdclient.jws, and place it in Tomcat\webapps\axis.
Accessing the WebService data source in the Java class
Java publishes a SOAP request, accesses Testws2tdclient.java, obtains the returned data, the code is as follows:
try {String endpoint = "Http://localhost:8080/axis/TestWS2TDClient.jws"; Service service = new service (); Create a service invocation (call) calls Service.createcall (); Create a Call Object Call.settargetendpointaddress (new Java.net.URL (endpoint)) through the service; Set the service's Urlcall.setoperationname (new QName ("Http://localhost:8080/axis/TestWS2TDClient.jws", "GETTD")); Call the Gettd method in service string[][] ret = (string[][]) Call.invoke (new object[] {}); The Gettd method has no arguments, so it passes an empty object to get the data returned in the service GETTD return ret;} catch (Exception e) {e.printstacktrace ();}
Soap is a simple Object access protocol, a client sends a request, invokes the corresponding object, and the server returns the result. These messages are in XML format and are encapsulated as messages that conform to the HTTP protocol.
In the meantime, Axis.jar, Commons-discovery-0.2.jar, Commons-logging-1.0.4.jar, Wadl4j-a.5.a.jar, Log4j-1.2.8.jar, Jaxrpc.jar Six packs, can be found under Zxis\web-inf\lib.
Convert data to program data set
When webservice is accessed, the service returns data to the client, which returns an array of strings. Define the Webservicetabledata.java class, extend the Abstracttabledata, and convert the obtained array data to the program dataset. The complete code is as follows:
Package Com.fr.data;import Javax.xml.namespace.qname;import Org.apache.axis.client.call;import Org.apache.axis.client.service;import Com.fr.data.abstracttabledata;import Com.fr.general.data.tabledataexception;public class Webservicetabledata extends Abstracttabledata{private String[][ ] Data;public Webservicetabledata () {this.data = This.getdata ();} Gets the number of columns public int getcolumncount () throws tabledataexception {return data[0].length;} Gets the name of the column that is the value of the first row in the array public String getcolumnname (int columnindex) throws Tabledataexception {return data[0][columnindex];} Gets the number of rows for the length of the data -1public int GetRowCount () throws tabledataexception {return data.length-1;} Get the value public Object getvalueat (int rowIndex, int columnindex) {return data[rowindex + 1][columnindex];} Public string[][] GetData () {try {String endpoint = "Http://localhost:8080/axis/TestWS2TDClient.jws"; Service service = new service (); Call call = (call) Service.createcall (); Call.settargetendpointaddress (new Java.net.URL (endpoint)); Call.setoperationname (New QName ("Http://localhost:8080/axis/TestWS2TDClient.jws", "GETTD")); string[][] ret = (string[][]) Call.invoke (new object[] {}); return ret;} catch (Exception e) {e.printstacktrace ();} return new string[][] {};}}
Copy the compiled class file to the%fr_home%/webreport/web-inf/classes/com/fr/data folder.
Calling the program dataset in the designer
Create a new report, define a dataset, select a program dataset, select a defined program DataSet Webservicetabledata.class, the name of the custom dataset is DS1, launch the Tomcat server, click Preview, the effect is as follows:
Calling WebService data source schema in Finereport in a jws manner