Jump to content
Changes to the Jaspersoft community edition download ×

Creating a folder using the REST service.


spierepf

Recommended Posts

Greetings,

I am trying to create a folder in the JRS repository using the REST service. I am using Ruby and the rest-client library to connect.

So far, I've managed to read stuff from the repository, but I haven't had much luck with altering the repository contents.

My test case is to create two folders at the root of the repository. A parent folder at /parent, and a child folder at /parent/child. Here is the resource descriptor of the parent folder.

<resourceDescriptor name="parent" wsType="folder" uriString="/parent">  <label>REST created folder</label>  <resourceProperty name="PROP_PARENT_FOLDER">    <value>/</value>  </resourceProperty></resourceDescriptor>

No matter what I try, I get an error 400 BadRequest, with a 'Invalid resource descriptor' message.

Has anyone had any success with creating folders?

Peter.

 

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

I've installed TcpMon and captured the request:

PUT /report/rest/resource/ HTTP/1.1Content-Type: multipart/form-data; boundary=32032Accept: */*; q=0.5, application/xmlAccept-Encoding: gzip, deflateHost: localhost:8080Content-Length: 315Authorization: Basic c3VwZXJ1c2VyOnN1cGVydXNlcg==--32032Content-Disposition: form-data; name="ResourceDescriptor"<resourceDescriptor name="parent" wsType="folder" uriString="/parent" isNew="true">  <label>REST created folder</label>  <resourceProperty name="PROP_PARENT_FOLDER">    <value>/</value>  </resourceProperty></resourceDescriptor>--32032--

and the response:

 

HTTP/1.1 400 Bad RequestServer: Apache-Coyote/1.1Cache-Control: privateExpires: Wed, 31 Dec 1969 20:00:00 ASTSet-Cookie: JSESSIONID=CC3CE809E753F21931A3558DEFCE5B90; Path=/report/; HttpOnlyContent-Type: text/xml;charset=UTF-8Content-Length: 27Date: Wed, 13 Jun 2012 20:56:47 GMTConnection: closeInvalid resource descriptor

 

Link to comment
Share on other sites

  • 2 months later...

 I'm using multipart-post gem in a rails 3 app

 

opening connection to reports.intouchgps.com...

opened

<- "PUT /jasperserver/rest/resource HTTP/1.1\r\nAccept: */*\r\nUser-Agent: Ruby\r\nContent-Type: multipart/form-data; boundary=-----------RubyMultipartPost\r\nContent-Length: 457\r\nAuthorization: Basic d2Vic2VydmljZXM6d2Vic2VydmljZXM=\r\nConnection: close\r\nHost: reports.intouchgps.com:8080\r\n\r\n"

<- "-------------RubyMultipartPost\r\nContent-Disposition: form-data; name=\"ResourceDescriptor\"\r\n\r\n<resourceDescriptor name=\"75a425c0-de74-012f-d7d6-38ac6fdf26f8\" wsType=\"folder\" uriString=\"/Scheduled/75a425c0-de74-012f-d7d6-38ac6fdf26f8\" isNew=\"false\"><label>User Folder 75a425c0-de74-012f-d7d6-38ac6fdf26f8</label><resourceProperty name=\"PROP_PARENT_FOLDER\"><value>/Scheduled</value></resourceProperty></resourceDescriptor>\r\n-------------RubyMultipartPost--\r\n\r\n"

-> "HTTP/1.1 400 Bad Request\r\n"

-> "Server: Apache-Coyote/1.1\r\n"

-> "Pragma: No-cache\r\n"

-> "Cache-Control: no-cache\r\n"

-> "Expires: Wed, 31 Dec 1969 16:00:00 PST\r\n"

-> "P3P: CP=\"ALL\"\r\n"

-> "Set-Cookie: JSESSIONID=BE57A2C851D02CB1CB448052D9246DB3; Path=/jasperserver\r\n"

-> "Content-Type: text/xml;charset=UTF-8\r\n"

-> "Content-Length: 27\r\n"

-> "Date: Tue, 11 Sep 2012 20:14:48 GMT\r\n"

-> "Connection: close\r\n"

-> "\r\n"

reading 27 bytes...

-> "Invalid resource descriptor"

read 27 bytes

Conn close

 

This was in the log

 

2012-09-11 12:45:48,673 DEBUG RESTServlet,http-8080-7:131 - request params: Path: /resource Requested Service: resource Service from registry: class com.jaspersoft.jasperserver.rest.services.RESTResource$$EnhancerByCGLIB$$79dc9457
2012-09-11 12:45:48,676 DEBUG RESTAbstractService,http-8080-7:100 - execute: Resource=/resource Method=put
2012-09-11 12:45:48,815 DEBUG Utils,http-8080-7:158 - 0 attachments were extracted from the POST
2012-09-11 12:45:48,817 ERROR RESTResource,http-8080-7:237 - Unexpected error during resource descriptor marshaling: Premature end of file.
org.xml.sax.SAXParseException: Premature end of file.

 

Link to comment
Share on other sites

  • 9 months later...
  • 5 years later...

For anyone still trying to do this, here is an example that worked for me. Creating the folder "Reports" under myorg locally.

Using PUT

url = 'http://localhost:8080/jasperserver-pro/rest_v2/resources/organizations/myorg/Reports'

headers = {'Content-Type': 'application/repository.folder+json'}

content = {"uri" :"/organizations/myorg/Reports", "label":"Reports", "description":"Create and save your own reports here.", "permissionMask":"0", "creationDate": "2013-07-04T12:18:47", "updateDate": "2013-07-04T12:18:47", "version":"0"}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...