jasperserver-client 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,14 @@
1
- == 0.5.0 2008-09-25
1
+ == 1.0.0 2010-04-27
2
+
3
+ * Should now work when Nokogiri is being used as the ActiveSupport MiniXml backend.
4
+ * Releasing as 1.0. It appears that we are mostly bug-free.
5
+
6
+ == 0.2.0 2009-08-14
7
+
8
+ * Should now work with Rails 2.3
9
+ * Can now specify the maximum time the client will wait for a response from the Jasper Server
10
+
11
+
12
+ == 0.1.0 2008-09-25
2
13
 
3
14
  * Initial release
File without changes
@@ -11,7 +11,8 @@ module JasperServer
11
11
  # "http://<hostname>:<port>/jasperserver/services/repository"
12
12
  # username :: The username used to connect to the JasperServer.
13
13
  # password :: The password used to connect to the JasperServer.
14
- def initialize(url, username, password)
14
+ # timeout :: Maximum time to wait for a response from the JasperServer (default it 60 seconds).
15
+ def initialize(url, username, password, timeout = 60)
15
16
  unless url =~ /\/services\/repository\/?$/
16
17
  # add the /services/repository suffix to the URL if the user forgot
17
18
  # to include it
@@ -24,6 +25,7 @@ module JasperServer
24
25
  @jasper_url = url
25
26
  @jasper_username = username
26
27
  @jasper_password = password
28
+ @timeout = timeout
27
29
  end
28
30
 
29
31
  # Request a report from the server based on the ReportRequest object you provide.
@@ -44,9 +46,10 @@ module JasperServer
44
46
  # request_report will then return an easily readable String.
45
47
  def request_report(request)
46
48
  soap = JasperServer::Protocols::SOAP.new
47
- soap.connect(@jasper_url, @jasper_username, @jasper_password)
49
+ soap.connect(@jasper_url, @jasper_username, @jasper_password, @timeout)
48
50
  soap.request_report_via_soap(request)
49
51
  end
50
52
 
51
53
  end
52
54
  end
55
+
@@ -1,34 +1,60 @@
1
1
  require 'jasper_server/protocols/soap_monkeypatch'
2
2
  require 'jasper_server/error'
3
3
 
4
+ gem 'xml-simple'
5
+ require 'xmlsimple'
6
+
7
+ if Object.const_defined?(:XmlSimple) && !XmlSimple.respond_to?(:xml_in_string)
8
+ class XmlSimple
9
+ # Same as xml_in but doesn't try to smartly shoot itself in the foot.
10
+ def xml_in_string(string, options = nil)
11
+ handle_options('in', options)
12
+
13
+ @doc = parse(string)
14
+ result = collapse(@doc.root)
15
+
16
+ if @options['keeproot']
17
+ merge({}, @doc.root.name, result)
18
+ else
19
+ result
20
+ end
21
+ end
22
+
23
+ def self.xml_in_string(string, options = nil)
24
+ new.xml_in_string(string, options)
25
+ end
26
+ end
27
+ end
28
+
4
29
  module JasperServer
5
30
  module Protocols
6
31
  class SOAP
7
32
  JASPER_URN = "urn:"
8
-
33
+
9
34
  def request_report_via_soap(request)
10
35
  raise Error, "Must connect to JasperServer first!" if @driver.nil?
11
-
36
+
12
37
  report = request.report_unit
13
38
  format = request.output_format
14
39
  params = request.report_params
15
-
40
+
16
41
  params_xml = ""
17
42
  params.each do |name, value|
18
- if value.kind_of? Array
43
+ case value
44
+ when Array
19
45
  value.each do |item|
