HTTP or VelocityReport Plugin: How to do a DELETE method

Questions and answers on developing, deploying and using plugins and JavaBeans

HTTP or VelocityReport Plugin: How to do a DELETE method

Postby palacio » Thu Dec 03, 2015 10:43 pm

Hi!

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.

Code: Select all
public static ClientResponse RemoveMailingList() {
       Client client = Client.create();
       client.addFilter(new HTTPBasicAuthFilter("api",
                       "xxx"));
       WebResource webResource =
               client.resource("https://api/VERSION/lists/" +
                               "DOMAIN");
       return webResource.delete(ClientResponse.class);
}


I am accessing a API , for now I am able to do the POST method , I would just like to learn and understand how to do the DELETE method in
servoy.

Thank you in advance,
palacio
palacio
 
Posts: 47
Joined: Tue Aug 18, 2015 12:29 pm

Re: HTTP or VelocityReport Plugin: How to do a DELETE method

Postby ptalbot » Fri Dec 04, 2015 5:17 am

The velocity way is easy.

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:
Code: Select all
testVelocity: {
  services: {
     removeMailingList: {
       url: "serviceURL",
       method: "delete",
       processType: "client",
       authentication: "basic",
       preemptive: true,
       defaultUser: "api"
     }
  }
}

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:
Code: Select all
api=xxxx


Then in Servoy, you simply invoke the service this way:
Code: Select all
plugins.Velocity.invokeService("removeMailingList");


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: https://www.servoyforge.net/projects/ve ... vices/wiki
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: HTTP or VelocityReport Plugin: How to do a DELETE method

Postby palacio » Fri Dec 04, 2015 6:48 pm

ptalbot wrote:The velocity way is easy.

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:
Code: Select all
testVelocity: {
  services: {
     removeMailingList: {
       url: "serviceURL",
       method: "delete",
       processType: "client",
       authentication: "basic",
       preemptive: true,
       defaultUser: "api"
     }
  }
}

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:
Code: Select all
api=xxxx


Then in Servoy, you simply invoke the service this way:
Code: Select all
plugins.Velocity.invokeService("removeMailingList");


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: https://www.servoyforge.net/projects/ve ... vices/wiki



Thank you Mr. Patrick Talbot I'll try it right away and hope that it works
palacio
 
Posts: 47
Joined: Tue Aug 18, 2015 12:29 pm

Re: HTTP or VelocityReport Plugin: How to do a DELETE method

Postby sbutler » Fri Dec 04, 2015 7:53 pm

The HTTP plugin way:

Code: Select all
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())
Scott Butler
iTech Professionals, Inc.
SAN Partner

Servoy Consulting & Development
Servoy University- Training Videos
Servoy Components- Plugins, Beans, and Web Components
Servoy Guy- Tips & Resources
ServoyForge- Open Source Components
User avatar
sbutler
Servoy Expert
 
Posts: 759
Joined: Sun Jan 08, 2006 7:15 am
Location: Cincinnati, OH

Re: HTTP or VelocityReport Plugin: How to do a DELETE method

Postby ROCLASI » Sat Dec 05, 2015 7:57 am

Hi Scott,

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?
Robert Ivens
SAN Developer / Servoy Valued Professional / Servoy Certified Developer

ROCLASI Software Solutions / JBS Group, Partner
Mastodon: @roclasi
--
ServoyForge - Building Open Source Software.
PostgreSQL - The world's most advanced open source database.
User avatar
ROCLASI
Servoy Expert
 
Posts: 5438
Joined: Thu Oct 02, 2003 9:49 am
Location: Netherlands/Belgium

Re: HTTP or VelocityReport Plugin: How to do a DELETE method

Postby palacio » Sat Dec 05, 2015 5:30 pm

Hi Mr. Patrick Talbot

I followed every steps in the documentation of Velocity services

i modified the config.json file:
Code: Select all
NewsletterApi:{
   services: {
       deleteMailList: {
         url: "https://API.com",
         method: "delete",
         processType: "client",
         authentication: "basic",
         preemptive: true,
         defaultUser: "api",
       }
   }
}


I modified the user.properties file:
Code: Select all
api=XXX


then in servoy , one of my existing forms I created a button with a on action function and inside it :
Code: Select all
   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 ???
palacio
 
Posts: 47
Joined: Tue Aug 18, 2015 12:29 pm

Re: HTTP or VelocityReport Plugin: How to do a DELETE method

Postby ptalbot » Sat Dec 05, 2015 7:59 pm

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

Hope this helps,
-Patrick
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: HTTP or VelocityReport Plugin: How to do a DELETE method

Postby palacio » Sun Dec 06, 2015 1:21 am

Hi Mr. Patrick,

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 https://www.servoyforge.net/projects/velocity-services/wiki

after writing it in the config.json file I wrote this function on the solution named TestWebService which I used in the
config.json :

Code: Select all
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:
Code: Select all
=>plugins.Velocity.invokeService("utcTime")
"Error during evalution:org/apache/http/impl/client/AbstractHttpClient"


Maybe I'm forgetting to install something?
palacio
palacio
 
Posts: 47
Joined: Tue Aug 18, 2015 12:29 pm

Re: HTTP or VelocityReport Plugin: How to do a DELETE method

Postby ptalbot » Sun Dec 06, 2015 2:28 am

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)
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: HTTP or VelocityReport Plugin: How to do a DELETE method

Postby palacio » Tue Dec 08, 2015 1:16 am

ptalbot wrote: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.

Code: Select all
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.

Thank you in advance,
Palacio
palacio
 
Posts: 47
Joined: Tue Aug 18, 2015 12:29 pm

Re: HTTP or VelocityReport Plugin: How to do a DELETE method

Postby ptalbot » Tue Dec 08, 2015 2:18 am

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.
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: HTTP or VelocityReport Plugin: How to do a DELETE method

Postby palacio » Tue Dec 08, 2015 3:27 pm

ptalbot wrote: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

Code: Select all
public static ClientResponse RemoveMailingList() {
       Client client = Client.create();
       client.addFilter(new HTTPBasicAuthFilter("api",
                       "XXXX"));
       WebResource webResource =
               client.resource("https://api.mailgun.net/" +
                               "LIST@DOMAIN.com");
       return webResource.delete(ClientResponse.class);
}


A function to delete a Mailing List.

palacio
palacio
 
Posts: 47
Joined: Tue Aug 18, 2015 12:29 pm

Re: HTTP or VelocityReport Plugin: How to do a DELETE method

Postby ptalbot » Wed Dec 09, 2015 8:39 pm

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.
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: HTTP or VelocityReport Plugin: How to do a DELETE method

Postby palacio » Thu Dec 10, 2015 12:29 am

goldcougar wrote:The HTTP plugin way:

Code: Select all
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())


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 .

palacio
palacio
 
Posts: 47
Joined: Tue Aug 18, 2015 12:29 pm

Re: HTTP or VelocityReport Plugin: How to do a DELETE method

Postby palacio » Thu Dec 10, 2015 12:33 am

ptalbot wrote: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?

palacio
palacio
 
Posts: 47
Joined: Tue Aug 18, 2015 12:29 pm

Next

Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 7 guests

cron