Jump to content
We've recently updated our Privacy Statement, available here ×

Problem creating reportUnit with nested resource (scriplet)


manzoor.mubashir

Recommended Posts

Hello, good day!
 
I am using jasperreports-server-cp-5.5.0 to create resources via REST v2 API and I am kind of hitting a dead end when creating reportUnit resource together with the resources.
 
When I upload without the scriptlet (without the resources part in the sample code below), I can create the resource on the server but I am having trouble when I attach a scriptlet.
 
payload = {
   "uri": resource_uri,
   "label": resource_name,
   "description": "Main jrxml file for resource %s" % resource_name,
   "dataSource": {
       "jdbcDataSource": {
           "uri": report_datasource,
           "label": settings.JASPER_DATASOURCE,
"driverClass": settings.JASPER_DATABASE_DRIVER_CLASS,
"username": settings.DATABASES['default']['USER'],
"password": settings.DATABASES['default']['PASSWORD'],
"connectionUrl": settings.JASPER_DATABASE_CONNECTION_URL
       }
   },
   "jrxml": {
       "jrxmlFile": {
           "uri": resource_uri,
           "label": resource_name,
           "content": encoded,
           "type": "jrxml"
       }
   },
   "resources": [{
    "resource": {
    "name": "baby",
    "file": {
    "fileResource": {
    "uri": resource_uri,
    "label": resource_name,
    "content": encoded2,
    "type": "jar"
    }
    }
    }
}
]
}
 
 
And here is the POST request in python that I am making:
 
try:
requests.post(
url=get_url('rest_v2/resources/reports/'),
data=json.dumps(payload),
  headers={'content-type': 'multipart/form-data'},
  auth=(settings.JASPER_USER, settings.JASPER_PASSWORD))
  except:
  raise
 
And the error I am getting is: 
 
The request sent by the client was syntactically incorrect (Bad Request 404)
 
Can anyone let me know what's wrong in what I am doing?
 
//Mubashir
 

 

Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

I believe jasper support team is either too busy or don't care about the product anymore. I am having the problem with getting answers to my question. Stackoverflow people point to go here. And here it is dead end. I can only suggest writing on daily basis. Their doc misses many fundamental hints without which we can't progress further.
Link to comment
Share on other sites

After my comment I suggest you to do the following:

try to include in  your accept cookie header application/json , as their error messages contain detailed info regarding the problem in json response. Also whenever you try to create new resource dont forget that you need to create custom type namely application/repository.reportUnit+json - cant remember exactly(see the doc) the syntax but this is mandatory. Also dont undermine the power of rest client like Cocoa rest client (if using mac) where you can test what you are doing quite easily.

 

Finally, dont attempt to create local resources unless you are 100% sure you won't need to reuse that dataSource in other reports. From what I found it you cannot reference local resources from reports.(but i am asking here whether my assumption is correct on daily basis).

 

 

 

Link to comment
Share on other sites

Thanks for the acknowledgement Tonyy.

I had already tried setting the content-type to "application/repository.reportUnit+json" but in vain. Then I went on to read the documentation and I found this text "The POST method also supports a way to create complex resources and their nested resources in a single multipart request." and hence, I decided to try the multipart/form-data which gave me the errors mentioned in my first post.

Adding application/json in the Accept header gives me the following error response back:

{"message":"Unexpected error","errorCode":"unexpected.error","parameters":["com.jaspersoft.jasperserver.api.JSExceptionWrapper: Can not deserialize instance of com.jaspersoft.jasperserver.dto.resources.ClientReportUnitResourceListWrapper out of START_ARRAY tokenn at [source: org.apache.catalina.connector.CoyoteInputStream@49b0741a; line: 1, column: 19763] (through reference chain: com.jaspersoft.jasperserver.dto.resources.ClientReportUnit["resources"])"]}