20
- params_xml << %{<parameter name="#{name}" isListItem="true">#{@@html_encoder.encode(item, :decimal)}</parameter>\n}
46
+ params_xml << %{<parameter name="#{name}" isListItem="true"><![CDATA[#{item}]]></parameter>\n}
21
47
  end
22
- elsif value.kind_of? Time
48
+ when Time, DateTime, Date
23
49
  ts = ReportRequest.convert_time_to_jasper_timestamp(value)
24
50
  params_xml << %{<parameter name="#{name}">#{ts}</parameter>\n}
25
- elsif value.kind_of? Integer
26
- params_xml << %{<parameter name="#{name}">#{value}</parameter>\n}
27
- elsif !value.blank?
51
+ else
52
+ unless value.blank?
28
53
  params_xml << %{<parameter name="#{name}"><![CDATA[#{value}]]></parameter>\n}
29
54
  end
30
55
  end
31
-
56
+ end
57
+
32
58
  request = %Q|<request operationName="runReport" locale="en">
33
59
  <argument name="RUN_OUTPUT_FORMAT">#{format}</argument>
34
60
  <resourceDescriptor name="" wsType=""
@@ -38,33 +64,55 @@ module JasperServer
38
64
  #{params_xml}
39
65
  </resourceDescriptor>
40
66
  </request>|
41
-
42
- RAILS_DEFAULT_LOGGER.debug "JasperSoapClient Request:\n#{request}"
43
-
67
+
68
+ RAILS_DEFAULT_LOGGER.debug "#{self.class.name} Request:\n#{request}" if Object.const_defined?('RAILS_DEFAULT_LOGGER')
69
+
44
70
  result = @driver.runReport(request)
45
-
46
- RAILS_DEFAULT_LOGGER.debug "JasperSoapClient Response:\n#{result}"
47
-
48
- xml = XmlSimple.xml_in_string(result)
71
+
72
+ RAILS_DEFAULT_LOGGER.debug "#{self.class.name} Response:\n#{result}" if Object.const_defined?('RAILS_DEFAULT_LOGGER')
73
+
74
+ if Object.const_defined?(:ActiveSupport) && ActiveSupport.const_defined?(:XmlMini)
75
+ # for Rails 2.3+
76
+ xml = ActiveSupport::XmlMini.parse(result)
77
+ xml = xml['operationResult']
78
+
79
+ begin
80
+ content_key = ActiveSupport::XmlMini.backend::CONTENT_KEY
81
+ rescue NameError
82
+ # Nokogiri doesn't define a CONTENT_KEY const -- the content key is always just '__content__'
83
+ content_key = '__content__'
84
+ end
85
+
86
+ xml.each do |k,v|
87
+ if v.kind_of?(Hash) && v[content_key]
88
+ xml[k] = [v[content_key]]
89
+ end
90
+ end
91
+ else
92
+ xml = XmlSimple.xml_in_string(result)
93
+ end
94
+
49
95
  unless xml['returnCode'].first.to_i == 0
50
96
  raise JasperServer::Error, "JasperServer replied with an error: #{xml['returnMessage'] ? xml['returnMessage'].first : xml.inspect}"
51
97
  end
52
-
98
+
53
99
  result.instance_variable_get(:@env).external_content['report'].data.content
54
100
  end
55
-
56
- def connect(url, username, password)
57
- @driver = connect_to_soap_service(url, username, password)
101
+
102
+ def connect(url, username, password, timeout = 60)
103
+ @driver = connect_to_soap_service(url, username, password, timeout)
58
104
  end
59
-
105
+
60
106
  protected
61
- def connect_to_soap_service(url, username, password)
107
+ def connect_to_soap_service(url, username, password, timeout = 60)
62
108
  driver = ::SOAP::RPC::Driver.new(url, JASPER_URN)
63
109
  driver.options['protocol.http.basic_auth'] << [url, username, password]
64
-
110
+ driver.options['receive_timeout'] = timeout
111
+
112
+
65
113
  driver.add_method('runReport', 'requestXmlString')
66
114
  return driver
67
115
  end
68
116
  end
69
117
  end
70
- end
118
+ end
@@ -18,14 +18,17 @@ module JasperServer
18
18
  # are automatically adjusted for timezone).
19
19
  # E.g. <tt>{ 'fruit' => "Apple", 'date' => Time.now}</tt>
20
20
  def initialize(report_unit, output_format, report_params = {})
21
+ raise ArgumentError, "Missing output_format in report request!" if output_format.nil? || output_format.empty?
21
22
  @report_unit = report_unit
22
23
  @output_format = output_format.upcase
23
24
  @report_params = report_params
24
25
  end
25
26
 
26
- # Converts the given Time into a timestamp integer acceptable by JasperServer.
27
+ # Converts the given Time/DateTime/Date into a timestamp integer acceptable by JasperServer.
27
28
  # The timezone adjustment is performed (converted to UTC).
28
29
  def self.convert_time_to_jasper_timestamp(time)
30
+ time = Time.parse(time.to_s) unless time.kind_of?(Time)
31
+
29
32
  # convert to milisecond timestamp
30
33
  ts = time.to_i * 1000
31
34
  # adjust for timezone
@@ -34,4 +37,4 @@ module JasperServer
34
37
  end
35
38
 
36
39
  end
37
- end
40
+ end
@@ -1 +1,3 @@
1
- require 'jasper_server/client'
1
+ require 'jasper_server/client'
2
+ require 'jasper_server/report_request'
3
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jasperserver-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zukowski
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-25 00:00:00 -04:00
12
+ date: 2010-04-27 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -33,14 +33,12 @@ extra_rdoc_files:
33
33
  - History.txt
34
34
  - License.txt
35
35
  - Manifest.txt
36
- - PostInstall.txt
37
- - README.txt
36
+ - README.rdoc
38
37
  files:
39
38
  - History.txt
40
39
  - License.txt
41
40
  - Manifest.txt
42
- - PostInstall.txt
43
- - README.txt
41
+ - README.rdoc
44
42
  - Rakefile
45
43
  - config/hoe.rb
46
44
  - config/requirements.rb
@@ -65,14 +63,12 @@ files:
65
63
  - test/test_jasperserver-client.rb
66
64
  has_rdoc: true
67
65
  homepage: http://jasper-client.rubyforge.org
68
- post_install_message: |+
69
-
70
- For more information on jasperserver-client, see http://jasperserver-client.rubyforge.org
71
-
72
-
66
+ licenses: []
67
+
68
+ post_install_message:
73
69
  rdoc_options:
74
70
  - --main
75
- - README.txt
71
+ - README.rdoc
76
72
  require_paths:
77
73
  - lib
78
74
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -90,10 +86,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
86
  requirements: []
91
87
 
92
88
  rubyforge_project: jasper-client
93
- rubygems_version: 1.2.0
89
+ rubygems_version: 1.3.5
94
90
  signing_key:
95
91
  specification_version: 2
96
- summary: Ruby-based client for JasperServer. Allows for requesting and fetching reports using Ruby from a networked JasperServer over SOAP.
92
+ summary: Ruby-based client for JasperServer.
97
93
  test_files:
98
94
  - test/test_jasperserver-client.rb
99
95
  - test/test_helper.rb
@@ -1,4 +0,0 @@
1
-
2
- For more information on jasperserver-client, see http://jasperserver-client.rubyforge.org
3
-
4
-