jasperserver-client 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,3 @@
1
+ == 0.5.0 2008-09-25
2
+
3
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/Manifest.txt ADDED
@@ -0,0 +1,28 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ PostInstall.txt
5
+ README.txt
6
+ Rakefile
7
+ config/hoe.rb
8
+ config/requirements.rb
9
+ init.rb
10
+ lib/jasper_server/client.rb
11
+ lib/jasper_server/error.rb
12
+ lib/jasper_server/protocols/basic.rb
13
+ lib/jasper_server/protocols/soap.rb
14
+ lib/jasper_server/protocols/soap_monkeypatch.rb
15
+ lib/jasper_server/report_request.rb
16
+ lib/jasper_server/version.rb
17
+ lib/jasperserver-client.rb
18
+ script/console
19
+ script/destroy
20
+ script/generate
21
+ script/txt2html
22
+ setup.rb
23
+ tasks/deployment.rake
24
+ tasks/environment.rake
25
+ tasks/website.rake
26
+ test/test_helper.rb
27
+ test/test_jasperserver-client.rb
28
+
data/PostInstall.txt ADDED
@@ -0,0 +1,4 @@
1
+
2
+ For more information on jasperserver-client, see http://jasperserver-client.rubyforge.org
3
+
4
+
data/README.txt ADDED
@@ -0,0 +1,62 @@
1
+ = JasperServer-Client
2
+
3
+ * http://jasper-client.rubyforge.org
4
+ * http://github.com/gunark/jasperserver-client
5
+
6
+ == DESCRIPTION:
7
+
8
+ JasperServer-Client is -- you guessed it -- a Ruby-based client for JasperServer.
9
+ The library allows for requesting and fetching reports from a networked JasperServer over SOAP.
10
+
11
+ == USAGE:
12
+
13
+ Here we request a report to be generated in PDF format and then save the resulting data
14
+ to a local file:
15
+
16
+ # Create a new client instance for the JasperServer running at
17
+ # http://example.com/jasperserver
18
+ client = JasperServer::Client.new("http://example.com/jasperserver/services/repository",
19
+ "jasperadmin", "secret!")
20
+
21
+ # Create a request for a report. The first parameter is the full path of the
22
+ # report unit, the second is the desired output format, and the last is an
23
+ # optional hash of parameters to be fed into the report.
24
+ request = JasperServer::Request.new("/example/my-report", "PDF", {'fruit' => 'apple'})
25
+
26
+ # Send the report request to the server and return the output data.
27
+ pdf_data = client.request_report(request)
28
+
29
+ # Write the report data to a file (instead you could send the data to the user's
30
+ # browser if you're doing this in, for example, a Rails controller action).
31
+ File.open('/tmp/report.pdf', 'w') do |f|
32
+ f.puts(pdf_data)
33
+ end
34
+
35
+ == REQUIREMENTS:
36
+
37
+ * A Ruby interpreter.
38
+ * The *soap4r* gem, version 1.5.8 or greater. (This should be automatically
39
+ installed as a dependency; otherwise run <tt>gem install soap4r</tt>.)
40
+ * A running JasperServer instance. The client has been tested with versions 2.0 through
41
+ to 3.0 of JasperServer.
42
+
43
+ == INSTALL:
44
+
45
+ * Via RubyGems:
46
+ gem install jasperserver-client
47
+
48
+ == LICENSE:
49
+
50
+ JasperServer-Client is free software; you can redistribute it and/or modify
51
+ it under the terms of the GNU Lesser General Public License as published
52
+ by the Free Software Foundation; either version 3 of the License, or
53
+ (at your option) any later version.
54
+
55
+
56
+ JasperServer-Client is distributed in the hope that it will be useful,
57
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
58
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
59
+ GNU General Public License for more details.
60
+
61
+ You should have received a copy of the GNU Lesser General Public License
62
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb ADDED
@@ -0,0 +1,76 @@
1
+ require 'jasper_server/version'
2
+
3
+ AUTHOR = 'Matt Zukowski' # can also be an array of Authors
4
+ EMAIL = "matt@zukowski.ca"
5
+ DESCRIPTION = "Ruby-based client for JasperServer. Allows for requesting and fetching reports using Ruby from a networked JasperServer over SOAP."
6
+ GEM_NAME = 'jasperserver-client' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'jasper-client' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+ EXTRA_DEPENDENCIES = [
11
+ ['soap4r', '>= 1.5.8']
12
+ ]
13
+
14
+ @config_file = "~/.rubyforge/user-config.yml"
15
+ @config = nil
16
+ RUBYFORGE_USERNAME = "gunark"
17
+ def rubyforge_username
18
+ unless @config
19
+ begin
20
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
21
+ rescue
22
+ puts <<-EOS
23
+ ERROR: No rubyforge config file found: #{@config_file}
24
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
25
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
26
+ EOS
27
+ exit
28
+ end
29
+ end
30
+ RUBYFORGE_USERNAME.replace @config["username"]
31
+ end
32
+
33
+
34
+ ENV['NODOT'] = '1'
35
+
36
+
37
+ REV = nil
38
+ # UNCOMMENT IF REQUIRED:
39
+ # REV = YAML.load(`svn info`)['Revision']
40
+ VERS = JasperServer::VERSION::STRING + (REV ? ".#{REV}" : "")
41
+ RDOC_OPTS = ['--quiet', '--title', 'JasperServer-Client documentation',
42
+ "--opname", "index.html",
43
+ "--line-numbers",
44
+ "--main", "README.txt",
45
+ "--inline-source"]
46
+
47
+ class Hoe
48
+ def extra_deps
49
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
50
+ @extra_deps
51
+ end
52
+ end
53
+
54
+ # Generate all the Rake tasks
55
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
56
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
57
+ p.developer(AUTHOR, EMAIL)
58
+ p.description = DESCRIPTION
59
+ p.summary = DESCRIPTION
60
+ p.url = HOMEPATH
61
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
62
+ p.test_globs = ["test/**/test_*.rb"]
63
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
64
+
65
+ # == Optional
66
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
67
+ #p.extra_deps = EXTRA_DEPENDENCIES
68
+
69
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
70
+ end
71
+
72
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
73
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}"
74
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
75
+ $hoe.rsync_args = '-av --delete --ignore-errors'
76
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
data/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ # This file makes it possible to install JasperServer-Client as a Rails plugin.
2
+
3
+ $: << File.expand_path(File.dirname(__FILE__))+'/lib'
4
+
5
+ require 'jasperserver-client'
@@ -0,0 +1,52 @@
1
+ require 'jasper_server/protocols/soap'
2
+
3
+ module JasperServer
4
+
5
+ # The client through which all report requests are sent to the JasperServer.
6
+ class Client
7
+
8
+ # Create a new instance of the client.
9
+ #
10
+ # url :: The URL of the JasperServer. This should look something like:
11
+ # "http://<hostname>:<port>/jasperserver/services/repository"
12
+ # username :: The username used to connect to the JasperServer.
13
+ # password :: The password used to connect to the JasperServer.
14
+ def initialize(url, username, password)
15
+ unless url =~ /\/services\/repository\/?$/
16
+ # add the /services/repository suffix to the URL if the user forgot
17
+ # to include it
18
+ url << "/services/repository"
19
+
20
+ puts "WARNING: You may have forgotten to add the '/services/repository' "+
21
+ "to your JasperServer URL. Your URL has been automatically changed to #{url.inspect}."
22
+ end
23
+
24
+ @jasper_url = url
25
+ @jasper_username = username
26
+ @jasper_password = password
27
+ end
28
+
29
+ # Request a report from the server based on the ReportRequest object you provide.
30
+ # Returns the report data.
31
+ #
32
+ # For example if your request specifies <tt>PDF</tt> as the output format, PDF
33
+ # binary data will be returned.
34
+ #
35
+ # client = JasperServer::Client.new("http://example.com/jasperserver/services/repository",
36
+ # "jasperadmin", "secret!")
37
+ # request = JasperServer::Request.new("/example/my-report", "PDF", {'fruit' => 'apple'})
38
+ # pdf_data = client.request_report(request)
39
+ # File.open('/tmp/report.pdf', 'w') do |f|
40
+ # f.puts(pdf_data)
41
+ # end
42
+ #
43
+ # For debugging purposes, try requesting output in <tt>CSV</tt> format, since
44
+ # request_report will then return an easily readable String.
45
+ def request_report(request)
46
+ soap = JasperServer::Protocols::SOAP.new
47
+ soap.connect(@jasper_url, @jasper_username, @jasper_password)
48
+ soap.request_report_via_soap(request)
49
+ end
50
+
51
+ end
52
+ end
@@ -0,0 +1,4 @@
1
+ module JasperServer
2
+ class Error < Exception
3
+ end
4
+ end
@@ -0,0 +1,97 @@
1
+ require 'jasper_server/error'
2
+
3
+ module JasperServer
4
+ module Protocols
5
+
6
+ # <b>THIS PROTOCOL ADAPTER DOES NOT YET WORK!!!</b>
7
+ #
8
+ # This was an attempt at fetching reports using scraping... unfortunately
9
+ # I can't figure out how to fake the Spring authentication session :(
10
+ class Basic
11
+ # EXAMPLE URL FOR FETCHING REPORT
12
+ # http://jas01:8080/jasperserver/flow.html?_flowId=viewReportFlow&reportUnit=/u-track/project-totals-for-orgunit&standAlone=true&ParentFolderUri=/u-track&orgunit-id=2&start-date=20080801040000&end-date=20080831040000&output=swf&decorate=no
13
+
14
+ def request_report_via_url(request)
15
+ report_unit = request.report_unit
16
+ output_format = request.output_format
17
+ report_params = request.report_params
18
+
19
+ params = {}
20
+ report_params.each do |name, value|
21
+ if value.kind_of? Time
22
+ params[name] = ReportRequest.convert_time_to_jasper_timestamp(value)
23
+ else
24
+ params[name] = value
25
+ end
26
+ end
27
+
28
+ params['_flowId'] = 'viewReportFlow'
29
+ params['standAlone'] = 'true'
30
+ #params['parentFolderUri'] = '/u-track'
31
+ params['decorate'] = 'no'
32
+
33
+ params['reportUnit'] = report_unit
34
+ params['output'] = output_format
35
+
36
+ puts "FETCHING LOGIN PAGE"
37
+ uri = URI.parse("http://jas01:8080/jasperserver/login.html")
38
+ res = Net::HTTP.start(uri.host, uri.port) do |http|
39
+ http.get(uri.path)
40
+ end
41
+ res['set-cookie'] =~ /JSESSIONID=([a-z0-9]*);/i
42
+ jsessionid = $~[1]
43
+ puts "SESSION ID IS #{jsessionid}"
44
+
45
+ sleep 1
46
+
47
+ uri = URI.parse("http://jas01:8080/jasperserver/j_acegi_security_check")
48
+
49
+ # FIXME: logging in doesn't work :(
50
+
51
+ puts "LOGGING IN"
52
+ req = Net::HTTP::Post.new(uri.path)
53
+ req.set_form_data({'j_username' => 'jasperadmin', 'j_password' => 'jasper!', 'btnsubmit' => 'Login', 'jsessionid' => jsessionid})
54
+
55
+ client = Net::HTTP.new(uri.host, uri.port)
56
+ result = client.start do |http|
57
+ puts "LOGIN REQ"
58
+ puts req.to_hash.inspect
59
+ http.request(req)
60
+ end
61
+ #res = Net::HTTP.post_form(uri, {'j_username' => 'jasperadmin', 'j_password' => 'jasper!', 'btnsubmit' => 'Login'})
62
+ puts "LOGIN RESP HEADERS"
63
+ puts res.to_hash.inspect
64
+ puts res.inspect
65
+
66
+
67
+
68
+ uri = URI.parse("http://jas01:8080/jasperserver/flow.html")
69
+ #
70
+ #req = Net::HTTP::Post.new(uri.path)
71
+ #req.set_form_data(params, '&')
72
+
73
+ sleep 1
74
+
75
+ # FIXME: this should fetch the report, but instead we get redirected to the login page
76
+ # since I can't seem to get the fake login to work :(
77
+
78
+ params['jsessionid'] =
79
+ q = params.collect{|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"}.join("&")
80
+ uri.query = q
81
+ req = Net::HTTP::Get.new(uri.request_uri)
82
+ puts uri.request_uri
83
+
84
+ client = Net::HTTP.new(uri.host, uri.port)
85
+ result = client.start do |http|
86
+ puts req.to_hash.inspect
87
+ http.request(req)
88
+ end
89
+
90
+ return result
91
+ end
92
+
93
+ class Error < JasperServer::Error
94
+ end
95
+ end
96
+ end
97
+ end