Read XML from a POST to an Ebase form (Ebase 4.4.3)

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

chayward
Ebase User
Posts: 22
Joined: Fri Oct 13, 2017 9:43 am
Location: Hertford, UK
Contact:

Read XML from a POST to an Ebase form (Ebase 4.4.3)

#1

Postby chayward » Fri Oct 13, 2017 10:47 am

Hi

I have an Ebase 4.4.3 form which needs to be able to react to an HTTP POST that will be sent to the form URL, usually whilst the form is being used by a user.
The POST body (or content) will be XML, so I need to parse values out of that XML, in order to do a database update in the background.

I realise that the POST to the form will start a new session, so it will actually be independent of the form session currently in use by the user. This is expected, and will be ok.

Having looked through the XML resource documentation, there doesn't seem to be a matching 'adapter' that would fit this scenario, in order to create an XML resource for handling this.
Can anyone suggest a way that this can be done - perhaps directly by serverside Javascript? Or is there in fact a way using an XML resource definition?

Thanks.
Chris.
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#2

Postby Jon » Fri Oct 13, 2017 1:12 pm

Chris,

You can use Javascript on the server to populate an XML Resource form an XML string e.g.

Code: Select all

var languagesString = "<languages type='dynamic'><lang>JavaScript</lang><lang>Python</lang></languages>";
 // set the document 
 resources.myXmlResource.setDocument("languages", languagesString);