This is the error, in fact, I have been seeing on my screen for so long. As I understand, the "resources" part of the resource descriptor is invalid and cannot be deserialized as a valid report unit object. But how else am I supposed to send in the resource descriptor? I am merely following the report unit definition mentioned on page 34 of the Web Services Guide which requires the resources to be in the format that I'm sending.

   "resources": [
   "resource": {
   "name": "{resourceName}",
    "file": {
   "fileReference": {
   "uri": "{fileResourceUri}"
   }
   }
   },
   ...
  ]
 
Ironically, the JSON example provided in the example isn't correct either, it's an invalid JSON! The "resources" array should contain the objects bounded by "{ } ". Having found all these glitches and trying several combinations and failing, I am now forced to dig down in to the source code to learn a bit more about the problem at hand. Unless you or anyone else have some other suggestion for me?
 
 
 
 

 

 

 

 

 
Link to comment
Share on other sites

I believe your problem is merely json mapping which means you are getting close. There are online json parsers, have you tried to put what you send to JasperServer? I am pretty sure it will highlight syntax errors, I am using JacksonMapper for Java and it works quite nicely. I got similar messages when could not find suitable data structure when receiving JSON response. Yours is just the opposite.

 

In short words JasperServer can't understand the JSON structure you are sending. Keep digging you are close.

Link to comment
Share on other sites

Well, the JSON variant of the resource descriptor just doesn't work! There seems to be a bug with the deserializer library that Jasper 5.5 is using or the documentated JSON syntax is wrong. The XML version of the same works but with a nasty fix, i.e.  the XML tree nodes are incorrect in the documentation. The "resources" node should be in the following order: resources -> resource -> fileResource whereas it appears as resources -> resource -> file -> fileResource in the documentaion. Isn't this annoying?? Seriously, someone in the Jasper support team has to clarify/fix these glitches. Or may be they just want people to use the Enterprise edition of their product and only see the Community edition as their "selling" material.

Link to comment
Share on other sites

  • 2 weeks later...
Thanks for this tip manzoor.mubashir. I had the same issue with JSON that had me perplexed, XML works fine. For XML I could figure out that 'file' should not be there from source, and I was trying the same structure for JSON without any luck. Converting it to XML worked like a charm.
Link to comment
Share on other sites

  • 2 months later...

Faced the same promblem: had to create report unit with all its resources on the Jasper Server (version 5.5.0) via REST api using PUT request.
After several (actually, many) atempts I have finally found out what the descriptor should look like.
In JSON:

{
"label" : YOUR_REPORT_LABEL,
"description" : YOUR REPORT DESCRIPTION,
 
"dataSource" : { 
"dataSourceReference" : { 
"uri" : YOUR DATA SOURCE URI
},
 
"jrxml" : {
"jrxmlFile" : {
"label" : FILE NAME WITH EXTENSION,
"type" : "jrxml",
"content" : JRXML FILE 64BASE ENCODED CONTENT
}
},
 
"resources" : {
"resource" : [
{  "name" : FILE NAME WITH EXTENSION,
    "file" : {
"fileResource" : {
            "label" : FILE ANME WITH EXTENSION,
                                                                  "type" : FILE TYPE,
             "content" : FILE 64BASE ENCODED CONTENT
}
      }
             },
...
]
}
 
In this way all resources get loaded as local resources of the report unit and so I just use their filenames with extensions as resource labels. But as far as I know there is no special constraint for that.
 
 And XML descriptor looks like this:
 

<reportUnit>

<label>RESOURCE_LABEL</label>

<description>RESOURCE_DESCRIPTION</description>

 <dataSourceReference>

  <uri>PATH_TO_DS_IN_REPO</uri>

 </dataSourceReference>

 <jrxmlFile>

 <label>JRXML _FILE_NAME_WITH_EXT</label>

 <type>jrxml</type>

 <content>64_BASE_ENCODED_FILE_CONTENT</content>

 </jrxmlFile>

  <resources>

  <resource>           

         <name>FILE_NAME_WTH_EXT</name>

         <fileResource>                      

                <label> FILE_NAME_WTH_EXT </label>

                <type>FILE_TYPE</type>

   <content>64_BASE_ENCODED_FILE_CONTENT content>

         </fileResource>

  </resource>

   </resources>    

</reportUnit>

 
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...