I would like to ask if anyone knows how to do a Delete method using the HTTP plugin or the VelocityReport plugin (Servoy 5.2).
I was trying to translate these java codes in java maybe the plugins above may help me or may not.
In your config.json (which should reside inside the a www folder inside the reports folder pointed by the server properties “velocityreport.reportfolder” - that you’ll find in servoy-admin/plugin-settings), inside the solution object declaration (let’s call it testVelocity), you declare the service:
The default user password must be declared in the users.properties alongside the config.json. It’s a simple key/value properties file, and the password will be encrypted upon the first read, in your case, it will contain:
api=xxxx
Then in Servoy, you simply invoke the service this way:
To be noted that the config.json file is checked upon any request to the velocity servlet, so you can make changes to this file, adding or modifying services, and they will be picked up automatically.
In your config.json (which should reside inside the a www folder inside the reports folder pointed by the server properties “velocityreport.reportfolder” - that you’ll find in servoy-admin/plugin-settings), inside the solution object declaration (let’s call it testVelocity), you declare the service:
The default user password must be declared in the users.properties alongside the config.json. It's a simple key/value properties file, and the password will be encrypted upon the first read, in your case, it will contain:
api=xxxx
Then in Servoy, you simply invoke the service this way:
To be noted that the config.json file is checked upon any request to the velocity servlet, so you can make changes to this file, adding or modifying services, and they will be picked up automatically.
Check out the Velocity Services project for more info: <a class="postlink" href="https://www.servoyforge.net/projects/velocity-services/wiki">https://www.servoyforge.net/projects/ve ... vices/wiki</a>
Thank you Mr. Patrick Talbot I’ll try it right away and hope that it works
var client = plugins.http.createNewHttpClient()
var deleteReq = client.createDeleteRequest('https://api/VERSION/lists/')
var response = deleteReq.executeRequest('api', 'xxx')
application.output(response.getStatusCode()) //should be plugins.http.HTTP_STATUS.SC_OK for most
application.output(response.getResponseBody())
Palacio is still using Servoy 5.2 which has an older HTTP plugin that doesn’t support the createDeleteRequest function.
Do you know if you can simply install the Servoy 7.x version of this plugin in Servoy 5.2?
then in servoy , one of my existing forms I created a button with a on action function and inside it :
var v_result = plugins.Velocity.invokeService("deleteMailList");
application.output(v_result);
the result is always: {exception:org.mozilla.javascript.NativeJavaObject@798ded3f}
Additional:
I don’t know if this was needed to be done, I created a new Solution , name = NewsletterApi
inside it I created a form testNewsletter with a function vr_getContext () ← Do i need to do this part ???
1/ In developer, the services should be declared in the ACTIVE solution.
2/ the url should be a valid one.
3/ Your config.json should be valid JSON (althought with lenient rules), you can go here: http://www.freeformatter.com/json-validator.html, paste your JSON into a { }, check the “Accept non-quoted names” and “Accept single-quotes” and click “Validate JSON”, this will show you whether there is an issue. For example the trailing , comma after “api”
4/ the XXX in api should be the real password you use.
If you put the “services” declaration inside the active solution (or one of its module) it should work.
No need to a vr_getContext() method, unless you are the one exposing the service…
I tried the steps that you said but still the invokeService doesn’t function.
Then I tried to use the “Calling existing services” in the documentation Wiki - Velocity Services - ServoyForge
after writing it in the config.json file I wrote this function on the solution named TestWebService which I used in the
config.json :
function onAction(event) {
// TODO Auto-generated method stub
var v_result = plugins.Velocity.invokeService("utcTime");
application.output(v_result + ' ' + v_result.dateString);
}
then I tried debugging it using the interactive console:
=>plugins.Velocity.invokeService("utcTime")
"Error during evalution:org/apache/http/impl/client/AbstractHttpClient"
Maybe I’m forgetting to install something?
palacio
Looks like you have a jar issue. Perhaps you have more than one httpclient.jar/httpcore.jar in your application_server install.
Just make sure there’s only one of both of these jars in the /lib folder. Remove any other duplicates from your /plugins folders (and sub folders)
ptalbot:
Looks like you have a jar issue. Perhaps you have more than one httpclient.jar/httpcore.jar in your application_server install.
Just make sure there’s only one of both of these jars in the /lib folder. Remove any other duplicates from your /plugins folders (and sub folders)
Mr. Patrick I searched for the files but there were no duplicates, sorry for this news.
Meanwhile I saw something in the internet some one who also used servoy but he did a workaround to do a Post method
I tried to use it but it failed because I am not writing the apikey.
function myFunction()
{
//DELETE
var client = new Packages.org.apache.commons.httpclient.HttpClient();
// API-missingpart.....CREDENTIALS PART????
var fileDelete = new Packages.org.apache.commons.httpclient.methods.DeleteMethod("https://domain.net/");
var status = client.executeMethod(fileDelete);
//read response
if(status == 200){
application.output("DONE");
} else {
application.output("NOPE");
}
}
I think this will work but I need your help in the missing part area.
That’s strange because I tried a call to a request.bin with a delete word in Servoy 5.2 and it worked without any class exception…
Now your “API part” could be sent as parameters, in the url, in the body, as json, or xml, in the header, etc.
Check what your service is expecting, until then, I cannot help.
ptalbot:
That’s strange because I tried a call to a request.bin with a delete word in Servoy 5.2 and it worked without any class exception…
Now your “API part” could be sent as parameters, in the url, in the body, as json, or xml, in the header, etc.
Check what your service is expecting, until then, I cannot help.
Mr. Patrick I was trying to do this code, it was in Java
Sorry but your Java is custom. Looks like it’s using the Jersey API. But basically, it looks like you’re setting authentication headers (which are base64 encoded). Depending on whether your service needs preemptive authentication or not, it would lead to different java code, but still I wouldn’t make it straight into servoy javascript, but rather encapsulate that into a plugin.
var deleteReq = client.createDeleteRequest(‘https://api/VERSION/lists/’)
var response = deleteReq.executeRequest(‘api’, ‘xxx’)
application.output(response.getStatusCode()) //should be plugins.http.HTTP_STATUS.SC_OK for most
application.output(response.getResponseBody())
Hi Mr. Scott , is there a way to use the Delete method in Servoy 5.x because this is my only problem I could not do
any Delete method in servoy 5 .
ptalbot:
Sorry but your Java is custom. Looks like it’s using the Jersey API. But basically, it looks like you’re setting authentication headers (which are base64 encoded). Depending on whether your service needs preemptive authentication or not, it would lead to different java code, but still I wouldn’t make it straight into servoy javascript, but rather encapsulate that into a plugin.
Yes the api documents that I was using it uses the Jersey APi, is there a way that I could use it in commons.httpclient or should I download the Jersey API and try creating a plugin that will help my problem in doing the DELETE Method?
Do you have any sample using the " new Packages.org.apache.commons.httpclient.HttpClient(); " as a DeleteMethod with
BasicAuthorization?
I suppose you could build it using the Jersey client as a dependency jar, although I would beware of the dependencies (and java version) needed.
Otherwise, commons.httpclient authentication samples are available on the Apache site, just make sure you follow v3.1 documentation (and not v4, which is not available in Servoy 5.2).