mateusz.moska Posted December 11, 2012 Share Posted December 11, 2012 Hi,I've got a problem with creating the simple resource by putting resource descriptor into multipart request. I have been looking for the solution on jasper server community, but I couldn't have found an answear. If I try to create a resource, the same as is in the documentation, I will get Error 400 Bad Request: "Invalid Resource Descriptor" and in the jasperserver.log file I've got an exception:2012-12-10 11:41:55,054 ERROR RESTResource,http-18080-6:237 - Unexpected error during resource descriptor marshaling: Premature end of file. org.xml.sax.SAXParseException: Premature end of file. at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) at com.jaspersoft.jasperserver.rest.services.RESTResource.doPut(RESTResource.java:220) at com.jaspersoft.jasperserver.rest.RESTAbstractService.execute(RESTAbstractService.java:113) ...In the attached files there are two clients create in JAVA and C#, both cause the same error. What is interesting, if I send the seme resource descriptor by PUT method, but without multipart, every thing goes fine. Unfortunately in the future I will need the request with multipart, because I want to create resource with file from remote system (I can not use SOAP based WS).Best Regards Link to comment Share on other sites More sharing options...
christophe_1 Posted December 13, 2012 Share Posted December 13, 2012 Hi i had the same issue. The documentation is not true.To create a new folder, dont use multipart/form-data but just text/plain. see my example below :in this example body=dataput in this url = http://localhost:8080/jasperserver/rest/resourceheaders = Cookie : JSESSIONID=9D19A14DB810A623C9475673A86A5BEE; Path=/jasperserver content-type : text/plain User-Agent : JasperServer-Pythondata = your XML resource descriptor Reponse = status : 201 content-length : 0 expires : Thu, 01 Jan 1970 01:00:00 CET server : Apache-Coyote/1.1 pragma : No-cache cache-control : no-cache date : Thu, 13 Dec 2012 09:54:01 GMT p3p : CP="ALL" content-type : text/xml;charset=UTF-8 Link to comment Share on other sites More sharing options...
mateusz.moska Posted December 13, 2012 Author Share Posted December 13, 2012 Hi Chrispohe_1,Thanks for the response, but I think you don't understand me. Creating a folder was just a simple example, in the future I want to create more complicated resources like, jrxml files, images ...The documentation said: "If the resource has one or more file resources, they must be provided using a multipart request." So I think this is only one posibility to put resourceDescriptor and file content together by REST webservice. Link to comment Share on other sites More sharing options...
christophe_1 Posted December 13, 2012 Share Posted December 13, 2012 Sorry for the empty post above.Hey,To put or post a resource including resourcedescriptor and file resource, see my example belowput in this url = http://localhost:8080/jasperserver/rest/resourceheaders = Cookie : JSESSIONID=96F74EFB25567E3F0CD872652EAF3FBB; Path=/jasperserver Content-Length : 1649 Content-Type : multipart/form-data; boundary=643e0c37cf39452eb005e5be13a4da72 User-Agent : JasperServer-Pythondata =--643e0c37cf39452eb005e5be13a4da72Content-Disposition: form-data; name="ResourceDescriptor"Content-Type: text/plain; charset=utf-8 your xml resourcedescriptor with property has data set to true --643e0c37cf39452eb005e5be13a4da72Content-Disposition: form-data; name="/images/imagetest.png"; filename="/var/lib/tomcat6/webapps/jasperserver/wcf/tree/leaf.png"Content-Type: image/png --643e0c37cf39452eb005e5be13a4da72-- Reponse = status : 201 content-length : 0 expires : Thu, 01 Jan 1970 01:00:00 CET server : Apache-Coyote/1.1 pragma : No-cache cache-control : no-cache date : Thu, 13 Dec 2012 12:30:09 GMT p3p : CP="ALL" content-type : text/xml;charset=UTF-8 the name of the second argument must be the same as the uriString Link to comment Share on other sites More sharing options...
mateusz.moska Posted December 14, 2012 Author Share Posted December 14, 2012 Hi,The answer was very helpful, thanks a lot! The example in documentation is incorrect. You can't create resource using multipart content-type without sending a file content.In my example you can create folder using multipart content type, but you have to add dummy file as one part in the request. Link to comment Share on other sites More sharing options...
christophe_1 Posted December 14, 2012 Share Posted December 14, 2012 I know, I told you the documentation is false and incompleteFYI, i found a good code example lost somewhere in this website : http://community.jaspersoft.com/wiki/getting-started-rest-web-service-apiyou'll find java code example at the bottom of page. Just read the code in the following path :codeexamplesrctestjavacomjaspersoftjasperserverrestsampleBasicResourceCRUDTest.javaI hope i help a lot of people, because i never found any informations about creating resource with RESTapi Link to comment Share on other sites More sharing options...
anjalisaxena Posted March 4, 2013 Share Posted March 4, 2013 When I am trying to follow the above example I am getting :HTTP/1.1 403 Forbidden.Can you please share the format of your resource descriptor. Appreciate your help in advance. Link to comment Share on other sites More sharing options...
christophe_1 Posted March 4, 2013 Share Posted March 4, 2013 Hi, if you get a 403 that it's not a Resource Descriptor format issue. You try to use method not allowed. Please explain you're trying to do. Christophe Link to comment Share on other sites More sharing options...
anjalisaxena Posted March 5, 2013 Share Posted March 5, 2013 Hi Chris, Appreciate your response. I have copied a jrxml from the server by GET method and now I am trying to put that back to the same location meaning I need to use addormodify, in REST API as per documentation I have to use POST method with resource service. I created a multi part request as per the above example. I am pasting the pseudo-code below MultipartEntity multipartEntity = null; HttpPost generateReport = new HttpPost("http://localhost:8070/jasperserver/rest/resource/pathtoresource"); multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); multipartEntity.addPart("ResourceDescriptor", new StringBody(requestXml)); multipartEntity.addPart("http://localhost:8070/jasperserver/rest/resource/pathtoresource", new FileBody(new File("location of jrxml"))); generateReport.setEntity(multipartEntity); HttpResponse httpResponse = httpClient.execute(generateReport, localContext); Before this code I am calling the login function an I am getting status 200 but then 403. Anjali Link to comment Share on other sites More sharing options...
christophe_1 Posted March 5, 2013 Share Posted March 5, 2013 You say : "I have copied a jrxml from the server by GET method and now I am trying to put that back to the same location meaning I need to use addormodify, in REST API as per documentation I have to use POST method with resource service" Exact ! You say : "http://localhost:8070/jasperserver/rest/resource/pathtoresource" the documentation is not exact. You have to use pathtoresource for PUT method BUT pathtoresource/resourcetomodify for POST method. You can't use POST in a folder. You need to know name the of resource you want to modify. Do you understand i mean ? Link to comment Share on other sites More sharing options...
anjalisaxena Posted March 5, 2013 Share Posted March 5, 2013 Thanks for your reply. Exactly that's what I am trying to do. I am doing a POST and then in the above statement "http://localhost:8070/jasperserver/rest/resource/pathtoresource" here actually path to resource is the path to the reportunit, which is what I need to modify. Similarly in the same API I have a need to copy a reportunit from one folder to another within the jasperserver. For that I am using PUT which is giving me 400 error. Link to comment Share on other sites More sharing options...
anjalisaxena Posted March 5, 2013 Share Posted March 5, 2013 One more thing I will like to share, the way I am trying to capture cokkies DefaultHttpClient httpClient = new DefaultHttpClient(); HttpContext localContext = new BasicHttpContext(); try{ HttpClient client = new HttpClient(); // Setting Login URL in a POST method String loginURL = "http://localhost:8070/jasperserver/rest/login"; HttpPost loginCall = new HttpPost("http://localhost:8070/jasperserver/rest/login"); PostMethod postMethod = new PostMethod(loginURL); httpClient.getCredentialsProvider().setCredentials( new AuthScope("http://localhost", 8070), new UsernamePasswordCredentials("username", "password")); cookieStore = new BasicCookieStore(); // Set authentication parameters postMethod.addParameter("j_username", "username"); postMethod.addParameter("j_password", "password"); int statusCode = client.executeMethod(postMethod); if (statusCode != HttpStatus.SC_OK) { System.out.println("Login failed: " + postMethod.getStatusLine()); return; }else System.out.println("The value of login status is:"+postMethod.getStatusLine()); // Create local HTTP context // Bind custom cookie store to the local context localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); loginCall.setHeader("content-type", "application/x-www-form-urlencoded"); Link to comment Share on other sites More sharing options...
christophe_1 Posted March 5, 2013 Share Posted March 5, 2013 error 400 means BadRequest : check format of your resourceDescriptor. Why dont' use the web interface to copy ? Link to comment Share on other sites More sharing options...
anjalisaxena Posted March 6, 2013 Share Posted March 6, 2013 This is the need of my application. We need to copy the jrxml and then change it on local and deploy it back and then generate the reports. Main thing is the issue of 403 on modifying.Any pointers for that. Link to comment Share on other sites More sharing options...
christophe_1 Posted March 6, 2013 Share Posted March 6, 2013 did you add the resource name in your path as '/pathtoresource/resourcename' ? 403 means the method is not allowed. Link to comment Share on other sites More sharing options...
anjalisaxena Posted March 6, 2013 Share Posted March 6, 2013 Yes I did added. Link to comment Share on other sites More sharing options...
christophe_1 Posted March 6, 2013 Share Posted March 6, 2013 FYI , it exists several REST clients addons in web browser (Chrome and firefox). Go to chrome webstore and look for 'REST' term. My favorite is Postman REST. You'll be able to try the API faster than modify your code. I spent a lot of time on this API. This tools is really efficient to test the API, and writing the code. Link to comment Share on other sites More sharing options...
anjalisaxena Posted March 6, 2013 Share Posted March 6, 2013 Already using cREST client plugin in CHROME. Same error. Thanks for your help though. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now