I have been working with HandleSpecialURL to allow a third party website to communicate with my web based app.
The third party site sends a http get to my handleSpecialURL handler, and this works. My web based app sends me off an email to indicate it received the comms, and writes to the local log file in the Xojo Cloud Documents Folder.
But this only works when there is an active session running on my web based app. If there is no session running, I don’t get an email.
My web based app has code in the HandleSpecialURL event which resides in the App domain (or environment). When the event is invoked, I write to a local text file on the server (in Xojo Cloud). I also send email. All these functions are in the App domain, not in the Session or a Web Page.
Is this expected behaviour ? If so, what is the secret sauce to make my web based app wake up when HandleSpecialURL is invoked from web-side and do what it is supposed to do ? If not, what should I do to make it all Just Work ?
Also, is there a way to get a desktop app to establish a session with a web based app (living in Xojo Cloud) ? Should this be done via a TCP/IP socket or a HTMLviewer ?
[quote=127397:@Tony Barry]I have been working with HandleSpecialURL to allow a third party website to communicate with my web based app.
The third party site sends a http get to my handleSpecialURL handler, and this works. My web based app sends me off an email to indicate it received the comms, and writes to the local log file in the Xojo Cloud Documents Folder.
But this only works when there is an active session running on my web based app. If there is no session running, I don’t get an email.
[/quote]
Do you have the app running as CGI ? Or more to the point, is the App actually running. When run as a CGI the app would shutdown after the last session closes.
[quote=127397:@Tony Barry]The third party site sends a http get to my handleSpecialURL handler, and this works. My web based app sends me off an email to indicate it received the comms, and writes to the local log file in the Xojo Cloud Documents Folder.
But this only works when there is an active session running on my web based app. If there is no session running, I don’t get an email.[/quote]
What about the log ?
A cgi app would launch automatically when its URL is called, so specialurl or not, it should restart automatically.
Just a hunch : where is the method that sends email ? If it is anywhere in Session or on a page, of course it won’t work for handlespecialurl since that event is in App. Only a method in App or in a module can be called when there is no session.
SMTPSocket/SMTPSecureSocket are asynchronous. It probably initiates the email transfer then falls out of scope before it finishes. Maybe make the SMTP socket a property of App object. However then you can only use one. Ideally you write the email to a log, then another background job comes along and sends the appropriate outgoing emails.
Another approach is use something like Mailgun and use their REST API to send emails. Then you can use a synchronous HTTPSocket.
The conclusion comes naturally : one socket dedicated to the task of sending the above mentioned email in app, or even in the handlespecialurl event, to make sure it does not get out of scope.
Hi All,
Thank you to all who replied. The input is muchly appreciated.
Yes the web app is CGI.
All the code for receiving the third party input is within the app class.
All the email code is within the app class.
All the logfile write code is within the app class.
The code for opening the firewall is within the app class.
The SMTPsecureSocket is a property of the app class.
The log file is also written to only when a session is active.
I went through the code fairly carefully after reading the above messages, and discovered that I did not instantiate the SMTPsecureSocket within the handleSpecialRequest event. This is likely the cause of the fail.
Normally, I would expect some kind of error (nilObject) in some relevant place. Unfortunately I do not know where a Xojo Cloud app will put such errors.
This does mean that handleSpecialURL could be called recursively if I have a slow send on the email. Is that a problem ? My HTTP GETs to the app are likely to come in every couple of seconds under the right circumstances.
It would probably be okay, but if you’re really concerned, move the email code to a separate console app and just call it using a shell. Then you don’t need to worry about whether the app stays running.
Keep in mind though… If you’ll be getting hit every couple seconds, it might be worth setting App.AutoQuit = False in the App.Open event so the app will stay running. Then maybe once per day you could set it to True so the app will quit once in a while.
I think you’re saying “set it (App.AutoQuit) to False in the App.Open event and then periodically set it to True so the app can quit on it’s own once per day.”