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

前端 未结 2 1889
孤街浪徒
孤街浪徒 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

    I'll answer my own question:

    The PUT returns a Cookie in the response header, that you have to use in the subsequent GET:

    // Send PUT 
    string requestAllResult = httpclient.UploadString("http://website/jasperserver/rest/report/Declaraties/12change/Klant/budget_overzicht_per_klant?RUN_OUTPUT_FORMAT=PDF", "PUT", requestXml);
    
    // Get session cookie
    string session = httpclient.ResponseHeaders.Get("Set-Cookie");
    // Set session cookie
    httpclient.Headers.Add("Cookie", session);
    
    // Get report
    report=httpclient.DownloadString("http://website/jasperserver/rest/report/f521fe7d-7432-4c47-962c-9fec29bdaa43?file=report");
    

    And that's it!

    0 讨论(0)
  • 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 = "<resourceDescriptor name='#{report}' wsType='reportUnit' uriString='/reports/hawk/#{report}' isNew='false'><label>null</label>"
    params.each{|k,v| request_body += "<parameter name='#{k}'>#{v}</parameter>"}
    request_body += "</resourceDescriptor>"
    body_put = ''
    body_get = ''
    cookie_put = ''
    
    uri_put = URI.parse("http://<yourhost>: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://<yourhost>: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
    
    0 讨论(0)
提交回复
热议问题