JasperReports Server Web Services example
I don’t have a lot of experience working with web services and JasperReports Server. I have good knowledge of what they’re capable of achieving, and I know all about the what’s and wherefore’s of SOAP vs REST, but I don’t have a lot of hands-on knowledge from working with them.
And that’s exactly the reason I was so pleased to see this sample earlier today. It came from Java-guru and Jaspersoft-guru Lucian Chiriţă. The customer question which motivated it was someone having difficulties updating an existing user via a POST request. The elegance of the example is that it’s a single command runnable on nearly any system, and it uses a trivially short XML file to hold the sample information.
I hope that this sample makes its way into core JasperReports Server documentation someday soon. But until then, here’s a sample request in case it’s useful for more folks than just this one JasperReports Server customer. First create an XML with this content:
<user> <enabled>true</enabled> <externallyDefined>false</externallyDefined> <fullName>Updated Joe User</fullName> <password>secret</password> <roles> <externallyDefined>false</externallyDefined> <roleName>ROLE_USER</roleName> </roles> <roles> <externallyDefined>false</externallyDefined> <roleName>ROLE_DEMO</roleName> </roles> <tenantId>organization_1</tenantId> <username>joeuser</username> </user>
I saved the file as user.data.xml. Then update the sample user “joeuser” using this command:
curl -X POST -u jasperadmin:jasperadmin -H "Content-Type: application/xml" --data-binary @/tmp/user.data.xml "http://localhost:8080/jasperserver-pro/rest/user/joeuser|organization_1"
Joeuser will find that he has a new password and a new fullname the next time he logs in. Starting from a simple example that immediately works, it should be relatively straightforward to develop a real application which uses the JasperReports Server web services REST API.