Alternatively, you can just use the Javascript XML API and not bother with a resource (I'm not too sure this is available in V4.4) e.g.

Code: Select all

var languagesString = "<languages type='dynamic'><lang>JavaScript</lang><lang>Python</lang></languages>";
var xml = new XML(languagesString);
xml...
Here's doc on the XML API http://www.ebasetech.com/ebase/doc/Javascript_XML.htm

Jon
0 x

chayward
Ebase User
Posts: 22
Joined: Fri Oct 13, 2017 9:43 am
Location: Hertford, UK
Contact:

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#3

Postby chayward » Fri Oct 13, 2017 1:54 pm

Thanks Jon, that is helpful.
I'll give those two options a try and let you know how it goes.

Regards,
Chris.
0 x

chayward
Ebase User
Posts: 22
Joined: Fri Oct 13, 2017 9:43 am
Location: Hertford, UK
Contact:

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#4

Postby chayward » Fri Oct 13, 2017 2:59 pm

Jon,

In this scenario, how can I actually get the body/content payload of the POST i.e. the form has been started by a POST.
Is there a request object available in the serverside Javascript?

Thanks.

Regards,
Chris.
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#5

Postby Jon » Fri Oct 13, 2017 3:48 pm

The Http Request is available at client.request e.g.
client.request.getParameter("parameterName");

..or you could have a form field of the same name set as a URL parameter and then access it as fields.NAME.value.

I'm not sure exactly what you're doing, but there are some features in later Ebase versions that may help you:
  • V4.5 adds a client API so you can call directly from client Javascript to server-side Javascript within the context of a form - setting field values, passing objects etc
    V5 adds Rest web services - can be called from a browser or anything else
0 x

chayward
Ebase User
Posts: 22
Joined: Fri Oct 13, 2017 9:43 am
Location: Hertford, UK
Contact:

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#6

Postby chayward » Fri Oct 13, 2017 4:06 pm

Thanks Jon.

Chris.
0 x

chayward
Ebase User
Posts: 22
Joined: Fri Oct 13, 2017 9:43 am
Location: Hertford, UK
Contact:

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#7

Postby chayward » Mon Oct 16, 2017 2:29 pm

Hello Jon

It seems that perhaps what I was hoping to do here is not possible.
I cannot get an Ebase form to run in reponse to a POST, it would seem i.e. as a background task, with no browser associated.
At least, I see nothing in the Tomcat logs to indicate that the form is responding to a POST to that form's URL.
Is there something in Ebase that will only allow an Ebase form to run in conjunction with a client browser?

Thanks,
Chris.
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#8

Postby Jon » Tue Oct 17, 2017 8:38 am

Chris,

Are you trying to initiate this form from server code?

If yes, then in V5.0 you can use services.scheduler.runBackgroundForm(). In V4.4 I think the only option would be to use Http client software e.g. something like this:

Code: Select all

importPackage (Packages.org.apache.commons.httpclient);
var httpclient = new HttpClient();
var url = "http://mydomain/ebase/ufsmain?formid=MYFORM";
var get = new GetMethod(url);
var status = httpclient.executeMethod(get);                  // execute get and get Http status code
var result = httpclient.getResponseBodyAsString();         //get response - if you need it 

Please note that I haven't tested this. The version of httclient that you have in V4.4 has now been deprecated and replaced by another package with the same name and this is shipped with Ebase V5, but this has a different API and the only example I have uses this. The example above uses the older version. So you might have to do a bit of work to get this code to work.

Good luck
Jon
0 x

chayward
Ebase User
Posts: 22
Joined: Fri Oct 13, 2017 9:43 am
Location: Hertford, UK
Contact:

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#9

Postby chayward » Tue Oct 17, 2017 9:15 am

Hello Jon
Thanks for the reply and that code suggestion. I do know the Apache Commons HttpClient component, from previous use in Java code in the past. However, to do a GET of the Ebase form is not quite what I am trying to do here.

This is actually a 3rd-party online payment process, which needs to notify 'our' code, which is Ebase form code currently, of online payment success for failure. It does this by POSTing a response to a URL that we tell them.
I wanted to be able to give them the URL of the Ebase form which is transacting with the outside online payment system, so that our Ebase code can then do the necessary updates in response to this payment notification POST. It would mean running the Ebase code whilst not associated with a browser session though.

My work colleagues here have reminded me that we already do a lot of that sort of work via Ebase scheduled tasks - mainly 'Form runner' scheduled tasks.
If using a scheduled task is a viable way of doing this, I see that one way of starting a scheduled task is via a 'Trigger'. The question is, can a POST request from outside be used to trigger a scheduled task somehow?
It would be fairly straight forward to have a non-Ebase URL receive the POST instead, and for it to then trigger the Ebase task (somehow), passing parameters by some means, if that makes it easier i.e. if the trigger must be something other than a POST.

I hope this makes it clearer what it is that I need to achieve here.
We don't have control over how the 3rd-party payment notification happens, only that it is a POST to a URL that we supply.
Any suggestions would be greatly appreciated.
Thanks.

Regards,
Chris.
0 x

User avatar
Wai
Moderator
Moderator
Posts: 165
Joined: Wed Sep 12, 2007 9:04 am
Location: Sandy, UK
Contact:

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#10

Postby Wai » Tue Oct 17, 2017 2:12 pm

Is the process:

1. User using the Ebase form
2. Is taken to the Payment site
3. Payment is made and returns user to the calling form with XML response

Or are you wanting the payment site to be able to call a service at any time?
0 x

chayward
Ebase User
Posts: 22
Joined: Fri Oct 13, 2017 9:43 am
Location: Hertford, UK
Contact:

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#11

Postby chayward » Tue Oct 17, 2017 3:27 pm

Hello Wai

The process follows these steps:

1. User using the Ebase form
2. Is taken to the Payment site
3. Payment is made, and asynchronously POSTs an Http request to a URL. We can tell them what URL. The POST contains an XML body/payload, with payment success or failure details.
4. Payment returns to calling form, but only after user has clicked a 'Finish' button on payment site.

Step 4 might not happen, if the user doesn't click Finish, so we must not depend on that for notification of payment status.
It is step 3 which is the important step, and must trigger an update process, in Ebase, which will run separately from the present form session that the user is using.
I hope that explains what I need to achieve.

Thanks for your time.

Regards,
Chris.
0 x

User avatar
Wai
Moderator
Moderator
Posts: 165
Joined: Wed Sep 12, 2007 9:04 am
Location: Sandy, UK
Contact:

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#12

Postby Wai » Tue Oct 17, 2017 5:17 pm

Hi Chris,

This should work. Can you try disabling browser check and see if you can see anything in the logs after the POST.
chayward wrote:
Mon Oct 16, 2017 2:29 pm
Hello Jon

It seems that perhaps what I was hoping to do here is not possible.
I cannot get an Ebase form to run in reponse to a POST, it would seem i.e. as a background task, with no browser associated.
At least, I see nothing in the Tomcat logs to indicate that the form is responding to a POST to that form's URL.
Is there something in Ebase that will only allow an Ebase form to run in conjunction with a client browser?

Thanks,
Chris.
0 x

chayward
Ebase User
Posts: 22
Joined: Fri Oct 13, 2017 9:43 am
Location: Hertford, UK
Contact:

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#13

Postby chayward » Wed Oct 18, 2017 9:14 am

Hello Wai
How do you disable browser checking, that you suggest?
I've been looking through the Help documentation, but can't find that topic. I can see the $PRESENTATION_USE_JAVASCRIPT = 'N' setting, but do you mean something else, or at a system level?
Thanks.

Chris.
0 x

User avatar
Wai
Moderator
Moderator
Posts: 165
Joined: Wed Sep 12, 2007 9:04 am
Location: Sandy, UK
Contact:

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#14

Postby Wai » Wed Oct 18, 2017 11:50 am

Hi Chris,

Add this to your UFSSetup.properties

# Skip Browser Check
Ufs.skipBrowserAttributesCheck=true

The server needs to be restarted.
0 x

chayward
Ebase User
Posts: 22
Joined: Fri Oct 13, 2017 9:43 am
Location: Hertford, UK
Contact:

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#15

Postby chayward » Wed Oct 18, 2017 1:26 pm

Thanks Wai
I'm rather worried about doing that at the system level.
Will it not have an adverse effect on normal form use? It says it will bypass checking on whether browsers being used support javascript, cookies and stylesheets. But that would be for everyone. I don't think I can implement that in the live environment.

Do you think there is any way forwards using a form as a scheduled task, started via a trigger? We could receive the POST via a process outside of Ebase, and get it to trigger the Ebase form perhaps, if there is a way of triggering from outside?

Regards,
Chris.
0 x

chayward
Ebase User
Posts: 22
Joined: Fri Oct 13, 2017 9:43 am
Location: Hertford, UK
Contact:

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#16

Postby chayward » Thu Oct 19, 2017 10:08 am

Hello Wai
On our Test Ebase system, I have tried the Ufs.skipBrowserAttributesCheck=true setting, and it does indeed then work correctly.
The form starts up from the POST to its URL, and successfully runs the before form and before page1 event scripts.

So, this is a way of doing what I need, but I am loathe to switch off the browser check at the system level on our live Ebase system, because all forms will then be affected.
Is there any other way, by script perhaps, of switching off the browser check, for an individual form, at run time?
Or, as mentioned previously, any way of triggering a scheduled task form, from outside, as an alternative way?

Thanks for your help.

Regards,
Chris.
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#17

Postby Jon » Mon Oct 23, 2017 11:39 am

Chris,

If it was me, I would try turning off the browser check - the risk is quite low, it makes some small changes to menus with IE5 or IE6 but many people now run with this switched off. The issues it addresses are very old.

In answer to your questions:

o There is no way to programmatically turn off the browser check
o It might be possible to trigger a scheduled task by sending XML, but this is much harder and has never been tried before so far as I know

Regards
Jon
0 x

chayward
Ebase User
Posts: 22
Joined: Fri Oct 13, 2017 9:43 am
Location: Hertford, UK
Contact:

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#18

Postby chayward » Thu Oct 26, 2017 9:35 am

Hello Jon
Thanks for the reply and advice.

As you suggest, I could switch off the browser check, and get the form to repsond directly to the XML POST. That does work.

However, I've been experimenting with an external Java process which receives the XML POST instead, and then triggers the Ebase form via a Java Runtime exec of the /External/EbaseTrigger/ebasetrigger.bat mechanism.
This works fine - the form starts and runs.
But, I am trying to pass parameters to the form when it is triggered, as per the docs for a triggered task. I cannot find how to access these parameters from the form script code - it doesn't say in the docs where they will go. They don't go into URL Parameter fields - I guess because a task started in batch like this doesn't run as a URL.
Please can you explain how I can pick up the parameter values supplied with the trigger command, from the form Javascript(API) code?

Thanks very much.

Regards,
Chris.
0 x

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#19

Postby Jon » Thu Oct 26, 2017 4:49 pm

Chris,

Sorry, but you can't pass form parameters to a scheduled form via the trigger mechanism. You probably should be able to do this but I'm afraid we left it out when we added form parameters to scheduled tasks, and you're the first person to notice. :(

If you're writing Java code and the requirement is to insert something into a database, why not just do it directly from the Java code? And skip invoking an Ebase form altogether. Sounds much simpler to me. I could supply an example if you're interested.

Regards
Jon
0 x

Steve James
Ebase User
Posts: 331
Joined: Mon Mar 10, 2014 8:34 am

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#20

Postby Steve James » Thu Oct 26, 2017 5:43 pm

Hi Chris.

I've just scanned through your post but I've not read the whole content.
This is actually a 3rd-party online payment process, which needs to notify 'our' code, which is Ebase form code currently, of online payment success for failure. It does this by POSTing a response to a URL that we tell them.
We do this via the following mechanism
  • Form 1 to capture the details of the service request. Just before passing over to the payment pages log the job on the database. We create a case in our CRM and put it in a pending payment queue
  • Redirect to the payment pages. I assume you have to encrypt xml with the appropriate fund codes, value etc. Our payment pages have 3 return urls, complete; cancel and back (vague as it's from memory).
  • The return from the payment pages fires a new Ebase form to conclude the transaction. The payment pages send us encrypted xml for us to decode and extract the appropriate nodes. We then 'release' the job upon successful payment ie in our case update the CRM job and move it to a 'get on with it queue'. We record auth codes etc. We have steps for cancelled; declined payments etc.
To cater for the chance that we take payment but the customer fails to get back to our completion form we run an end of day process. We can get our payments system to output a file of all successful payments so we just loop through them and update the case if appropriate.

It has worked for several years now very successfully with a number of transaction types.
Any use?

Thanks
Steve
0 x

chayward
Ebase User
Posts: 22
Joined: Fri Oct 13, 2017 9:43 am
Location: Hertford, UK
Contact:

Re: Read XML from a POST to an Ebase form (Ebase 4.4.3)

#21

Postby chayward » Fri Oct 27, 2017 8:41 am

Jon - thanks for the info that triggered tasks can't be passed parameters - I won't pursue that idea any further. Instead, I will switch off the browser-check, and allow the POST to start the Ebase form directly.
Perhaps you could update the documentation with a note about that, since it says here that parameters can be passed to a triggered form task.

Regarding doing the whole task in the external Java process, the reason for wanting to use the Ebase form is because we already have code there for doing what we want i.e. the database and email resources, and script code, already developed to do almost exactly what we want.

Steve - thanks for that info. Yes, that's pretty much what we will be doing here. In fact, we already have it working similar to that, in live, but this is to facilitate a change of online payment provider, and the difference is that this provider sends notification via an XML POST. Previously we've been using Web Services for the same work flow.
Adding an end of day catch-all is a good idea, which I'll suggest we implement as well - so, thanks for that idea.

Thanks everyone.

Regards,
Chris.
0 x


Who is online

Users browsing this forum: No registered users and 12 guests