Right Outer Join

3 September 2012

Web services POST example

Filed under: JasperReports Server, JasperServer — Tags: , — mdahlman @ 13:49

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.

About these ads

2 Comments »

  1. Brilliantly simple Matt, thank you!

    Comment by Ernesto — 13 September 2012 @ 03:26

    • Thanks. And I agree. But…

      • Credit for understanding the problem should go to Lucian.
      • Credit for thinking up a good sample should go to Lucian.
      • Credit for creating a working smaple should go to Lucian.
      • Credit for writing an introductory paragraph and re-posting the sample… that’s all me!

      Comment by mdahlman — 13 September 2012 @ 08:53


RSS feed for comments on this post. TrackBack URI

Go on... leave a reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Silver is the New Black Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 36 other followers

%d bloggers like this: