Not able to access package Apache Commons

Forum to discuss the Web client version of Servoy.

Not able to access package Apache Commons

Postby nestrocuation » Tue Mar 12, 2013 10:16 pm

Hey ,

I am trying to upgrade my solution from 5.1.12 to 6.1.4 . Most of the things is working fine , but we have a feature where we convert word document to pdf .

and it has this line of code which access the commons package in my servoy developer
Code: Select all
    var client = new Packages.org.apache.commons.httpclient.HttpClient();

When i debug my code stops over here and
The funny part is in new servoy i cannot get default propsals around Packages.org , coz they are not accessble .And this is the error i am getting in debug console . Any help appreciated
nestrocuation
 
Posts: 61
Joined: Tue Jun 08, 2010 11:27 pm

Re: Not able to access package Apache Commons

Postby ptalbot » Wed Mar 13, 2013 12:15 am

Why do you want to use the HttpClient directly? It's a vast library with various pitfalls and using it in JavaScript will most likely open up a can of leakage, thread concurrency exceptions, etc.
Why not use the http plugin???
Patrick Talbot
Freelance - Open Source - Servoy Valued Professional
https://www.servoyforge.net
Velocity rules! If you don't use it, you don't know what you're missing!
User avatar
ptalbot
 
Posts: 1654
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Not able to access package Apache Commons

Postby nestrocuation » Wed Mar 13, 2013 7:04 pm

Yes , i would love to do that . And i tried testing with http plugin the main issue is it only sets body content as string i am sending like byte array to jodconverter which converts it to pdf .

jod converter also accepts string but converting blob to string, i dont know how efficient that is . here is my code would appreciate any help . And i would have also checked out your new velocity service but we use ubuntu server .

Code: Select all
var client = new Packages.org.apache.commons.httpclient.HttpClient();
        var filePost = buildHTTPSettings();
   filePost.setRequestBody(new Packages.java.io.ByteArrayInputStream(documentByteArrayInputStream));
   filePost.setRequestHeader("Content-type","application/vnd.openxmlformats-officedocument.wordprocessingml.document");
   filePost.setRequestHeader("Accept","application/pdf");
   
   var httpResultCode = client.executeMethod(filePost);   
   
   if ( httpResultCode != 200 )
      throw httpResultCode;
   
   //TODO: Use getResponseBodyAsStream() to avoid memory issues?
   return filePost.getResponseBody();


And here is with http plugin

Code: Select all

var client = plugins.http.createNewHttpClient();
   var filepost = client.createPostRequest(url);
   [b]filepost.setBodyContent(documentByteArrayInputStream);[/b]
   filepost.addHeader("Content-type","text/plain");
       filepost.addHeader("Accept","application/pdf");
      var code = filepost.executeRequest();
     var code_status = code.getStatusCode();
    var code_response = code.getMediaData();
    var type = 'application/pdf';
    plugins.file.writeFile("myfile.pdf",code_response,type);
   return code_response ;

nestrocuation
 
Posts: 61
Joined: Tue Jun 08, 2010 11:27 pm

Re: Not able to access package Apache Commons

Postby nestrocuation » Wed Mar 13, 2013 8:06 pm

Well actually this seems to be working and i just feel like idiot :mrgreen: , thanks a lot patrick to make me try http plugin again .
but i would still want to know how to get packages in servoy as before .

Here is my updated code .
Code: Select all
var client = plugins.http.createNewHttpClient();
   var filepost = client.createPostRequest(url);
   [b]var file = plugins.file.convertToJSFile('blah.txt');
   var success = file.setBytes(documentByteArrayInputStream, true);
    filepost.addFile(null,file);[/b]
   filepost.addHeader("Content-type","text/plain");
       filepost.addHeader("Accept","application/pdf");
      var code = filepost.executeRequest();
     var code_status = code.getStatusCode();
    var code_response = code.getMediaData();
    var type = 'application/pdf';
    plugins.file.writeFile("myfile.pdf",code_response,type);
   return code_response ;
nestrocuation
 
Posts: 61
Joined: Tue Jun 08, 2010 11:27 pm

Re: Not able to access package Apache Commons

Postby david » Wed Mar 13, 2013 8:50 pm

http plugin was improved quite a bit from 5.1.x to 6.1.x.
David Workman, Kabootit

Image
Everything you need to build great apps with Servoy
User avatar
david
 
Posts: 1727
Joined: Thu Apr 24, 2003 4:18 pm
Location: Washington, D.C.


Return to Servoy Web Client

Who is online

Users browsing this forum: No registered users and 5 guests