Find file
Fetching contributors…
Cannot retrieve contributors at this time
135 lines (96 sloc) 4.53 KB


A client API for accessing jasper reports repository service.

The list, get, and runReport actions are supported.

JasperClient provides a mechanism to construct service requests using Xml::Builder. Client methods (list, get, run_report) yield to a block which is passed a builder to the guts of the SOAP request. This allows for an easy mechanism to create XML that is added to a request.

An example list request document:

<?xml version="1.0" encoding="utf-8"?>
    <axis:list soapenv:encodingStyle="">
      <requestXmlString xsi:type="xsd:string">
         <request operationName="list"> 
           <argument name="LIST_RESOURCES"/> 
           <argument name="RESOURCE_TYPE">reportUnit</argument> 
           <argument name="START_FROM_DIRECTORY">/Reports/xforty</argument> 

When a call to list is made, a builder is passed to the block provided. The above request could be executed using the list example below. In a nuttshell, the caller needs to construct the body/ children of the <request></request> element. Short work can be made of this by telling builder what to construct.

Example list request

The list request retrieves information about a folders contents on the jasper server. The jasper server organizes resources (reports, controls, queries files, etc) in a folder hierarchy similar to the way modern computers manage files.

A list request fetches the contents of a folder on the server.

A typical request might looks look like the following:

client =, user, pass)

response = client.list do |request|
  request.argument :name => "LIST_RESOURCES"
  request.argument 'reportUnit', :name => "RESOURCE_TYPE"
  request.argument '/Reports/xforty', :name => 'START_FROM_DIRECTORY'


For more information see JasperClient::RepositoryService::Response::ListResponse.

response.each do |entry|

Example get request

A get request retrieves full information about a resource on the server. This example fetches information about a report called user_list, though any resource type can be retuned with a get.

response = client.get do |req|
  req.resourceDescriptor :name => 'jrlogo', :wsType => 'report', :uriString => '/Reports/xforty/user_list', :isNew => 'false'

puts "Is successful: #{response.success?}"

For more information see JasperClient::RepositoryService::Response::GetResponse.

Example runReport request

The runReport request produces report output in the desired format.

response = client.run_report do |req|
  req.argument 'HTML', :name => 'RUN_OUTPUT_FORMAT'

  req.resourceDescriptor :name => 'JRLogo', 
    :wsType => 'img', 
    :uriString => '/reports/xforty/user_list', 
    :isNew => 'false'

puts "Is successful: #{response.success?}"

puts "Parts? #{}" do |part|
  puts "Part: #{part.suggested_filename}"

For more information see JasperClient::RepositoryService::Response::RunReportResponse.

The class of the request depends on the type of request. It will be of type ListResponse, GetResponse, or RunReportResponse.

Response types are specific to the request. Response types include ListResponse, GetResponse, RunReportResponse, etc. Non-report responses tend to be focused around the Resource class, which represnets <resourceDescriptor> xml response elements.


Reports are unique. A report response is a multipart related mime document. The parts include the XML SOAP response, the report content (which might be a PDF, a CSV, or an HTML file with accompanying images in their individual parts).


In the future helper methods for helping to hone in on various kinds of info from the server will be built. For example, you might want ot just find or list particular resource types like reports, queries, etc.

Additionaly, the ability to update resources could be provided, but we didn't have any use for this right now so we didn't focus on this.


Copyright © 2010 xforty technologies. See LICENSE for details.