Get report from jasperserver using REST webservice and asp.net C#

前端 未结 2 1893
孤街浪徒
孤街浪徒 2020-12-14 12:21

You can use the jasperservers webservices (SOAP and REST is available) to get mange and run reports on from a web application. The SOAP wsdl is not compatible with asp.net c

2条回答
  •  没有蜡笔的小新
    2020-12-14 13:11

    Dude thanks very much this was the single most helpful post I've found on getting reports out of JasperServer via REST, and I'm using Ruby on Rails. After upgrading to JS 5.0 i found the SOAP interface very unreliable, basically you had to hit it twice for the report to generate. I had zero success with the rest_v2 interface, it never seemed to honor any parameters passed to it.

    So I tried out the older REST interface and its working fine. For any Rails guys, here's my (slightly messy) console code.

    report = 'TempSpeedLimit'
    params = {:tsl_id => 744}
    request_body = ""
    params.each{|k,v| request_body += "#{v}"}
    request_body += ""
    body_put = ''
    body_get = ''
    cookie_put = ''
    
    uri_put = URI.parse("http://:8080/jasperserver/rest/report/reports/hawk/#{report}")
    http_put = Net::HTTP.new(uri_put.host, uri_put.port)
    http_put.start do |http|
    req = Net::HTTP::Put.new(uri_put.path + "?RUN_OUTPUT_FORMAT=PDF")
    req.basic_auth('jasperadmin', 'secretpassword')
    req.body = request_body
    resp = http.request(req)
    body_put = resp.body
    cookie_put = resp['Set-Cookie']
    end
    
    xml = REXML::Document.new(body_put)
    uuid = xml.elements["report/uuid"].text
    
    uri_get = URI.parse("http://:8080/jasperserver/rest/report/#{uuid}")
    http_get = Net::HTTP.new(uri_get.host, uri_get.port)
    http_get.start do |http|
    req = Net::HTTP::Get.new(uri_get.path + "?file=report")
    req.basic_auth('jasperadmin', 'secretpassword')
    req['cookie'] = cookie_put
    resp = http.request(req)
    body_get = resp.body
    end
    
    f = File.new('test.pdf', 'wb')
    f.write(body_get)
    f.close
    

提交回复
热议问题