...
The commandLoop() method in the ''' Contacts''' class below shows how this is done in the Contacts application. Note that the FormsService instance is state-full and the same instance needs to be used throughout the session (this is specially the case when rendering form urls in the browser since an API key is automatically appended and bound to the FormsService session - as soon as you logout() the API key becomes invalid). In the case of this command-line application the session spans the life-time of the executable, but in the case of a web application the FormsService instance is usually stored in the HTTP session that the user has with the application.<syntaxhighlight lang="java">
Code Block |
---|
public class Contacts { |
...
... |
...
private void commandLoop() throws IOException, ServiceException |
...
{ // create the FormsService to hold the session with |
...
frevvo FormsService s = new FormsService(getProtocol(), getHost(), getPort(), null); |
...
try { // login to frevvo s.login(getUsername() + '@' + getTenant(), getPassword()); |
...
// save the service to be used in subsequent |
...
interactions this.service = s; |
...
// Auto-upload the contact application, if not already |
...
there if (getContactForm() == null) |
...
{ uploadContactApplication(s); } // start the interactive shell ShellFactory.createConsoleShell(getPrompt(), null, this).commandLoop(); |
...
} finally { this.service = null; s.logout(); |
...
} } ... |
...
} |
</syntaxhighlight>Since there is some overhead associated with logging in and out, you need to keep the '''FormsService''' instance FormsService instance around for as long as you need to interact with frevvo before before logging out. Logging out ensures that frevvo will will release any unneeded resources and the user count will be decremented, as the number of users is affected by your frevvo license license.
LoginAs
Since version 4.1.1, frevvo supports supports an additional way of logging into frevvo using the Data API: the loginAs() method. This new method allows you to login to frevvo as any of the existing tenant users provided you can pass in the tenant's admin user and password. This is quite convenient when you want login to frevvo using the same user that is logged into your application without having to know their password.
...