Creating a Resource

The PUT method on the resource service is used to create a new resource. If the resource has one or more file resources, they must be provided using a multipart request.

Method

URL

PUT

http://<host>:<port>/jasperserver[-pro]/rest/resource/path/to/resource/

Argument

Type/Value

Description

Resource
Descriptor

String

This parameter identifies the part with an XML resource descriptor in a multipart request. This is a required argument when using multipart requests.

Content-Type

Content

multipart/form-data

text/plain (in the first part)

application/octet-stream (for files)

A well-formed XML resourceDescriptor that fully describes the resource, including any locally defined resources. File resources are uploaded in separate parts.

Return Value on Success

Typical Return Values on Failure

201 Created – The body is XML containing the resourceDescriptor of the resource just created.

An error if the resource cannot be created for some reason. If you have very large files, see section Setting the Temporary Upload Directory.

In the following sample request, the URI is the location where we want to create the resource, in this case / (the root), and the content includes the resource descriptor for a new folder called myfolder.

PUT /jasperserver/rest/resource/ HTTP/1.1
Content-Length: 473
Content-Type: multipart/form-data; boundary=1afdzzMUQLfSOmu0Pgb2F-nmEnTwWuPf3
Host: localhost:8080
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)
Cookie: JSESSIONID=3370EC843B09363C0A8DD09A2D1F21E3
Cookie2: $Version=1
--1afdzzMUQLfSOmu0Pgb2F-nmEnTwWuPf3
Content-Disposition: form-data; name="ResourceDescriptor"
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 8bit
<resourceDescriptor name="myfolder" wsType="folder" uriString="/myfolder"
                    isNew="false">
  <label>REST created folder</label>
  <resourceProperty name="PROP_PARENT_FOLDER">
    <value>/</value>
  </resourceProperty>
</resourceDescriptor>
--1afdzzMUQLfSOmu0Pgb2F-nmEnTwWuPf3--

Also, the example above shows a multi-part request even though it is only sending the plain-text resource descriptor and not a binary file. Usually, such requests could be sent without multiple parts, and multiple parts are used to send a binary file, for example when creating a report.

When the ResourceDescriptor contains the ResourceProperty PROP_PARENT_FOLDER, that property overrides the path/to/resource given as the URL and determines the location of the new resource.

The response to the PUT request is the complete resource descriptor for the new folder:

HTTP/1.1 201 Created
Server: Apache-Coyote/1.1
Cache-Control: no-cache
Content-Length: 648
Date: Mon, 01 Aug 2011 14:44:05 GMT
<resourceDescriptor name="myfolder" wsType="folder" uriString="/myfolder"
                    isNew="false">
  <label>REST created folder</label>
  <creationDate>1312209845000</creationDate>
  <resourceProperty name="PROP_RESOURCE_TYPE">
    <value>com.jaspersoft.jasperserver.api.metadata.common.domain.Folder</value>
  </resourceProperty>
  <resourceProperty name="PROP_PARENT_FOLDER">
    <value>/</value>
  </resourceProperty>
  <resourceProperty name="PROP_VERSION">
    <value>0</value>
  </resourceProperty>
  <resourceProperty name="PROP_HAS_DATA">
    <value>false</value>
  </resourceProperty>
</resourceDescriptor>
Version: 
Feedback
randomness