Calling Rest service before LoginService executes

Posted by bharold on 01-Mar-2014 07:37

In my Mobile App, i Execute 'MobileService_Login' after user has entered Login_Id and Password. And All other JSDO services are initialised after MobileService_Login is executed.

 

Sales and Marketing department is requesting to display some dynamic info on Login Page of the App.

I have created the rest service but How do I call this rest service before even calling Login service? 

What are my options to call  rest service before user is authenticated?

All Replies

Posted by Bill Wood on 01-Mar-2014 07:49

Interesting question.

Basically, to have some dynamic data/UI shown before the user logs in that has to be exposed at a different endpoint that is public and unauthenticated.

This could be raw HTML that you include on the page, or it could be a rest service the returns data that you bind in the mobile app UI. Regardless it needs to be at an unauthenticated endpoint.

If it is REST data I assume it is read-only so you could just bind to it as a rest service easily. You could use the JSDO as well (although I am unsure of the specific steps to support what is effectively two OpenEdge Mobile endpoints with different authentication).

Note that the marketing endpoint could be any .war file or web app on your Tomcat server but you will have fewer CORS issues if it shares the same port as domain URL (so both should use http or https and the same server DNS and port). =

Posted by whenshaw on 03-Mar-2014 10:12

As Bill Wood pointed out, your REST service that provides the marketing information would be set up as a different web application from the one that you already use for the app's main data, with its own JSDO catalog and authentication model. The marketing REST app would need to use the Anonymous authentication model.

As for the steps involved to support two OpenEdge endpoints: You would use the Mobile App Builder to add a second "Session service" to the mobile app, separate from the MobileService_Login/MobileService_Logout group that you already have. You could call it something like MarketingService_Login (and MarketingService_Logout). Execute MarketingService_Login when the app first loads, which would establish a connection only to your marketing service, create a JSDO for the marketing data, and get the marketing data that way. Your should not need to change your existing use of the MobileService_Login service.

Please be aware that we expect to release a new version of the Mobile App Builder very soon (but you would need to check with Product Management for exact timing). The new version of the MAB uses a somewhat different model for working with Session services, and makes it easier to create additional Session services. Currently you would need to create the second group of Session services by copying your existing service or using a plug-in, but our plan is that the process will be much easier in the new release. Please let me know if you would like more details on using a second Session service with the current MAB. Good luck!

-- Wayne Henshaw

Posted by bharold on 03-Mar-2014 14:10

Hi Wayne,

That makes sense.

If you can give me little bit more detail about how to create 2nd set of Session service that would be helpful.

How do I create 2nd set of Login/Logout services?  

I would appreciate if you can list the steps.

Thanks,

Posted by whenshaw on 03-Mar-2014 17:30

Well, here is a set of steps that should work for you in the current version of the Mobile App Builder. You may want to consider waiting for the new release after you see these, but I would be happy to help you through them if you want to go this route. The basic idea is to copy the existing MobileService and edit the copy to give you the second service. The copy is indirect -- you will need to create a plugin from MobileService and then create a new service from that plugin. (Thanks to Maura Regan for showing me a document she wrote that includes this procedure)

1. Open your project in the Mobile App Builder and select "Export" and then "OpenEdge Plugin"

 a. in the dialog that opens up, fill in a Name

 b. Uncheck "Export entire project"

 c. under "Export entire project" (now unchecked), expand "Services"

 d. check MobileService_Login, MobileService_Logout, and MobileService_Settings

     (be sure NOT to check any other services that might be there)

 e. Click the green Export button at bottom right

2. Should get a dialog box that says the export worked, click OK

3. Now back at the MAB screen for your project

4. Create New | From Plugin

  a. Select the plugin that you just created

  b. Click "Import selected plug-ins"  

5. Dialog box that says "Appery.io plugin(s) were installed successfully." should appear. It asks whether you want to set the Settings now. Might as well check the box for that and click "Apply settings" -- that will create the new services and display the Settings page for them

6. Set the appropriate settings -- the catalogsURIs and serviceURI for the REST service you created for the marketing info, leave the other 2 fields alone. Save.

8 Unfortunately, your new services (and the Settings object)  will have the same names as the original services that you made the plugin from, with GUIDs appended, e.g.,

- MobileService_Login1369420228594

- MobileService_Logout1369420228620

- MobileService_Settings1369420228648

And under the JavaScript node on the left of the MAB screen (these files contain the implementation code for the services):

- SessionLogin1369420228674

- SessionLogout1369420228700

Sooner or later you'll probably want to change those names. It's fairly easy to change the names of the MobileService_Login... and MobileService_Logout... services -- just click on them, you'll see a property page come up with fields for things like "Name", "JavaScript Implementation", etc. . Just enter whatever you'd like in the "Name" field ("MarketingService_Login", for example).

Changing the names of the MobileService_Settings... and the 2 JavaScript files is more involved and not necessary. I can give you instructions for that if you want, but for now let's make a few final changes that *are* necessary:

9. Click on the new JavaScript file for the login (SessionLogin1369420228674 in the example above).

a. you'll see the JS code displayed in the main part of the screen

b. on line 11 (I think it should be), replace $t.SessionLogin  with   $t.SessionLoginxxxx..., where xxxx... is the number appended to the JavaScript file you're editing   (i.e., make sure that what follows the first $t. on that line is the name of the file it's in. Leave the $t.createClass on that line alone)

 c. Save

10. Click on the SessionLogout JS file so you can edit it, too

 a. As in the login file, replace $t.SessionLogout (should be on line 9) with   $t. + the name of the file you're editing

 b. a little farther down (it's line 28 in the file I'm looking at), replace MobileService_Login with the name of your

    new MobileService_Login service -- that would be MobileService_Login1369420228594 in the example above, or whatever you may have changed it to  (and yes that is correct that even though this is the logout code, you are dealing with the Login service in this particular statement)

11. Be sure to save!

This will give you the second set of Session services.  As I outlined earlier, you'd probably want to execute the new Marketing login as soon as the app is activated, by adding it to the Data tab of your main page and executing it in page Load, or something along those lines.

Posted by bharold on 03-Mar-2014 18:10

Wayne,

Thank you for perfect instructions. I was able to follow it and have 2 rest services working.

One last question:  

How do I share resources /  class files between 2 rest services?  

Should I just copy my source.cls file to 2nd rest service folder or is there any easier way?

Thanks again for your help with creating 2 rest services.  You should make this as a KB article.

- Harold

Posted by whenshaw on 04-Mar-2014 10:28

Harold,

That's good to hear!

Regarding the question of sharing resources: Are you asking about deploying source.cls for when your services are running, or sharing it between PDSOE projects when you are doing development?

--Wayne

Posted by bharold on 04-Mar-2014 12:27

Wayne,

I am asking about sharing source between PDSOE while developing.

I would like to share a source code object between my 2 projects which I have created for secure and non-secure rest services.

Posted by whenshaw on 04-Mar-2014 15:47

You should be able to put the file into one project and set the PROPATH of your 2nd project so that the 2nd project picks up the file. Is that what you're trying to accomplish?

This thread is closed