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
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
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???
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 .
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
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 ;
Well actually this seems to be working and i just feel like idiot , 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 .
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 ;