Velocity Services question

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

Velocity Services question

Postby garroyo » Sat Mar 05, 2022 1:22 pm

I am testing the velocity service to see if it can be used to send an xml to a web service
Environment: Internet.
Protocol: HTTPS 1.1 (TLS 1.1 or higher).
Shipping method: POST.
Messages: Rest Service.
Encoding: UTF-8. The input is an XML that must conform to the following XSD input schema specification.


This is the config.json that I'm using after read the documentation of plugin:
Code: Select all
TicketBAI: {
       method: "post",
            processType: "client",
            params: {
                                url: "String", //web service url
            inPath: "String", //xml file path to send
            certPath: "String", //digital certificate path to use
            certpasswordPath: "String" //path of the key of the digital certificate to use
            },
            return: {
         file: "Path"
         },
         headers: {
            Content-Type: "application/xml",
            charset: "UTF-8",
                Accept: "application/json"
            }
        }

And I'm calling it like this:
Code: Select all
function envioTBAI98(myXml)
{
   var sURL = "https://tbai-prep.egoitza.gipuzkoa.eus/WAS/HACI/HTBRecepcionFacturasWEB/rest/recepcionFacturas/alta"
   plugins.Velocity.invokeService('TicketBAI',{url:sURL,inPath: 'C:\TMP\ficheroenviocurl.xml',certPath: 'D:\CERTIF_AG\cgagfnmt.pem', certpasswordPath: 'D:\CERTIF_AG\cgagfnmt_key.pem'}, callBack);
}


function callBack(result){
      application.output('callback');
      if (result) {
          if (result.exception) {
              application.output(result.exception, LOGGINGLEVEL.ERROR);
          } else {
              application.output(JSON.stringify(result));
          }
      }
   }

but I must not be doing something right, I can't get it to run. I would be grateful if someone could help me and tell me the correct way to do it.
garroyo
 
Posts: 14
Joined: Mon Jan 23, 2017 2:01 pm

Re: Velocity Services question

Postby ptalbot » Sun Mar 06, 2022 1:56 am

Not sure what you want to do here. If the idea is to send data as xml that's one thing, although I doubt the service you are trying to access is going to accept file paths which are local to the client. So, it looks like you want the plugin to read the file, sign it, and send it as xml, but the plugin is not made for that, and has no idea of your intention...
You can send data, like any kind of javascript object which you pass as parameters, as json or xml, in which case the plugin will create a JSON or XML structure based on the passed parameters.

2 things as well:

1/ the "url" parameters should be at the top level of your configuration, like:
Code: Select all
TicketBAI: {
       method: "post",
       processType: "client",
       url: "$url",
       entityFormat: "xml",
       params: {
              url: "String",
              ...
       }
}


2/ if you want to send data as JSON or XML in the body and not in url-encoded format (default), you need to set the "entityFormat" parameter to either "json" or "xml"

Still, the plugin will not be able to know that the paths you are passing in parameters are files that should be read, used to sign and send the result as file. To be able to achieve that you will need to do the signing yourself (client side) then use the http plugin to send the signed file.
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: 1659
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC

Re: Velocity Services question

Postby garroyo » Mon Mar 07, 2022 11:28 am

Thanks for the answer. My intention is to send an XML to a web service using my digital certificate and obtain an xml validation response. You answer me that this plugin could not use it to carry out that task. Is there a plugin equivalent to the CURL command? For what you say the http plugin could work for that task.
garroyo
 
Posts: 14
Joined: Mon Jan 23, 2017 2:01 pm

Re: Velocity Services question

Postby ptalbot » Mon Mar 07, 2022 5:22 pm

Yes, the http plugin should be able to do what you want, although it's not really equivalent to CURL as it is a low level plugin and you will need to deal with everything yourself (creating a client, creating a request object, filling all the parameters and headers, etc.)
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: 1659
Joined: Wed Mar 11, 2009 5:13 am
Location: Montreal, QC


Return to Plugins and Beans

Who is online

Users browsing this forum: No registered users and 10 guests

cron