Class: JasperServer::Protocols::SOAP

Inherits:
Object
  • Object
show all
Defined in:
lib/jasper_server/protocols/soap.rb

Constant Summary collapse

JASPER_URN =
"urn:"

Instance Method Summary collapse

Instance Method Details

#connect(url, username, password, timeout = 60) ⇒ Object



91
92
93
# File 'lib/jasper_server/protocols/soap.rb', line 91

def connect(url, username, password, timeout = 60)
  @driver = connect_to_soap_service(url, username, password, timeout)
end

#request_report_via_soap(request) ⇒ Object

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/jasper_server/protocols/soap.rb', line 34

def request_report_via_soap(request)
  raise Error, "Must connect to JasperServer first!" if @driver.nil?
  
  report = request.report_unit
  format = request.output_format
  params = request.report_params
  
  params_xml = ""
  params.each do |name, value|
    if value.kind_of? Array
      value.each do |item|
        params_xml << %{<parameter name="#{name}" isListItem="true">#{@@html_encoder.encode(item, :decimal)}</parameter>\n}
      end
    elsif value.kind_of? Time
      ts = ReportRequest.convert_time_to_jasper_timestamp(value)
      params_xml << %{<parameter name="#{name}">#{ts}</parameter>\n}
    elsif !value.blank?
      params_xml << %{<parameter name="#{name}"><![CDATA[#{value}]]></parameter>\n}
    end
  end
  
  request = %Q|<request operationName="runReport" locale="en">
    <argument name="RUN_OUTPUT_FORMAT">#{format}</argument>
    <resourceDescriptor name="" wsType=""
        uriString="#{report}"
        isNew="false">
      <label>null</label>
      #{params_xml}
    </resourceDescriptor>
  </request>|
  
  RAILS_DEFAULT_LOGGER.debug "#{self.class.name} Request:\n#{request}" if Object.const_defined?('RAILS_DEFAULT_LOGGER')
    
  result = @driver.runReport(request)
  
  RAILS_DEFAULT_LOGGER.debug "#{self.class.name} Response:\n#{result}" if Object.const_defined?('RAILS_DEFAULT_LOGGER')

  if Object.const_defined?(:ActiveSupport) && ActiveSupport.const_defined?(:XmlMini)
    # for Rails 2.3+
    xml = ActiveSupport::XmlMini.parse(result)
    xml = xml['operationResult']
    xml.each do |k,v|
      if v.kind_of?(Hash) && v[ActiveSupport::XmlMini.backend::CONTENT_KEY]
        xml[k] = [v[ActiveSupport::XmlMini.backend::CONTENT_KEY]]
      end
    end
  else
    xml = XmlSimple.xml_in_string(result)
  end

  unless xml['returnCode'].first.to_i == 0
    raise JasperServer::Error, "JasperServer replied with an error: #{xml['returnMessage'] ? xml['returnMessage'].first : xml.inspect}"
  end
  
  result.instance_variable_get(:@env).external_content['report'].data.content
end