REST Web Service API: upload/update report templat

2019-04-10 18:31发布

问题:

I want to store and deploy report template with my code.

With this one in mind running a report is a two step process:

  • upload or update existing report template jrxml (it does not have links to other resources like images)
  • run it with my data (this one is done)

The official documentation doesn't contain a minimal example for updating report template

What is raw request which uploads/updates report template xml via JasperReports Server REST API?

I tried this way

here is my raw request

here is response

here what I see in /var/lib/tomcat6/webapps/jasperserver/WEB-INF/logs/jasperserver.log

What am I doing wrong? What does 400 error: could not find the binary content for resource: /Reports/product_structures_workshops mean?

回答1:

This works for Jasper 5.5+ (but does not for 5.1-, returns just 404 Not Found "Specified page not found" instead).

Uploading

POST http://your-host:port/jasperserver/rest_v2/resources/path/to/resource/

Content-Type: application.repository.reportUnit+json

{
    "label": "Sample",
    "jrxml": {
        "jrxmlFile": {
            "label": "MyJRXML",
            "type":"jrxml",
            // encode your file in Base64 and put here
            "content": "PD94bWwg..."
        }
    }
}

Updating

PUT http://your-host:port/jasperserver/rest_v2/resources/path/to/resource/myReport/

Content-Type: application.repository.reportUnit+json

{
    "label": "Sample",
    "jrxml": {
        "jrxmlFile": {
            "label": "MyJRXML",
            "type":"jrxml",
            // encode your file in Base64 and put here
            "content": "PD94bWwg..."
        }
    }
}

References:

  • https://community.jaspersoft.com/questions/822949/example-creating-report-resource-rest-v2
  • http://community.jaspersoft.com/sites/default/files/docs/jasperreports-server-web-services-guide.pdf


回答2:

We ended up with writing proprietary local JAVA application with jasper libraries, which does same thing

It looks like this is doable in older jasper versions (> 5.2):

they simplified significally REST API (look for API v2)

https://community.jaspersoft.com/wiki/getting-started-rest-web-service-api

With the completion of the v2 REST API, Jaspersoft announces the deprecation of the original REST API and the end-of-life of the SOAP services